mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-12-11 23:19:03 +01:00
730c4053d6
* Add support for an instance actor * Skip username validation for local Application accounts * Add migration script to create instance actor * Make Codeclimate happy * Switch to id -99 for instance actor * Remove unused `icon` and `image` attributes from instance actor * Use if/elsif/else instead of return + ternary operator * Add instance actor to fresh installs * Use instance actor as instance representative Use instance actor for forwarding reports, relay operations, and spam auto-reporting. * Seed database in test environment * Fix single-user mode * Fix tests * Fix specs to accomodate for an extra `Account` * Auto-reject follows on instance actor Following an instance actor might make sense, but we are not handling that right now, so auto-reject. * Fix webfinger lookup and serialization for instance actor * Rename instance actor * Make it clear in the HTML view that the instance actor should not be blocked * Raise cache time for instance actor as there's no dynamic content * Re-use /about/more with a flash message for instance actor profile
70 lines
1.9 KiB
Ruby
70 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class HomeController < ApplicationController
|
|
before_action :authenticate_user!
|
|
before_action :set_referrer_policy_header
|
|
before_action :set_initial_state_json
|
|
|
|
def index
|
|
@body_classes = 'app-body'
|
|
end
|
|
|
|
private
|
|
|
|
def authenticate_user!
|
|
return if user_signed_in?
|
|
|
|
matches = request.path.match(/\A\/web\/(statuses|accounts)\/([\d]+)\z/)
|
|
|
|
if matches
|
|
case matches[1]
|
|
when 'statuses'
|
|
status = Status.find_by(id: matches[2])
|
|
|
|
if status&.distributable?
|
|
redirect_to(ActivityPub::TagManager.instance.url_for(status))
|
|
return
|
|
end
|
|
when 'accounts'
|
|
account = Account.find_by(id: matches[2])
|
|
|
|
if account
|
|
redirect_to(ActivityPub::TagManager.instance.url_for(account))
|
|
return
|
|
end
|
|
end
|
|
end
|
|
|
|
matches = request.path.match(%r{\A/web/timelines/tag/(?<tag>.+)\z})
|
|
redirect_to(matches ? tag_path(CGI.unescape(matches[:tag])) : default_redirect_path)
|
|
end
|
|
|
|
def set_initial_state_json
|
|
serializable_resource = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(initial_state_params), serializer: InitialStateSerializer)
|
|
@initial_state_json = serializable_resource.to_json
|
|
end
|
|
|
|
def initial_state_params
|
|
{
|
|
settings: Web::Setting.find_by(user: current_user)&.data || {},
|
|
push_subscription: current_account.user.web_push_subscription(current_session),
|
|
current_account: current_account,
|
|
token: current_session.token,
|
|
admin: Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, '')),
|
|
}
|
|
end
|
|
|
|
def default_redirect_path
|
|
if request.path.start_with?('/web')
|
|
new_user_session_path
|
|
elsif single_user_mode?
|
|
short_account_path(Account.local.without_suspended.where('id > 0').first)
|
|
else
|
|
about_path
|
|
end
|
|
end
|
|
|
|
def set_referrer_policy_header
|
|
response.headers['Referrer-Policy'] = 'origin'
|
|
end
|
|
end
|