-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to setup access_policy.rb when roles are not part of a user model? #51
Comments
Would it help to just use the |
Like @jrochkind said, you should check for specific role inside |
Many to many relationships with this are tough, and by default was extremely non-DRY. In my case, my User model has rights to perform actions on other users, projects, etc. (about 12 different classes), with a bunch of conditional cases. So, extracting it to a clean pattern was challenging. So, what i did was create a Concern that I included into the I thought about forking and letting you pass a helper method, but that seemed like overkill. It seems to be working now, but I thought I'd share what I did in case future version want to make it all easier. Here's the important part/example of the mixin. No point in pasting 100s of lines.
My UserAccess class has a single method that wraps other "relational check" methods using a case statement to find the right way to extract the relational roles, so I can make the language in the "can" statement super simple.
Then, I mixed the PolicyBase into the class, as I said.. and then added it to the top of the policy file.
So you can see that the It's a great gem and does really simplify doing this by hand. Thanks for the work! Please let me know if there will be major unintended consequences to what I did. :-) |
I'm pretty new to Rails, however, I work on the app where I have this trio:
users, wikis, wiki_users
. Many users can be assigned to many wikis and vice versa.I struggle with connecting my
access_policy.rb
file with Rails. How could I let the gem know that it should look for user, assigned to a specific wiki with a specific role on that specific wiki?My project_users table contains columns
id
(of the relationship),user_id
,project_id
, androle
. Myaccess_policy.rb
file looks like this so far, with some effort to make it work inrole :reader
block. However, it all feels just like a workaround and I am wondering whether this scenario can't be handeled in easier manner?The text was updated successfully, but these errors were encountered: