diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/accounts_controller.rb | 8 | ||||
-rw-r--r-- | app/controllers/activitypub/inboxes_controller.rb | 16 | ||||
-rw-r--r-- | app/controllers/admin/accounts_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/api/proofs_controller.rb | 30 | ||||
-rw-r--r-- | app/controllers/api/v1/preferences_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/api/v1/statuses/reblogs_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/follower_accounts_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/relationships_controller.rb | 108 | ||||
-rw-r--r-- | app/controllers/settings/follower_domains_controller.rb | 24 | ||||
-rw-r--r-- | app/controllers/settings/identity_proofs_controller.rb | 45 | ||||
-rw-r--r-- | app/controllers/statuses_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/well_known/keybase_proof_config_controller.rb | 9 |
13 files changed, 239 insertions, 31 deletions
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 157ea8569..fcdebb47f 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -11,6 +11,8 @@ class AccountsController < ApplicationController respond_to do |format| format.html do use_pack 'public' + mark_cacheable! unless user_signed_in? + @body_classes = 'with-modals' @pinned_statuses = [] @endorsed_accounts = @account.endorsed_accounts.to_a.sample(4) @@ -31,17 +33,21 @@ class AccountsController < ApplicationController end format.atom do + mark_cacheable! + @entries = @account.stream_entries.where(hidden: false).with_includes.paginate_by_max_id(PAGE_SIZE, params[:max_id], params[:since_id]) render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.feed(@account, @entries.reject { |entry| entry.status.nil? || entry.status.local_only? })) end format.rss do + mark_cacheable! + @statuses = cache_collection(default_statuses.without_reblogs.without_replies.limit(PAGE_SIZE), Status) render xml: RSS::AccountSerializer.render(@account, @statuses) end format.json do - skip_session! + mark_cacheable! render_cached_json(['activitypub', 'actor', @account], content_type: 'application/activity+json') do ActiveModelSerializers::SerializableResource.new(@account, serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter) diff --git a/app/controllers/activitypub/inboxes_controller.rb b/app/controllers/activitypub/inboxes_controller.rb index 8f5e1887e..1501b914e 100644 --- a/app/controllers/activitypub/inboxes_controller.rb +++ b/app/controllers/activitypub/inboxes_controller.rb @@ -2,11 +2,14 @@ class ActivityPub::InboxesController < Api::BaseController include SignatureVerification + include JsonLdHelper before_action :set_account def create - if signed_request_account + if unknown_deleted_account? + head 202 + elsif signed_request_account upgrade_account process_payload head 202 @@ -17,12 +20,19 @@ class ActivityPub::InboxesController < Api::BaseController private + def unknown_deleted_account? + json = Oj.load(body, mode: :strict) + json['type'] == 'Delete' && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.where(uri: json['actor']).exists? + rescue Oj::ParseError + false + end + def set_account @account = Account.find_local!(params[:account_username]) if params[:account_username] end def body - @body ||= request.body.read + @body ||= request.body.read.force_encoding('UTF-8') end def upgrade_account @@ -36,6 +46,6 @@ class ActivityPub::InboxesController < Api::BaseController end def process_payload - ActivityPub::ProcessingWorker.perform_async(signed_request_account.id, body.force_encoding('UTF-8'), @account&.id) + ActivityPub::ProcessingWorker.perform_async(signed_request_account.id, body, @account&.id) end end diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb index e160c603a..e7795e95c 100644 --- a/app/controllers/admin/accounts_controller.rb +++ b/app/controllers/admin/accounts_controller.rb @@ -53,7 +53,7 @@ module Admin def reject authorize @account.user, :reject? - SuspendAccountService.new.call(@account, including_user: true, destroy: true) + SuspendAccountService.new.call(@account, including_user: true, destroy: true, skip_distribution: true) redirect_to admin_accounts_path(pending: '1') end diff --git a/app/controllers/api/proofs_controller.rb b/app/controllers/api/proofs_controller.rb new file mode 100644 index 000000000..a84ad2014 --- /dev/null +++ b/app/controllers/api/proofs_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Api::ProofsController < Api::BaseController + before_action :set_account + before_action :set_provider + before_action :check_account_approval + before_action :check_account_suspension + + def index + render json: @account, serializer: @provider.serializer_class + end + + private + + def set_provider + @provider = ProofProvider.find(params[:provider]) || raise(ActiveRecord::RecordNotFound) + end + + def set_account + @account = Account.find_local!(params[:username]) + end + + def check_account_approval + not_found if @account.user_pending? + end + + def check_account_suspension + gone if @account.suspended? + end +end diff --git a/app/controllers/api/v1/preferences_controller.rb b/app/controllers/api/v1/preferences_controller.rb new file mode 100644 index 000000000..077d39f5d --- /dev/null +++ b/app/controllers/api/v1/preferences_controller.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class Api::V1::PreferencesController < Api::BaseController + before_action -> { doorkeeper_authorize! :read, :'read:accounts' } + before_action :require_user! + + respond_to :json + + def index + render json: current_account, serializer: REST::PreferencesSerializer + end +end diff --git a/app/controllers/api/v1/statuses/reblogs_controller.rb b/app/controllers/api/v1/statuses/reblogs_controller.rb index 04847a6b7..ed4f55100 100644 --- a/app/controllers/api/v1/statuses/reblogs_controller.rb +++ b/app/controllers/api/v1/statuses/reblogs_controller.rb @@ -9,7 +9,7 @@ class Api::V1::Statuses::ReblogsController < Api::BaseController respond_to :json def create - @status = ReblogService.new.call(current_user.account, status_for_reblog) + @status = ReblogService.new.call(current_user.account, status_for_reblog, reblog_params) render json: @status, serializer: REST::StatusSerializer end @@ -32,4 +32,8 @@ class Api::V1::Statuses::ReblogsController < Api::BaseController def status_for_destroy current_user.account.statuses.where(reblog_of_id: params[:status_id]).first! end + + def reblog_params + params.permit(:visibility) + end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0209805d0..5401b9d59 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -227,6 +227,11 @@ class ApplicationController < ActionController::Base response.headers['Vary'] = 'Accept' end + def mark_cacheable! + skip_session! + expires_in 0, public: true + end + def skip_session! request.session_options[:skip] = true end diff --git a/app/controllers/follower_accounts_controller.rb b/app/controllers/follower_accounts_controller.rb index f985f0eff..213c209ab 100644 --- a/app/controllers/follower_accounts_controller.rb +++ b/app/controllers/follower_accounts_controller.rb @@ -7,6 +7,7 @@ class FollowerAccountsController < ApplicationController respond_to do |format| format.html do use_pack 'public' + mark_cacheable! unless user_signed_in? next if @account.user_hides_network? diff --git a/app/controllers/relationships_controller.rb b/app/controllers/relationships_controller.rb new file mode 100644 index 000000000..a0b9c77df --- /dev/null +++ b/app/controllers/relationships_controller.rb @@ -0,0 +1,108 @@ +# frozen_string_literal: true + +class RelationshipsController < ApplicationController + layout 'admin' + + before_action :authenticate_user! + before_action :set_accounts, only: :show + before_action :set_pack + before_action :set_body_classes + + helper_method :following_relationship?, :followed_by_relationship?, :mutual_relationship? + + def show + @form = Form::AccountBatch.new + end + + def update + @form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button)) + @form.save + rescue ActionController::ParameterMissing + # Do nothing + ensure + redirect_to relationships_path(current_params) + end + + private + + def set_accounts + @accounts = relationships_scope.page(params[:page]).per(40) + end + + def relationships_scope + scope = begin + if following_relationship? + current_account.following.joins(:account_stat) + else + current_account.followers.joins(:account_stat) + end + end + + scope.merge!(Follow.recent) + scope.merge!(mutual_relationship_scope) if mutual_relationship? + scope.merge!(moved_account_scope) if params[:status] == 'moved' + scope.merge!(primary_account_scope) if params[:status] == 'primary' + scope.merge!(by_domain_scope) if params[:by_domain].present? + scope.merge!(dormant_account_scope) if params[:activity] == 'dormant' + + scope + end + + def mutual_relationship_scope + Account.where(id: current_account.following) + end + + def moved_account_scope + Account.where.not(moved_to_account_id: nil) + end + + def primary_account_scope + Account.where(moved_to_account_id: nil) + end + + def dormant_account_scope + AccountStat.where(last_status_at: nil).or(AccountStat.where(AccountStat.arel_table[:last_status_at].lt(1.month.ago))) + end + + def by_domain_scope + Account.where(domain: params[:by_domain]) + end + + def form_account_batch_params + params.require(:form_account_batch).permit(:action, account_ids: []) + end + + def following_relationship? + params[:relationship].blank? || params[:relationship] == 'following' + end + + def mutual_relationship? + params[:relationship] == 'mutual' + end + + def followed_by_relationship? + params[:relationship] == 'followed_by' + end + + def current_params + params.slice(:page, :status, :relationship, :by_domain, :activity).permit(:page, :status, :relationship, :by_domain, :activity) + end + + def action_from_button + if params[:unfollow] + 'unfollow' + elsif params[:remove_from_followers] + 'remove_from_followers' + elsif params[:block_domains] + 'block_domains' + end + end + + def set_body_classes + @body_classes = 'admin' + end + + def set_pack + use_pack 'admin' + end +end diff --git a/app/controllers/settings/follower_domains_controller.rb b/app/controllers/settings/follower_domains_controller.rb deleted file mode 100644 index 8aae379aa..000000000 --- a/app/controllers/settings/follower_domains_controller.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class Settings::FollowerDomainsController < Settings::BaseController - def show - @account = current_account - @domains = current_account.followers.reorder(Arel.sql('MIN(follows.id) DESC')).group('accounts.domain').select('accounts.domain, count(accounts.id) as accounts_from_domain').page(params[:page]).per(10) - end - - def update - domains = bulk_params[:select] || [] - - AfterAccountDomainBlockWorker.push_bulk(domains) do |domain| - [current_account.id, domain] - end - - redirect_to settings_follower_domains_path, notice: I18n.t('followers.success', count: domains.size) - end - - private - - def bulk_params - params.permit(select: []) - end -end diff --git a/app/controllers/settings/identity_proofs_controller.rb b/app/controllers/settings/identity_proofs_controller.rb new file mode 100644 index 000000000..4a3b89a5e --- /dev/null +++ b/app/controllers/settings/identity_proofs_controller.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +class Settings::IdentityProofsController < Settings::BaseController + layout 'admin' + + before_action :authenticate_user! + before_action :check_required_params, only: :new + + def index + @proofs = AccountIdentityProof.where(account: current_account).order(provider: :asc, provider_username: :asc) + @proofs.each(&:refresh!) + end + + def new + @proof = current_account.identity_proofs.new( + token: params[:token], + provider: params[:provider], + provider_username: params[:provider_username] + ) + + render layout: 'auth' + end + + def create + @proof = current_account.identity_proofs.where(provider: resource_params[:provider], provider_username: resource_params[:provider_username]).first_or_initialize(resource_params) + @proof.token = resource_params[:token] + + if @proof.save + redirect_to @proof.on_success_path(params[:user_agent]) + else + flash[:alert] = I18n.t('identity_proofs.errors.failed', provider: @proof.provider.capitalize) + redirect_to settings_identity_proofs_path + end + end + + private + + def check_required_params + redirect_to settings_identity_proofs_path unless [:provider, :provider_username, :token].all? { |k| params[k].present? } + end + + def resource_params + params.require(:account_identity_proof).permit(:provider, :provider_username, :token) + end +end diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb index 6f56a67ba..53cf1c4ca 100644 --- a/app/controllers/statuses_controller.rb +++ b/app/controllers/statuses_controller.rb @@ -28,6 +28,8 @@ class StatusesController < ApplicationController respond_to do |format| format.html do use_pack 'public' + mark_cacheable! unless user_signed_in? + @body_classes = 'with-modals' set_ancestors @@ -37,7 +39,7 @@ class StatusesController < ApplicationController end format.json do - skip_session! unless @stream_entry.hidden? + mark_cacheable! unless @stream_entry.hidden? render_cached_json(['activitypub', 'note', @status], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter) diff --git a/app/controllers/well_known/keybase_proof_config_controller.rb b/app/controllers/well_known/keybase_proof_config_controller.rb new file mode 100644 index 000000000..eb41e586f --- /dev/null +++ b/app/controllers/well_known/keybase_proof_config_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module WellKnown + class KeybaseProofConfigController < ActionController::Base + def show + render json: {}, serializer: ProofProvider::Keybase::ConfigSerializer + end + end +end |