Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: implicit_authorization on default authorization service #3355

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 [email protected]_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
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
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
Loading