Skip to content

Commit

Permalink
fix: implicit_authorization on default authorization service (#3355)
Browse files Browse the repository at this point in the history
* fix: implicit_authorization on default authorization service

* fix `authorize_association_for`

* comment

* syntax fix
  • Loading branch information
Paul-Bob authored Oct 22, 2024
1 parent 39ba83c commit ba99622
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/avo/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def authorize_if_defined(method, record = @record)

if @authorization.has_method?(method.to_sym)
@authorization.authorize_action method.to_sym
elsif Avo.configuration.authorization_client.present? && Avo.configuration.implicit_authorization
elsif !@authorization.is_a?(Avo::Services::AuthorizationService) && Avo.configuration.implicit_authorization
raise Avo::NotAuthorizedError.new
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/avo/concerns/checks_assoc_authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def authorize_association_for(policy_method)

if service.has_method?(method_name, raise_exception: false)
service.authorize_action(method_name, record:, raise_exception: false)
else
elsif !service.is_a?(Avo::Services::AuthorizationService)
!Avo.configuration.implicit_authorization
else
true
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/avo/fields/has_base_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ def authorized?

if service.has_method? method
service.authorize_action(method, raise_exception: false)
else
elsif !service.is_a?(Avo::Services::AuthorizationService)
!Avo.configuration.implicit_authorization
else
true
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/dummy/config/initializers/avo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
config.locale = :en
# config.raise_error_on_missing_policy = true
# config.authorization_client = "Avo::Services::AuthorizationClients::ExtraPunditClient"
# Shouldn't impact on community only if custom authorization service was configured.
config.implicit_authorization = true

## == Customization ==
config.id_links_to_resource = true
Expand Down

0 comments on commit ba99622

Please sign in to comment.