Replies: 1 comment
-
Let me think about this use-case (not something we usually deal with). First, the model is namespaced ( Then, about the implicit target: def implicit_authorization_target
controller_path.gsub('web/','').classify.safe_constantize
end It should be: "portal/web/organizations".gsub('web/'. '').classify.safe_constantize #=>
"portal/organizations".classify.safe_constantize #=>
"Portal::Organization".safe_constantize #=>
Portal::Organization The same problem as in the first case (the lookup chain is the same). How can we deal with this? First of all, the namespacing looks good to me: we have a namespace = "Portal::Web"
policy = "Portal::OrganizationPolicy"
# drop Portal from the record and the namespace
namespace = "Web"
record = "OrganizationPolicy" Now we should be able to find "Web::OrganizationPolicy" (which would resolve into I think, we can implement this. (Though I need to think carefully about potential side-effects). For now, you can do the following two modifications:
class Portal::Organization < AR
def self.policy_name = "OrganizationPolicy"
end That would made record-based lookups work.
def implicit_authorization_target
controller_path.gsub('portal/web/','').to_sym
end That should make record-less lookups work. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I'm currently facing the situation, that I have a central model
Portal::Organization
with I would like to expose via a namespaced controllerPortal::Web::Organization
and also viaPortal::Api::Organization
. The authentication and authorization within theweb
namespace should be different from theapi
namespace.The policy classes are namespaced accordingly:
Portal::Web::OrganizationPolicy
andPortal::Api::OrganizationPolicy
.My current setup looks like this:
This setup leads to:
and when I overwrite the
implicit_authorization_target
with the following implementation (see also #170 (comment)):I get
Couldn't find policy class for Portal::Organization
. So I can provide like:and everything works nicely, but providing the "with" option every time, smells from my perspective a bit. So I was wondering if there is a known and supported way of providing the "with" option to the authorized_scope method, without overwriting?
Maybe I'm also doing something very strange here, but I'm kind of following the example implementation from the documentation, with the only difference that my base model is namespaced in
Portal
.Thanks for any support on this!
Beta Was this translation helpful? Give feedback.
All reactions