Skip to content

Commit

Permalink
Merge branch 'main' into feature/custom_list
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Sep 5, 2024
2 parents 38a1a5e + 3316e4a commit 952302a
Show file tree
Hide file tree
Showing 7 changed files with 527 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Avo::Fields::Common::Files::ControlsComponent < Avo::BaseComponent
delegate :id, to: :@field

prop :field, Avo::Fields::BaseField
prop :file, ActiveStorage::Attachment
prop :file, _Any
prop :resource, Avo::BaseResource

def destroy_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Avo::Fields::Common::Files::ViewType::GridItemComponent < Avo::BaseComponent
prop :field, Avo::Fields::BaseField
prop :resource, Avo::BaseResource
prop :file, _Nilable(ActiveStorage::Attachment)
prop :file, _Nilable(_Any)
prop :extra_classes, _Nilable(String)

def id
Expand Down
10 changes: 1 addition & 9 deletions app/components/avo/index/resource_controls_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
include Avo::ApplicationHelper
include Avo::Concerns::ChecksShowAuthorization

prop :resource, _Nilable(Avo::BaseResource)
prop :reflection, _Nilable(ActiveRecord::Reflection::AbstractReflection)
Expand All @@ -20,15 +21,6 @@ def can_edit?
@resource.authorization.authorize_action(:edit, raise_exception: false)
end

def can_view?
return false if Avo.configuration.resource_default_view.edit?

return authorize_association_for(:show) if @reflection.present?

# Even if there's a @reflection object present, for show we're going to fallback to the original policy.
@resource.authorization.authorize_action(:show, raise_exception: false)
end

def show_path
helpers.resource_show_path(resource: @resource, parent_or_child_resource: parent_or_child_resource, parent_resource: parent_resource, parent_record: @parent_record)
end
Expand Down
5 changes: 4 additions & 1 deletion app/components/avo/index/table_row_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class Avo::Index::TableRowComponent < Avo::BaseComponent
include Avo::ResourcesHelper
include Avo::Concerns::ChecksShowAuthorization

attr_writer :header_fields

Expand All @@ -24,5 +25,7 @@ def resource_controls_component
)
end

def click_row_to_view_record = Avo.configuration.click_row_to_view_record
def click_row_to_view_record
Avo.configuration.click_row_to_view_record && can_view?
end
end
18 changes: 18 additions & 0 deletions lib/avo/concerns/checks_show_authorization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Avo
module Concerns
module ChecksShowAuthorization
include Avo::Concerns::ChecksAssocAuthorization

extend ActiveSupport::Concern

def can_view?
return false if Avo.configuration.resource_default_view.edit?

return authorize_association_for(:show) if @reflection.present?

# Even if there's a @reflection object present, for show we're going to fallback to the original policy.
@resource.authorization.authorize_action(:show, raise_exception: false)
end
end
end
end
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"@hotwired/stimulus": "^3.2.2",
"@hotwired/turbo-rails": "^8.0.5",
"@rails/activestorage": "^6.1.7",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.14",
"@tailwindcss/forms": "^0.5.8",
"@tailwindcss/typography": "^0.5.15",
"@tiptap/core": "^2.6.6",
"@tiptap/extension-bold": "^2.6.6",
"@tiptap/extension-bullet-list": "^2.6.6",
Expand All @@ -42,7 +42,7 @@
"@tiptap/extension-text": "^2.6.6",
"@tiptap/extension-underline": "^2.6.6",
"@tiptap/pm": "^2.6.6",
"@yaireo/tagify": "^4.31.1",
"@yaireo/tagify": "^4.31.3",
"autoprefixer": "^10.4.20",
"chart.js": "^3.9.1",
"chartkick": "^4.2.0",
Expand All @@ -64,7 +64,7 @@
"luxon": "^3.5.0",
"mapkick": "^0.2.6",
"mousetrap": "^1.6.5",
"postcss": "^8.4.41",
"postcss": "^8.4.44",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-import": "^15.1.0",
"postcss-loader": "^7.3.4",
Expand All @@ -90,7 +90,7 @@
"esbuild-visualizer": "^0.3.1",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-import": "^2.30.0",
"prettier": "^2.8.8",
"prettier-plugin-erb": "^0.4.0"
},
Expand Down
Loading

0 comments on commit 952302a

Please sign in to comment.