Skip to content
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

Implement retrieval of individual permissions from the store #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Xylakant
Copy link
Contributor

@Xylakant Xylakant commented Aug 2, 2011

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
Copy link
Owner

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants