]> git.openstreetmap.org Git - rails.git/blob - app/controllers/users/received_blocks_controller.rb
Merge remote-tracking branch 'upstream/pull/5457'
[rails.git] / app / controllers / users / received_blocks_controller.rb
1 module Users
2   class ReceivedBlocksController < ApplicationController
3     include UserMethods
4     include PaginationMethods
5
6     layout "site"
7
8     before_action :authorize_web
9     before_action :set_locale
10
11     authorize_resource :class => UserBlock
12
13     before_action :lookup_user
14     before_action :check_database_readable
15     before_action :check_database_writable, :only => :destroy
16
17     ##
18     # shows a list of all the blocks on the given user
19     def show
20       @params = params.permit(:user_display_name)
21
22       user_blocks = UserBlock.where(:user => @user)
23
24       @user_blocks, @newer_user_blocks_id, @older_user_blocks_id = get_page_items(user_blocks, :includes => [:user, :creator, :revoker])
25
26       @show_user_name = false
27       @show_creator_name = true
28
29       render :partial => "user_blocks/page" if turbo_frame_request_id == "pagination"
30     end
31
32     ##
33     # shows revoke all active blocks page
34     def edit; end
35
36     ##
37     # revokes all active blocks
38     def destroy
39       if params[:confirm]
40         @user.blocks.active.each { |block| block.revoke!(current_user) }
41         flash[:notice] = t ".flash"
42         redirect_to user_received_blocks_path(@user)
43       else
44         render :action => :edit
45       end
46     end
47   end
48 end