0.0
No commit activity in last 3 years
No release in over 3 years
Rule Based Access Control gem for Ruby on Rails applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.13
~> 5.0
~> 10.0
~> 3.0
 Project Readme

AuthorizeRbac

Installation

Add this line to your application's Gemfile:

gem 'authorize_rbac'

And then execute:

$ bundle

Or install it yourself as:

$ gem install authorize_rbac

Usage

  • Generate necessary changes

    • You can generate all migration using the follwing command

        bundle exec rails g authorize_rbac install
      
    • Or you can do it one by one

      bundle exec rails g authorize_rbac user_migrate
      bundle exec rails g authorize_rbac role_migrate
      bundle exec rails g authorize_rbac update_application_controller
      bundle exec rails g authorize_rbac update_user_model
      bundle exec rails g authorize_rbac initializer
      
    • Generator help

      bundle exec rails g authorize_rbac user_migrate
      
  • Check the generated files and update them if necessary

  • Execute migration

    bundle exec rake db:migrate
    
  • Update Controller Methods with the allowed roles

     class MyController < ApplicationController
    
      roles :admin
      def admin_only
        "admin"
      end
    
      roles :admin, :user
      def admin_and_user
        "admin_and_user"
      end
    
      def all
        "all"
      end
    end
    
    • Default role is user, you need to update the registration process to assign users to roles.
    • if roles is not defined for a given action, then the action is allowed for all users.
    • To add a dynamic permission for a given role from rails console, use the following commands
    $-> role = Role.find :id
    $-> role.permissions = [:admin_index]
    $-> role.save
    
    
  • role.permissions is an array of all allowed actions. The items of this array are constructed with the following schema "#{controller_name}_#{action_name}". for instance, to allow the action users on AdminController, you need to add this to the permissions list :admin_users.

License

The gem is available as open source under the terms of the MIT License.