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: don't check action's authorization on render if visible return false #3628

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Changes from 1 commit
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
21 changes: 8 additions & 13 deletions lib/avo/base_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ class BaseAction
class_attribute :cancel_button_label
class_attribute :no_confirmation, default: false
class_attribute :standalone, default: false
class_attribute :visible
class_attribute :visible, default: -> {
# Hide on the :new view by default
return false if view.new?

# Show on all other views
return true
}
class_attribute :may_download_file
class_attribute :turbo
class_attribute :authorize, default: true
Expand Down Expand Up @@ -207,25 +213,14 @@ def handle_action(**args)
end

def visible_in_view(parent_resource: nil)
return false unless authorized?

if visible.blank?
# Hide on the :new view by default
return false if view.new?

# Show on all other views
return true
end

# Run the visible block if available
Avo::ExecutionContext.new(
target: visible,
params: params,
parent_resource: parent_resource,
resource: @resource,
view: @view,
arguments: arguments
).handle
).handle && authorized?
end

def succeed(text)
Expand Down
Loading