Re: acl9 gem

16 views
Skip to first unread message

Jason King

unread,
Dec 15, 2014, 9:28:39 PM12/15/14
to laurar...@gmail.com, acl9-d...@googlegroups.com
(CCing to the mailing list)

It's really very simple, there's an `accepted_roles` method that you can call on an object which will return all the `Role`s for a given object. The returned collection will contain the `collaborator` role, the `viewer` role, etc. PLUS you can call `users` on each of those role objects to get the collection of users for each role.

So, to get the above output in your view, you could basically iterate like this (using haml):

- @document.accepted_roles.each do |role|
  %h2= role.name.titelize
  %ul
    - role.users.each do |user|
      %li= user.name

Hope that helps.

Re your other question about limiting someone to just a single role, it has never come up because acl9 just combines the permissions of both in a sensible way, and the access_control block tends to make sense even when one of the roles is a deny role.

Re contributing, I've made the CONTRIBUTING doc, and laid things out as well as possible with issues for all the things that I know need doing, and I promise to review any Pull Request you might submit.

On Mon, Dec 15, 2014 at 4:36 PM, Laura DeWald <laura.r...@gmail.com> wrote:
Hi Jason,

I had a couple questions about gem usage that I was hoping you might be able to help me out with. 

I tried using the rolify gem (similar to acl9 role stuff) but just had too many issues with it, so I'm trying to switch over to acl9. 

I'll give you a brief intro to the app I need it for to hopefully make my questions a little bit more clear. 

I've got a Document object, which belongs to a User. I was to create 5 different "roles" that will be used in the view to show/hide certain things. The roles will be :owner, :collaborator, :editor, and :viewer. 

It's easy enough to set up the view permissions, but also in this view I want to output a list of each role type, so for example. jason.has_role!(:collaborator, @document), laura.has_role!(:owner, @document), and bill.has_role!(:viewer, @document)

I would want the view to list each category seperately, like:

Collaborators
  - Jason
Viewers
  - Bill

How difficult would this be to implement? I know that this issue exists which I believe would solve my problem, but I'm just wondering if maybe it's something I could get going now.

Second question, do you have any suggestions for adding a validation to ensure that a user can only have one role per object? For example, I wouldn't want to be able to give you both the :collaborator and :viewer role for the same document. This rolify issue sort of explains what I'm trying to figure out.

Thanks for any insight you have! I'd love to contribute to the project if there's any low hanging fruit that you want to get knocked out.

Thanks,
Laura
Reply all
Reply to author
Forward
0 new messages