Get roles for permissionable from principal #4

Closed
crystalneth opened this Issue Mar 13, 2010 · 6 comments

Comments

Projects
None yet
3 participants
Contributor

crystalneth commented Mar 13, 2010

For some display screens, I'd like to be able to get a list of roles for a principal over a given permissionable.

E.g.:
@principal.roles_for(@permissionable)

[:admin, :member]

I'm still a bit confused by some of the sanction code to put this in there properly.

Owner

matthewvermaak commented Mar 13, 2010

As of right now to access this information you would:

Sanction::Role.for_principals(@principal).for_permissionables(@permissionable).map(&:name)

This definitely seems like a reasonable utility method that should be cleaned up and accessible off of the@principal and @permissionable themselves. Most likely as association methods on principal_roles / permissionable_roles; this reasoning is supported by the fact that a principal can act as a permissionable as well. Therefore I envision the api to be extended as:

@principal.principal_roles.over(@permissionable)

Owner

matthewvermaak commented Mar 13, 2010

Pushed to master: ed5614c

This commit demonstrates the extended api concerning principal_roles / permissionable_roles. For example:

@principal.principal_roles.over(@permissionable)

will yield the role records, which then could be map'd for names.

These changes will be pushed to 1-1-stable pending review.

Contributor

crystalneth commented Mar 13, 2010

Awesome guys. So quick.

Collaborator

pjleonhardt commented Mar 13, 2010

I'll review this and aliix's pull request later today.

Collaborator

pjleonhardt commented Mar 14, 2010

All looks good to me.
Tests pass & pass with table name changed (mysql, dont have postgres installed).

Matt, feel free to merge this into stable.

Owner

matthewvermaak commented Apr 13, 2010

These changes have been pushed to 1-1-stable. Closing the issue.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment