]> cat aescling's git repositories - mastodon.git/blob - app/controllers/home_controller.rb
Add whitelist mode (#11291)
[mastodon.git] / app / controllers / home_controller.rb
1 # frozen_string_literal: true
2
3 class HomeController < ApplicationController
4 before_action :authenticate_user!
5 before_action :set_referrer_policy_header
6 before_action :set_initial_state_json
7
8 def index
9 @body_classes = 'app-body'
10 end
11
12 private
13
14 def authenticate_user!
15 return if user_signed_in?
16
17 matches = request.path.match(/\A\/web\/(statuses|accounts)\/([\d]+)\z/)
18
19 if matches
20 case matches[1]
21 when 'statuses'
22 status = Status.find_by(id: matches[2])
23
24 if status&.distributable?
25 redirect_to(ActivityPub::TagManager.instance.url_for(status))
26 return
27 end
28 when 'accounts'
29 account = Account.find_by(id: matches[2])
30
31 if account
32 redirect_to(ActivityPub::TagManager.instance.url_for(account))
33 return
34 end
35 end
36 end
37
38 matches = request.path.match(%r{\A/web/timelines/tag/(?<tag>.+)\z})
39 redirect_to(matches ? tag_path(CGI.unescape(matches[:tag])) : default_redirect_path)
40 end
41
42 def set_initial_state_json
43 serializable_resource = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(initial_state_params), serializer: InitialStateSerializer)
44 @initial_state_json = serializable_resource.to_json
45 end
46
47 def initial_state_params
48 {
49 settings: Web::Setting.find_by(user: current_user)&.data || {},
50 push_subscription: current_account.user.web_push_subscription(current_session),
51 current_account: current_account,
52 token: current_session.token,
53 admin: Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, '')),
54 }
55 end
56
57 def default_redirect_path
58 if request.path.start_with?('/web') || whitelist_mode?
59 new_user_session_path
60 elsif single_user_mode?
61 short_account_path(Account.local.without_suspended.where('id > 0').first)
62 else
63 about_path
64 end
65 end
66
67 def set_referrer_policy_header
68 response.headers['Referrer-Policy'] = 'origin'
69 end
70 end
This page took 0.083424 seconds and 5 git commands to generate.