-
Most of the examples are written with one type of actor, For example, take a twitter clone. Who can do what with class Visitor::PostPolicy
def read?
true
end
def update?
false
end
end
class User::PostPolicy < Visitor::PostPolicy
# omitting `def read`, since it's the same as for visitors
def update?
record.user_id = user.id
end
end
class Admin::PostPolicy < Visitor::PostPolicy
def update?
true
end
end Is this a sensible approach? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey! Yeah, this approach is sensible; actually, the namespacing feature of Action Policy was built with something like this in mind (we had an app with separate controllers for different types of users). Authorization layer (e.g., policies) is connected to the entrypoint layer; so, it makes sense to organize policy the way entrypoints structured. |
Beta Was this translation helpful? Give feedback.
Hey!
Sorry for late reply.
Yeah, this approach is sensible; actually, the namespacing feature of Action Policy was built with something like this in mind (we had an app with separate controllers for different types of users).
Authorization layer (e.g., policies) is connected to the entrypoint layer; so, it makes sense to organize policy the way entrypoints structured.