Skip to content

Commit

Permalink
fix: don't check action's authorization on render if visible return…
Browse files Browse the repository at this point in the history
…s false
  • Loading branch information
Paul-Bob committed Jan 31, 2025
1 parent ec77a11 commit c3f76c6
Showing 1 changed file with 8 additions and 13 deletions.
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

0 comments on commit c3f76c6

Please sign in to comment.