Skip to content

Commit

Permalink
Skip blocks check when getting active blocks list
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Jan 1, 2025
1 parent 621efb7 commit 00b3d9a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
7 changes: 7 additions & 0 deletions app/controllers/api/user_blocks/active_lists_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
module Api
module UserBlocks
class ActiveListsController < ApiController
before_action :disable_blocks_check
before_action :authorize

authorize_resource :class => :active_user_blocks_list

before_action :set_request_formats

def show; end

private

def disable_blocks_check
flash.now[:skip_blocks] = true
end
end
end
end
16 changes: 9 additions & 7 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ def setup_user_auth
# have we identified the user?
if current_user
# check if the user has been banned
user_block = current_user.blocks.active.take
unless user_block.nil?
set_locale
if user_block.zero_hour?
report_error t("application.setup_user_auth.blocked_zero_hour"), :forbidden
else
report_error t("application.setup_user_auth.blocked"), :forbidden
if flash.now[:skip_blocks].nil?
user_block = current_user.blocks.active.take
unless user_block.nil?
set_locale
if user_block.zero_hour?
report_error t("application.setup_user_auth.blocked_zero_hour"), :forbidden
else
report_error t("application.setup_user_auth.blocked"), :forbidden
end
end
end

Expand Down
26 changes: 26 additions & 0 deletions test/controllers/api/user_blocks/active_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@ def test_show_empty
assert_response :success
assert_dom "user_block", :count => 0
end

def test_show
user = create(:moderator_user)
user_auth_header = bearer_authorization_header(user, :scopes => %w[read_prefs])
create(:user_block, :expired, :user => user)
block0 = create(:user_block, :user => user)
block1 = create(:user_block, :user => user)
create(:user_block)
create(:user_block, :creator => user)

get api_user_blocks_active_list_path, :headers => user_auth_header
assert_response :success
end

def test_show_json
user = create(:moderator_user)
user_auth_header = bearer_authorization_header(user, :scopes => %w[read_prefs])
create(:user_block, :expired, :user => user)
block0 = create(:user_block, :user => user)
block1 = create(:user_block, :user => user)
create(:user_block)
create(:user_block, :creator => user)

get api_user_blocks_active_list_path(:format => "json"), :headers => user_auth_header
assert_response :success
end
end
end
end

0 comments on commit 00b3d9a

Please sign in to comment.