]> cat aescling's git repositories - mastodon.git/blob - app/controllers/relationships_controller.rb
Add rate limit for reporting (#13390)
[mastodon.git] / app / controllers / relationships_controller.rb
1 # frozen_string_literal: true
2
3 class RelationshipsController < ApplicationController
4 layout 'admin'
5
6 before_action :authenticate_user!
7 before_action :set_accounts, only: :show
8 before_action :set_body_classes
9
10 helper_method :following_relationship?, :followed_by_relationship?, :mutual_relationship?
11
12 def show
13 @form = Form::AccountBatch.new
14 end
15
16 def update
17 @form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button))
18 @form.save
19 rescue ActionController::ParameterMissing
20 # Do nothing
21 ensure
22 redirect_to relationships_path(filter_params)
23 end
24
25 private
26
27 def set_accounts
28 @accounts = RelationshipFilter.new(current_account, filter_params).results.page(params[:page]).per(40)
29 end
30
31 def form_account_batch_params
32 params.require(:form_account_batch).permit(:action, account_ids: [])
33 end
34
35 def following_relationship?
36 params[:relationship].blank? || params[:relationship] == 'following'
37 end
38
39 def mutual_relationship?
40 params[:relationship] == 'mutual'
41 end
42
43 def followed_by_relationship?
44 params[:relationship] == 'followed_by'
45 end
46
47 def filter_params
48 params.slice(:page, *RelationshipFilter::KEYS).permit(:page, *RelationshipFilter::KEYS)
49 end
50
51 def action_from_button
52 if params[:unfollow]
53 'unfollow'
54 elsif params[:remove_from_followers]
55 'remove_from_followers'
56 elsif params[:block_domains]
57 'block_domains'
58 end
59 end
60
61 def set_body_classes
62 @body_classes = 'admin'
63 end
64 end
This page took 0.082667 seconds and 4 git commands to generate.