nu7hatch / aclatraz

Flexible access control mechanism!
MIT License
110 stars 6 forks source link

Implement retrieval of individual permissions from the store #7

Open Xylakant opened 13 years ago

Xylakant commented 13 years ago

It's possible to add individual permissions using suspect.roles.assign(:author, Page.find(15)) but so far it is impossible to enumerate those permissions. This patch implements the functionality for the redis store. Example

      suspect.roles.assign(:author, Page.find(15)) 
      suspect.roles.assign(:author, BlogEntry.find(15)) 
      suspect.roles.assign(:author, Book)
      suspect.roles.permissions(:author) => [[Page, 15], [BlogEntry, 15], Book]
      suspect.roles.permissions(:author, Page) # => [[Page, 15]]
      suspect.roles.permissions(:author, Page.find(1)) # => [[Page, 15]]
nu7hatch commented 13 years ago

This gem has been mainly designed for fast matching, not retrieving permissions. Retrieving all permission in this case may be highly not efficient. Do you have any particular use cases where u need to have all permissions? If no, i prefere to keep it simpler without unused features...

Xylakant commented 13 years ago

I do have a use-case: I have a set of documents in a database where individual users may have read permissions to single documents. Now I want to retrieve a list of documents that the user has read permissions to: It's simple if I can enumerate the individual permissions for the given user, but slow if i need to retrieve all documents and then check the permissions.

However, there is already a method that does retrieve the information - it's suspect.roles.all() it nearly does what I'd like to do and fetches all information from the store but it explicitly filters the individual permissions on single documents. I considered changing that method, but did not want to change the method's signature.