No commit activity in last 3 years
No release in over 3 years
CanCanCan fields for rails_admin
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0

Runtime

< 6.0, >= 5.0
< 2.0, >= 1.0.0.rc
 Project Readme

RailsAdminUserAbilities

Rails 5 Support

That will add fields for access to models, objects and actions in rails_admin panel for specific users.

Installation

Add this line to your application's Gemfile:

gem 'rails_admin_user_abilities', '~> 0.2.0'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails_admin_user_abilities -v 0.2.0

Usage

Add in app/models/user.rb (temporary decision, it will be more configurable in future)

  has_one :ability, class_name: "RailsAdminUserAbilities::UserAbility", as: :rails_admin_user_abilitable
  scope :for_rails_admin, -> { where(:roles.in => ['admin', 'manager']) } # could be any you want, just need to

Add actions for rails_admin panel (in initializers/raisl_admin.rb)

RailsAdmin.config do |config|
  # some code
  config.actions do
    # some code

    user_abilities do
      visible do
        render_object = (bindings[:controller] || bindings[:view])
        render_object and render_object.current_user.admin? and
        ["User"].include? bindings[:abstract_model].model_name
      end
    end
    model_accesses do
      visible do
        render_object = (bindings[:controller] || bindings[:view])
        render_object and render_object.current_user.admin? and
        ["SomeModel1", "SomeModel2"].include? bindings[:abstract_model].model_name
      end
    end
  end
end

Also add method for set CanCanCan rules (in app/models/ability.rb)

class Ability
  include CanCan::Ability

  def initialize(user)
    # some code
    user.ability.to_cancancan(self) if user.ability
  end
end  

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake false to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/red-rocks/rails_admin_user_abilities.

License

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