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

feature: apply target resource policy on belongs_to field create new link #2934

Merged
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
6 changes: 5 additions & 1 deletion lib/avo/fields/belongs_to_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,12 @@ def index_link_to_record
end
end

# field :user, as: :belongs_to, can_create: true
# Only can create when:
# - `can_create: true` option is present
# - target resource's policy allow creation (UserPolicy in this example)
def can_create?
@can_create
@can_create && target_resource.authorization.authorize_action(:create, raise_exception: false)
end

def form_field_label
Expand Down
Loading