nathanl / authority

*CURRENTLY UNMAINTAINED*. Authority helps you authorize actions in your Rails app. It's ORM-neutral and has very little fancy syntax; just group your models under one or more Authorizer classes and write plain Ruby methods on them.
MIT License
1.21k stars 67 forks source link

Allow resource to specify the authorizer by class #45

Closed mguymon closed 11 years ago

mguymon commented 11 years ago

Add the ability to define the authorizer by class, such as

self.authorizer_class = GreatAuthorizer

in addition to

self.authorizer_name = "GreateAuithorizer"

This will allow runtime classes to be used as the Authorizer.

For my scenario, we have a authorizer generator that tweaks the authorizer at runtime for each class.

nathanl commented 11 years ago

For my scenario, we have a authorizer generator that tweaks the authorizer at runtime for each class.

I'm having a hard time picturing your use case and would love to hear more about it if you care to explain.

For instance:

mguymon commented 11 years ago

The Rails app extensively uses STI, so a Content model will be subclassed into Article, SlideShow, etc. Authorized actions to the model also depends on a workflow (Article is approved by an Editor, so it can now be Read by a User). The ContentAuthorizerGenerator creates an Authorize class with configurations for the specific model being used. The authorizer is generated once for each model based on app's runtime config:

include Authority::Abilities
self.authorizer_class = ContentAuthorizerGenerator.create(Article, opts)
nathanl commented 11 years ago

I see. Well, the pull request is merged! I'll try to release a new version soon; in the meantime you can point your Gemfile to the merge commit on Github if you want.