Subscribe to RSS Feed
Twitter
HIRE ME! home  archives  about  blogroll

Roleify, a rails authorization plugin

07 May 2009

Ha! Een nieuwe rails plugin: Roleify, a rails authorization plugin.

Deze plugin komt uit een lopend project van ons en ik dacht zo, we zullen die maar ineens opengooien. Ik heb er nog wel wat plannen mee, dus het zal zeker hier en daar nog wijzigen.

Here goes:

Roleify

A Rails authorization plugin

Dependent on Clearance (should be configurable in the future though)

Example

Make sure your User object has a “role” attribute (String).

Add an initializer

Roleify::Role.configure("role_a", "role_b") do
  {
    :role_a => { :issues =>  :all },
    :role_b => { :issues => "index" }
  }
end

In the example above “role_a” and “role_b” are the roles you are defining. The block contains the rules for these roles. There is no need to define an “admin” role, since it’s added by default.

The controller

class IssuesController < ActionController::Base
  include Clearance::Authentication
  include Roleify::RoleifyableController
end

The User model

class User < ActiveRecord::Base
  include Clearance::User
  include Roleify::RoleifyableModel
end

Extra’s

Constants:

Roleify::Role::ADMIN
Roleify::Role::ROLE_A
Roleify::Role::ROLE_B

Named scopes are automatically added:

User.admins
User.role_as
User.role_bs

Methods:

User.admin?
User.role_a?
User.role_b?

Questions? Shoot!

blog comments powered by Disqus