Open
Description
In certain scenarios, it's desired to place policy classes that impact Avo within a specific namespace, like Avo::
, to distinguish authorization logic between Avo resources and those from other segments of the application. This approach helps keep authorization files organized, ensuring a clear separation between Avo policies and others.
In this discussion, we converged on a solution to achieve this (thanks to @coatezy for sharing!):
module Avo
class BaseResource < Avo::Resources::Base
def initialize(...)
super(...)
namespace_authorization_policy
end
private
def namespace_authorization_policy
policy_class = "Avo::#{model_class}Policy".safe_constantize
self.class.authorization_policy ||= policy_class || Avo::DefaultPolicy
end
end
end
Let's turn this discussion into a recipe
Metadata
Metadata
Assignees
Type
Projects
Status
Backlog