-
Notifications
You must be signed in to change notification settings - Fork 143
Open
Description
Hello,
I know this has partially been reported already #171 but I think what proposed @ribordy is kinda nice. I would even imagine one step further like
class DemoResource
attribute :name, :string, readable: :readable?, writable: :writable?
attribute :role :string, readable: :readable?, writable: :writable?
def readable?(attr)
policy(model_instance).permitted_read_attributes.include?(attr)
end
def writable?(attr)
policy(model_instance).permitted_write_attributes.include?(attr)
end
end
class DemoPolicy
def index
# some logic
end
def update
# some logic
end
def permitted_read_attributes = %i[name role]
def permitted_write_attributes
if user.admin?
%i[name role]
else
%i[name]
end
end
end
That way we can leverage Pundit for what they call "permitted_attributes" too and have the read+write permissions at the same place => in the policy file, where I think it belongs.
Would that make sense?
mbajur and jkeen
Metadata
Metadata
Assignees
Labels
No labels