Skip to content

Commit

Permalink
Extract private methods in api/v1/instances/domain_blocks (mastodon#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored and vmstan committed Dec 14, 2023
1 parent 718c190 commit 5fbdd0c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/controllers/api/v1/instances/domain_blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def index
cache_if_unauthenticated!
end

render json: @domain_blocks, each_serializer: REST::DomainBlockSerializer, with_comment: (Setting.show_domain_blocks_rationale == 'all' || (Setting.show_domain_blocks_rationale == 'users' && user_signed_in?))
render json: @domain_blocks, each_serializer: REST::DomainBlockSerializer, with_comment: show_rationale_in_response?
end

private
Expand All @@ -25,4 +25,16 @@ def require_enabled_api!
def set_domain_blocks
@domain_blocks = DomainBlock.with_user_facing_limitations.by_severity
end

def show_rationale_in_response?
always_show_rationale? || show_rationale_for_user?
end

def always_show_rationale?
Setting.show_domain_blocks_rationale == 'all'
end

def show_rationale_for_user?
Setting.show_domain_blocks_rationale == 'users' && user_signed_in?
end
end

0 comments on commit 5fbdd0c

Please sign in to comment.