RailsAdmin AuthorizedFields
This gem adds ability to setup authorization rules for fields in a simple way.
Installation
Add this line to your application's Gemfile:
gem 'rails_admin_authorized_fields'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rails_admin_authorized_fields
Usage
Just add authorized_fields section to your model with specified rules:
rails_admin do
( {
[ :enabled, :is_default, :text_slug ] => proc { bindings[:view]._current_user.has_role?( :admin ) },
[ :domain ] => proc { !bindings[:view]._current_user.has_role?( :manager ) },
} )
field :enabled
field :name
field :domain
field :is_default
field :text_slug
end
You can also use unauthorized_fields section in opposite of authorized_fields. All rules will be checked.
rails_admin do
( {
[ :enabled, :is_default, :text_slug ] => proc { bindings[:view]._current_user.has_role?( :manager ) },
} )
field :enabled
field :name
field :domain
field :is_default
field :text_slug
end
Note: all fields are authorized by default.
TODO: just a small changes needed to make authorized_fields section overridable in subsection (list, edit)
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request