-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Hello, I'm working on a version of the authorizing processor that can support accept a resource instead of a class for create? and update? actions as referenced in #25 and several other issues.
The current behavior (only a class is given to create? and update?) is on by default. Users may switch to a resource-oriented create? and update? by toggling a configuration option. I was thinking about something like this:
JSONAPI::Authorization.configure do |config|
# Both are false by default
config.access_resource_on_create = true
config.access_resource_on_update = true
end
The configuration option changes how the callbacks are defined. That way we don't have to worry about introducing breaking changes to the default behavior, ie in authorizing_processor.rb:
...
if config.access_resource_on_create
# I'm not entirely sure that this is the correct way to hook into the save callback,
# but this at least shows what my intent is
set_callback :save, :around, :authorize_create_resource_with_resource
else
set_callback :create_resource, :before, :authorize_create_resource
end
if config.access_resource_on_update
set_callback :save, :around, :authorize_replace_fields_with_resource
else
set_callback :replace_fields, :before, :authorize_replace_fields
end
...
Assuming that I address edge cases that you mentioned in issue 25 (with the article.comments = comments example) and write corresponding tests and documentation, is this a feature that you would be willing to add to this gem? It's something that we need at my company so I plan on working on it regardless, but I know several other people here have also requested similar functionality.