I have a DirectoryController, and -- deliberately -- no UsersController. UsersController will doubtless be added when I create the administration controls, and will have a totally difference scope & purpose.
When I call policy_scoped in the directory controller, I want to use the scope from DirectoryPolicy and not UserPolicy (which doesn't exist yet). I want to do it in a way that verify_policy_scoped recognizes, which means the obvious work around of DirectoryPolicy::Scope.new(current_user, User).resolve is not only a tad long but also actually doesn't work. (Which seems like a bug) This seems like such an obvious oversight that I'm sure there's something, somewhere, to make this work, I just don't know what.
How do I do this in Pundit?
When you do this
you're effectively bypassing pundit's
policy_scoped?tracking.My first thought is that if
DirectoryPolicy::Scopeis intended to scope your user data, maybe you need to create aDirectorymodel as pundit expects. It could be as simple as thisNow when you have something like this in your
DirectoryControllerpundit can properly infer you want the
DirectoryPolicy::Scope, and yourresolvemethod can treat thescopeas if it were theUserclass because of the inheritance.If you can't subclass
Useras I describe here you'll need to show some actual code from your app and provide more context as to whatDirectoryis and what you're trying to do with it.