Code Monkey home page Code Monkey logo

the_role's Introduction

TheRole 3.0

Authorization gem for Ruby on Rails with Management Panel

TheRole. Authorization gem for Ruby on Rails with Administrative interface

Semantic. Flexible. Lightweight

TheRole: Gem Version API: Gem Version GUI: Gem Version CI: Build Status  ruby-toolbox

Strongly recommended to upgrade from TheRole2 to TheRole3. Please, do it ASAP.


INTRO

TheRole is an authorization library for Ruby on Rails which restricts what resources a given user is allowed to access. All permissions are defined in with 2-level-hash, and stored in the database as a JSON string.

TheRole. Authorization gem for Ruby on Rails with Administrative interface

Using hashes, makes role system extremely easy to configure and use

  • Any Role is a two-level hash, consisting of the sections and nested rules
  • A Section may be associated with a controller name
  • A Rule may be associated with an action name
  • A Section can have many rules
  • A Rule can be true or false
  • Sections and nested Rules provide an ACL (Access Control List)

Management Panel

http://localhost:3000/admin/roles
TheRole GUI

Import/Export operations provided via TheRole Management Panel. If you have 2 Rails apps, based on TheRole - you can move roles between them via export/import abilities of TheRole Management Panel. It can be usefull for Rails apps based on one engine.

TheRole. Authorization gem for Ruby on Rails with Administrative interface

Limitations by Design

TheRole uses few conventions over configuration. It gives simplicity of code, but also some limitations. You have to know about them before using of TheRole: Limitations list



FAQ


We need your feedback!

If you have to say something about TheRole, or if you need help, there are few ways to contact us:

  1. SKYPE: ilya.killich
  2. Email: [email protected]
  3. TWITTER: @iam_teacher
  4. Hash tag: #the_role
  5. Google group: about the_role

Test matrix

  • RAILS: 3.2.21, 4.0, 4.1, 4.2
  • RUBY: 1.9.3, 2.0, 2.1, 2.2
  • DB: sqlite, mysql, postgresql

totally: 48 environments


Supported locales: the_role_api | the_role_management_panel (please, help us with them)


MIT License

MIT License Copyright (c) 2012-2015 Ilya N.Zykin

Maintainers

@the-teacher, @sedx, @seuros

Contributors

@igmarin @doabit @linjunpop @egb3 @klacointe @niltonvasques

Thanks for contributors

the_role's People

Contributors

alex808r avatar daanforever avatar edgarortegaramirez avatar ekatebenkova avatar fabianoarruda avatar igmarin avatar joeunrue avatar o-200 avatar olleolleolle avatar onemanstartup avatar pavelandr1207 avatar pomahtuk avatar query-string avatar rrrene avatar seuros avatar sk8higher avatar styx avatar the-teacher avatar unimatrixzxero avatar yuanping avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

the_role's Issues

`create_section': undefined method `[]' for nil:NilClass (NoMethodError)

HI!
I am receiving:
.rvm/gems/ruby-2.1.0/gems/the_role-2.5.4/app/models/concerns/role.rb:58:in create_section': undefined method[]' for nil:NilClass (NoMethodError)
from /home/system/.rvm/gems/ruby-2.1.0/gems/the_role-2.5.4/app/models/concerns/role.rb:65:in create_rule' from /home/system/.rvm/gems/ruby-2.1.0/gems/the_role-2.5.4/lib/generators/the_role/the_role_generator.rb:51:increate_admin_role'
from /home/system/.rvm/gems/ruby-2.1.0/gems/the_role-2.5.4/lib/generators/the_role/the_role_generator.rb:14:in generate_controllers' from /home/system/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/command.rb:27:inrun'
from /home/system/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:120:in invoke_command' from /home/system/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:127:inblock in invoke_all'
from /home/system/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:127:in each' from /home/system/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:127:inmap'
from /home/system/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:127:in invoke_all' from /home/system/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/group.rb:233:indispatch'
from /home/system/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/base.rb:439:in start' from /home/system/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/generators.rb:156:ininvoke'
from /home/system/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands/generate.rb:11:in <top (required)>' from /home/system/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:inrequire'
from /home/system/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in block in require' from /home/system/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:inload_dependency'
from /home/system/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in require' from /home/system/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:48:in<top (required)>'
from bin/rails:4:in require' from bin/rails:4:in

'

When I am trying to execute: bundle exec rails g the_role admin
I was following steps from README and tried to update my existing project.
Any ideas?

Postgres and the role

I followed the documentation you mentioned about the migration and also for Postgres SQL, while when putting this code in role model

`def _jsonable val
val.is_a?(Hash) ? val : JSON.load(val)
end

def to_hash
begin the_role rescue {} end
end

def to_json
the_role.is_a?(Hash) ? the_role.to_json : the_role
end`

It keeps looping and redirecting in my applications, while it makes all my test cases pass If I removed it, the application runs normally and most of the test cases failed. should I change the_role field to JSON as well or keep the current setup. I used to use version 2.3

another issue that edit in place is not working and it says this message

No route matches [PATCH] "/admin/roles/4/change"

I followed the route migrations steps, but this does not work with me, any solution

What is the 'right' way to restrict access to nested resource index action?

I have a nested ExpenseReport model with a has_many association in regards to User.
I want to protect the index action addressable by /users/:user_id/expense_reports/ so that only the admins or a user with id == :user_id. (the current_user is the owner)

My problem is how to set the @owner_check_object in the expenseReportsController index action.
I started by setting it to @user.expense_reports.first but this will fail if the user doesn't have any expense reports.

I can create a new empty object but this doesn't feel the right way to me.
I looked at the docs and the demo app but this scenario is not addressed.
Thanks in advance.

After add "has_roles" I get errror

After add 'has_roles' to User

class User < ActiveRecord::Base

  has_roles

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  belongs_to :role
end

I got this error:

/home/deim/.rvm/rubies/ruby-2.0.0-p247/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/deim/workspace/rails/keepinfo/bin/rails server -b 0.0.0.0 -p 3000 -e development
=> Booting Thin
=> Rails 4.0.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined local variable or method `has_roles' for User(no database connection):Class (NameError)
    from /home/deim/workspace/rails/keepinfo/app/models/user.rb:3:in `<class:User>'
    from /home/deim/workspace/rails/keepinfo/app/models/user.rb:1:in `<top (required)>'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:424:in `load'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:424:in `block in load_file'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:616:in `new_constants_in'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:423:in `load_file'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:324:in `require_or_load'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:463:in `load_missing_constant'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:184:in `const_missing'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/inflector/methods.rb:226:in `const_get'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/inflector/methods.rb:226:in `block in constantize'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/inflector/methods.rb:224:in `each'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/inflector/methods.rb:224:in `inject'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/inflector/methods.rb:224:in `constantize'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:535:in `get'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:566:in `constantize'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise.rb:297:in `get'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise/mapping.rb:77:in `to'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise/mapping.rb:72:in `modules'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise/mapping.rb:89:in `routes'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise/mapping.rb:156:in `default_used_route'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise/mapping.rb:66:in `initialize'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise.rb:331:in `new'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise.rb:331:in `add_mapping'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise/rails/routes.rb:218:in `block in devise_for'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise/rails/routes.rb:217:in `each'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.1/lib/devise/rails/routes.rb:217:in `devise_for'
    from /home/deim/workspace/rails/keepinfo/config/routes.rb:3:in `block in <top (required)>'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:341:in `instance_exec'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:341:in `eval_block'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:319:in `draw'
    from /home/deim/workspace/rails/keepinfo/config/routes.rb:1:in `<top (required)>'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in `load'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in `block in load'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in `load'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `each'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/file_update_checker.rb:75:in `call'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/file_update_checker.rb:75:in `execute'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `run'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/deim/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from /home/deim/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /home/deim/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from /home/deim/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from /home/deim/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from /home/deim/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from /home/deim/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/application.rb:215:in `initialize!'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/deim/workspace/rails/keepinfo/config/environment.rb:5:in `<top (required)>'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `block in require'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require'
    from /home/deim/workspace/rails/keepinfo/config.ru:3:in `block in <main>'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
    from /home/deim/workspace/rails/keepinfo/config.ru:in `new'
    from /home/deim/workspace/rails/keepinfo/config.ru:in `<main>'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands/server.rb:48:in `app'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands/server.rb:75:in `start'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands.rb:76:in `block in <top (required)>'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands.rb:71:in `tap'
    from /home/deim/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/commands.rb:71:in `<top (required)>'
    from /home/deim/workspace/rails/keepinfo/bin/rails:4:in `require'
    from /home/deim/workspace/rails/keepinfo/bin/rails:4:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

Process finished with exit code 1

deep_stringify_keys

I noticed that the console gives the out the following message:

TheRole => RAILS 4 like method deep_stringify_keys mixed to HASH class

Using rails 3.2.3.

Error running demo (default configuration)

~ Hi

I was testing this gem (looks very good) and run the demo, previously run the "bundle", "migration" and "seed", I found this error:

Sprockets::Rails::Helper::DependencyError in Welcome#index

Asset depends on 'bootstrap/glyphicons-halflings-regular.eot' to generate properly but has not declared the dependency
Please add: `//= depend_on_asset "bootstrap/glyphicons-halflings-regular.eot"` to '/home/xxxx/.rvm/gems/ruby-2.0.0-p353@the_role/bundler/gems/bootstrap-sass-b9bb1967d3e8/vendor/assets/stylesheets/bootstrap.scss'
  (in /home/xxxx/.rvm/gems/ruby-2.0.0-p353@the_role/bundler/gems/bootstrap-sass-b9bb1967d3e8/vendor/assets/stylesheets/bootstrap.scss)

captura de pantalla de 2013-12-12 21 51 49

After several attempts to solve this I had to add these lines:

//= depend_on_asset "bootstrap/glyphicons-halflings-regular.eot"
//= depend_on_asset "bootstrap/glyphicons-halflings-regular.woff"
//= depend_on_asset "bootstrap/glyphicons-halflings-regular.ttf"
//= depend_on_asset "bootstrap/glyphicons-halflings-regular.svg"

@import "bootstrap/bootstrap";

As I said, did not modify anything, just ran the demo default. If it helps here is the list of gems installed on the gemset "the_role" created to test the project.

*** LOCAL GEMS ***

actionmailer (4.0.2)
actionpack (4.0.2)
activemodel (4.0.2)
activerecord (4.0.2)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.2)
arel (4.0.1)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
bigdecimal (1.2.0)
builder (3.1.4)
bundler (1.3.5)
bundler-unload (1.0.2)
coffee-script (2.2.0)
coffee-script-source (1.6.3)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.0.2)
executable-hooks (1.2.6)
factory_girl (4.3.0)
factory_girl_rails (4.3.0)
faker (1.2.0)
haml (4.0.4)
hike (1.2.3)
i18n (0.6.9)
io-console (0.4.2)
jbuilder (1.0.2)
jquery-rails (3.0.4)
json (1.8.1, 1.7.7)
mail (2.5.4)
mime-types (1.25.1)
minitest (4.7.5, 4.3.2)
multi_json (1.8.2)
orm_adapter (0.5.0)
polyglot (0.3.3)
psych (2.0.0)
rack (1.5.2)
rack-test (0.6.2)
rails (4.0.2)
railties (4.0.2)
rake (10.1.0, 10.0.4, 0.9.6)
rdoc (4.0.0)
rspec (2.14.1)
rspec-core (2.14.4)
rspec-expectations (2.14.4)
rspec-mocks (2.14.4)
rspec-rails (2.14.0)
rubygems-bundler (1.4.2)
rvm (1.11.3.8)
sass (3.2.12)
sprockets (2.10.1)
sprockets-rails (2.0.1)
sqlite3 (1.3.8)
state_machine (1.2.0)
test-unit (2.0.0.0)
thor (0.18.1)
thread_safe (0.1.3)
tilt (1.4.1)
treetop (1.4.15)
tzinfo (0.3.38)
uglifier (2.3.3)
warden (1.2.3)

the_role hash

x = Role.first
x.the_role = {:system => {:administrator => true}}
x.save

User.first.update_attribute(:role_id, x.id)

then if i remove begin...rescue block in to_hash method inside the_role i see crash -

795: unexpected token at '---
system:
  administrator: true
'

in the_role (1.7.0) lib/the_role/modules/role_model.rb:55:in `to_hash'

I'm using postgres. field is saved as the_role: "---\nsystem:\n administrator: true\n"

Is there something wrong with serialization. changing from JSON.load to YAML.load helps

undefined local variable or method `login_required'

I got this error:

Started GET "/admin/roles" for 127.0.0.1 at 2013-11-24 20:21:35 +0400
Processing by Admin::RolesController#index as HTML
Completed 500 Internal Server Error in 4ms

NameError - undefined local variable or method `login_required' for #<Admin::RolesController:0x00000003385150>:
  activesupport (4.0.1) lib/active_support/callbacks.rb:407:in `_run__1774266526836032881__process_action__callbacks'
  activesupport (4.0.1) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (4.0.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.0.1) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.0.1) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.1) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.0.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
  activerecord (4.0.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.0.1) lib/abstract_controller/base.rb:136:in `process'
  actionpack (4.0.1) lib/abstract_controller/rendering.rb:44:in `process'
  actionpack (4.0.1) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.0.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.0.1) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.0.1) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.0.1) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.0.1) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.0.1) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.0.1) lib/action_dispatch/routing/route_set.rb:680:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  actionpack (4.0.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.0.1) lib/action_dispatch/middleware/flash.rb:241:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.0.1) lib/action_dispatch/middleware/cookies.rb:486:in `call'
  activerecord (4.0.1) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.0.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
  activerecord (4.0.1) lib/active_record/migration.rb:369:in `call'
  actionpack (4.0.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.1) lib/active_support/callbacks.rb:373:in `_run__2521567753640078128__call__callbacks'
  activesupport (4.0.1) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.1) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.1) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  better_errors (1.0.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (1.0.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (1.0.1) lib/better_errors/middleware.rb:56:in `call'
  actionpack (4.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.1) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.1) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.1) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.1) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.1) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.0.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.1) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.1) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.0.1) lib/rails/engine.rb:511:in `call'
  railties (4.0.1) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  thin (1.6.1) lib/thin/connection.rb:82:in `block in pre_process'
  thin (1.6.1) lib/thin/connection.rb:80:in `pre_process'
  thin (1.6.1) lib/thin/connection.rb:55:in `process'
  thin (1.6.1) lib/thin/connection.rb:41:in `receive_data'
  eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
  thin (1.6.1) lib/thin/backends/base.rb:73:in `start'
  thin (1.6.1) lib/thin/server.rb:162:in `start'
  rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
  rack (1.5.2) lib/rack/server.rb:264:in `start'
  railties (4.0.1) lib/rails/commands/server.rb:84:in `start'
  railties (4.0.1) lib/rails/commands.rb:76:in `block in <top (required)>'
  railties (4.0.1) lib/rails/commands.rb:71:in `<top (required)>'
  bin/rails:4:in `<top (required)>'
  -e:1:in `<main>'

How to fix it?

Why this deprecation warning?

Whenever I fire up any rails command or rake command, I always see this msg:

[TheRole] RAILS 4 like method **deep_transform_keys** mixed to HASH class
[TheRole] RAILS 4 like method **deep_stringify_keys** mixed to HASH class

What does it mean and how to avoid this?

Styles not applied

I am using the_role with my app. Everything works fine but the styles are not applied to the admin area, or at least it doesn't look like the screenshot in the README. Here is what it looks like:

The Role Admin Area - Styles not applied

I am using bootstrap-sass and here is what my application.css.scss looks like:

@import "bootstrap";
@import "font-awesome";
//= require_self
//= require_directory .
//= require the_role/bootstrap_sass
//= require the_role

And the section where I yield the sections:

<div class="container-fluid">
  <div class="row-fluid">
    <div class="span3">
      <div class="sidebar-nav">
        <%= yield :role_sidebar %>
      </div>
    </div>
    <div class="span9">
      <%= ariane.render %>
      <%= bootstrap_flash %>
      <%= yield :role_main %>
    </div>
  </div><!--/row-->
</div> <!-- /container -->

Notice style?

How can i change notice style for the_role "Access Denied" message?

Uploaded application with the_role implemented to server:

"uninitialized constant User::TheRole"

I pulled down my additions from git and reset database and so on. But now I have no idea what is wrong - it complains that TheRole is not initialized.
I installed the gem with bundle install, any clues?

'Semantic' improvement on own objects

Nice gem approach for authorization...i like the gui usability!

Just one comment, maybe an other option to add (apart for enable/disable an action), is the possibility to specify from whom the object could be; i.e. "edit or destroy objects created by me (current_user) only, or by my group (group users functionality)"

By the way, is any option to avoid coding in every view link the "if permmission", making that automaticaly based on the actions would be awesome too (some gems use a view:helper...but is not the best approach)

I cannot make a user to admin.

I just implemented TheRole together with Devise in a Rails 4.0 application.
I followed the installation and did the :
"bundle exec rails g the_role admin"

With response that 'Admin role exists'.

But when running the "User.first.update( role: Role.with_name(:admin) )"
I only receive bash: syntax error near unexpected token `role:'.

I implemented everything like the installation said :/

Several Issues - the instructions say one thing generator does another

The Role model on the tutorial - include TheRole::Role . However if you use the generator it makes it RoleModel::Role .

In my own app, I am getting errors like - NameError: uninitialized constant TheRole::AdminRoutes . Adding admin refuses to work. Again the db has the field the_role (text) and just id as the unique. Should it be role_id?
Installing the dummy program does not work as described because of issues with the_role_bootstrap3_ui not found in the repository. sprockets also throws errors from bundle.
I am too new to rails to figure all this out, but I have checked the instructions close.
I am using rails 4.1.6 and MySql. I am going through it one more time from the beginning to get the first trace to post here as soon as I can.

Wrong information in wiki's example

Hi, I was reading your wiki's information and I couldn't make your gem work, after many hours trying to make it work, I realized something.

In Integration with Devise2, you defined this:
alias_method :role_access_denied, :access_denied

But in the controller example, you're calling this:
before_filter :role_required, :except => [:index, :show]
And it doesn't exist, because you called it role_access_denied.

db:roles:create creating error

Hi Teacher teacher ;)
when I run "bundle exec rake db:roles:create" I get the following error.
rake aborted!
Don't know how to build task 'db:roles:create'

I followed the install instructions on the homepage readme. then noticed the readme in the wiki was different.

Unable to create new Role

Ok so clean Rails 4 project and hopefully setup TheRole correctly.

When trying to create a new Role getting error:

ActiveModel::ForbiddenAttributesError in Admin::RolesController#create

Nothing else on page. Any ideas?

Model name isn't configurable?

I was reading the code to find a solution for my issue. I'm using the_role as a role manager on my model that is called Admin.

Then, when I try to delete one role, it returns the following error:

ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: people.role_id: SELECT 1 AS one FROM "people" WHERE "people"."type" IN ('User') AND "people"."role_id" = ?
LIMIT 1

Since my model is admin it should be admins.role_id, isn't that right?

I see that the relationship is set on this file (line 21):

https://github.com/the-teacher/the_role/blob/master/app/models/concerns/role.rb#L21

My question is: there's a non documented way to do that or may it being not defined as I expect?

Thanks in advance,
Vinícius Ebersol

the_role + devise 2.1.2 + rails 3.2.8

alias_method :login_required, :authenticate_user! causes crash on start

application_controller.rb:6:in alias_method': undefined methodauthenticate_user!' for class `ApplicationController' (NameError)

As i understood authenticate_user created later that alias method requires it. Any workaround for it?

Without this alias everything works well, except roles admin page. It requires method 'login_required'

for now i'm using

def login_required
  authenticate_user!
end

I18n::MissingTranslationData in Admin::Roles#index

After follow the installation instruction for GUI manage roles,, when I try to access the /admin/role page, i have this error (show the title of this issue).
error log show me:
"Showing /home/jerome/.rvm/gems/ruby-2.2.2/gems/the_role_management_panel-3.0.2/app/views/admin/roles/_sidebar.html.haml where line #11 raised:"
" translation missing: en.admin.roles.sidebar.roles_list"
and from line 311:
" raise exception.respond_to?(:to_exception) ? exception.to_exception : exception"
Trace of template inclusion: /home/jerome/.rvm/gems/ruby-2.2.2/gems/the_role_management_panel-3.0.2/app/views/admin/roles/index.haml

update_attributes not working

This is a weird one, but it looks like the_role is preventing update_attributes() from performing mass-assignment. Although it returns true, no field is changed. When I removed the gem, it works fine.

I just noticed now and very surprised that there are no specs.

I think the line:

User.send :include, TheRole::UserModel if the_class_exists? :User

might be the culprit.

I suggest removing this block altogether as it's making the assumption that the user model and application controller is the target and in my case it's not:

config.to_prepare do
Role.send :include, TheRole::RoleModel if the_class_exists? :Role
User.send :include, TheRole::UserModel if the_class_exists? :User
ApplicationController.send :include, TheRole::Requires if the_class_exists? :ApplicationController
end

Multiple roles for one user

Hello, is it posible to assign multiple roles to a user. In cancan for example it posible and he store role_id in a single integer column using a bitmask. Mayby you changed your model to HABTM association? Or the other way makes a nested roles, when one role is member of others. This feature is very very needed.

Many thanks!

The /admin/roles page has flaws.

When I select a role from the role i come to the link "/admin/roles/2/edit", but then I cannot edit the information.
When I am in the first window, I can edit my first role, but there is no way for me to edit any other.

It only fails when I follow the link from the "Roles List"

Migrating existing app to TheRole

Hi,

i need some help understanding how TheRole is working.
I have an application with:

  • devise
  • cancancan
  • rolify

This application is also multi-tenant, so each company account has many users.
There is an increasing need of company administrators to define their custom roles and set permissions to their users.

So, currently I have a predefined list of roles (admin, manager, user) with predefined permissions.
I was looking around what would be the best way to implement administrator defined roles /permissions and I found out TheRole gem which looks promising.

I basically have 2 general questions:

  • what do i need to do to replace cancancan/rolify with TheRole (devise so of course stay)
  • is it possible to integrate the role management panel with my own skin

I don't need very detailed information, but a general view on how to approach this problem of replacing current situation with the gem. What are the gotchas, where can problems arise.

Thanks for any reply!

Conflict with Active Admin

I'm trying to use the_role in my rails 4.0.2 app, but after I add the gem into my Gemfile, I get the following error message when trying to run any rails command:

activesupport-4.0.2/lib/active_support/dependencies.rb:464:in `load_missing_constant': 
Unable to autoload constant Base, 
expected /opt/boxen/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/the_role-2.3/app/models/concerns/base.rb 
to define it (LoadError)

Any ideas?

unable to open selection from comboBox for enable/disable a rule

under firefox-38.0.5 from archlinux, i can not use the comboBox for enable a new rule.
This is from the GUI admin Role page. is it from bootstrap and how to find information for fix/resolve the problem ? (i read something around dropdown function who is not same interprted by web browsrs engines... but i think from css and javascript, it could be possible to add codes to take care so many different un-standardised way of thinking for all of them)
Also, i installed chromium... same problem occurs.
Opera just don't want to show me localhost:3000 (i directly uninstall it quickly).
And Microsoft IE or Safary Apple... i really don't want to touch this anymore and i will not. :)
thank you.

undefined method name for User

u.try(:name) || u.try(:username) || u.try(:login)|| u.try(:email) || u.id

causes undefined method name with devise.

atm solved as

def name
  email
end

in user model

Cannot define multiple included blocks for a Concern

Hi,

Im using the_role for a project with rails 4.2 and just hited this issue while running bundle exec rails g the_role admin, here's the stacktrace:

/home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/concern.rb:126:in `included': Cannot define multiple 'included' blocks for a Concern (ActiveSupport::Concern::MultipleIncludedBlocks)
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/the_role-2.5.4/app/models/concerns/role.rb:18:in `<module:Role>'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/the_role-2.5.4/app/models/concerns/role.rb:2:in `<module:TheRole>'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/the_role-2.5.4/app/models/concerns/role.rb:1:in `<top (required)>'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:457:in `load'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:457:in `block in load_file'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:647:in `new_constants_in'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:456:in `load_file'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:354:in `require_or_load'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:494:in `load_missing_constant'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:184:in `const_missing'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:526:in `load_missing_constant'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:184:in `const_missing'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/the_role-2.5.4/lib/generators/the_role/the_role_generator.rb:44:in `create_admin_role'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/the_role-2.5.4/lib/generators/the_role/the_role_generator.rb:14:in `generate_controllers'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/railties-4.2.0/lib/rails/generators.rb:157:in `invoke'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/railties-4.2.0/lib/rails/commands/generate.rb:13:in `<top (required)>'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:130:in `generate_or_destroy'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:50:in `generate'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /home/developer/.rvm/gems/ruby-2.0.0-p481@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'

Making user admin.

"ActiveModel::MissingAttributeError: can't write unknown attribute `role_id'"

when running: User.first.update( role: Role.with_name(:admin) )

Rails 4.1 compatibility

First, I wanted to thank you for the work you've done with this great gem. I've used it in quite a few applications and it's saved me a bunch of time.

I'm currently working on a new application and it's using the new Rails 4.1 and I'm having a little difficulty getting a couple parts to work properly and I was wondering if this was a known issue or if I'm doing something wrong. The full application stack is ruby 2.0.0-p0, rails 4.1 and postgresql 9.2. I've made sure that I'm using the latest gem version of 2.5.4. Here's from my Gemfile.lock

    the_role (2.5.4)
      rails (>= 3, < 5)
      the_string_to_slug (~> 1.2)
    the_role_bootstrap3_ui (1.1)
      haml
      rails (>= 3, < 5)

Everything works as usual with the exception of sections and rules. When I attempt to create a rule or section, it's returning true, however the role hash does not get updated. I get the same behavior from both the UI (I'm using your the_role_bootstrap3_ui gem) and from the console.

Here's an example output from the console

[3] pry(main)> @role = Role.last
  Role Load (0.5ms)  SELECT  "roles".* FROM "roles"   ORDER BY "roles"."id" DESC LIMIT 1
=> #<Role id: 2, name: "not_admin", title: "Not Admin", description: "Not an admin role", the_role: {}, created_at: "2014-04-09 19:46:29", updated_at: "2014-04-09 19:46:29", parent_id: nil, lft: 3, rgt: 4, depth: 0>
[4] pry(main)> @role.create_section(:pages)
   (0.2ms)  BEGIN
  Role Exists (0.7ms)  SELECT  1 AS one FROM "roles"  WHERE ("roles"."name" = 'not_admin' AND "roles"."id" != 2) LIMIT 1
  Role Exists (0.2ms)  SELECT  1 AS one FROM "roles"  WHERE ("roles"."title" = 'Not Admin' AND "roles"."id" != 2) LIMIT 1
  Role Load (0.3ms)  SELECT  "roles".* FROM "roles"  WHERE "roles"."id" = $1 LIMIT 1  [["id", 2]]
  SQL (0.7ms)  UPDATE "roles" SET "depth" = 0 WHERE "roles"."id" IN (SELECT "roles"."id" FROM "roles"  WHERE "roles"."id" = 2  ORDER BY "lft")
   (2.7ms)  COMMIT
=> true

The output from the log looks pretty much the same

Started POST "/admin/roles/2/sections" for 127.0.0.1 at 2014-04-09 13:12:34 -0700
Processing by Admin::RoleSectionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"QLrU1rw8CjJvAR1U8ASu0jl1z56iAR237r9WgzHn9As=", "section_name"=>"pages", "commit"=>"Create new section", "role_id"=>"2"}
  User Load (0.3ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
  Role Load (0.3ms)  SELECT  "roles".* FROM "roles"  WHERE "roles"."id" = $1 LIMIT 1  [["id", 1]]
  Role Load (0.2ms)  SELECT  "roles".* FROM "roles"  WHERE "roles"."id" = $1 LIMIT 1  [["id", 2]]
   (0.1ms)  BEGIN
  Role Exists (0.5ms)  SELECT  1 AS one FROM "roles"  WHERE ("roles"."name" = 'not_admin' AND "roles"."id" != 2) LIMIT 1
  Role Exists (0.2ms)  SELECT  1 AS one FROM "roles"  WHERE ("roles"."title" = 'Not Admin' AND "roles"."id" != 2) LIMIT 1
  Role Load (0.3ms)  SELECT  "roles".* FROM "roles"  WHERE "roles"."id" = $1 LIMIT 1  [["id", 2]]
  SQL (0.6ms)  UPDATE "roles" SET "depth" = 0 WHERE "roles"."id" IN (SELECT "roles"."id" FROM "roles"  WHERE "roles"."id" = 2  ORDER BY "lft")
   (0.5ms)  COMMIT

In either case it doesn't look like the role hash is being updated at all. Is there something that I'm missing or did I configure something wrong here?

The title of The Roles admin page shows "TheRoleTestcase"

The management panel has a fixed title of "TheRoleTestcase". Very minor but kind of annoying. Maybe have it pick up it's title from the calling application's title? Also with Rails now allowing controller specific style sheets maybe have the install of TheRole make a blank stylesheet called the_role.scss in the stylesheets directory so that specific styles can be applied to the management panel? The management panel could use some ID's on the divs to allow further personalization.

I would be willing to work on these if you are open to the changes.

Rails 4?

Hi,

Does this gem work with rails 4? I seem to have it installed fine. But I can't seem to create the admin role and assign it. Has anyone done it before?

User has_many :somethings, through: :anythings. Doesn't allow acces for owned somethings.

Hello.

I've issue with the next configuration (rails 4 rc2, devise 3 rc, the_role 2.0.3, postgresql):

class User < ActiveRecord::Base
  devise :database_authenticatable # and etc
  has_one :anything
  has_many :somethings, through: :anything
  include TheRoleUserModel
end

class Anything < ActiveRecord::Base
  belongs_to :user
  has_many :somethings
end

class Something < ActiveRecord::Base
  belongs_to :anything
  delegate :user_id, :user, to: :anything
end

class SomethingsController < ApplicationController
  before_action :login_required
  before_action :set_something, only: [:show, :edit, :update, :destroy]
  before_action :owner_required, only: [:edit, :update, :destroy]

  # Scaffold actions omitted

  private
    def set_something
      @something = Something.find(params[:id])
      @owner_check_object = @something
    end
end

Result: returned access denied: requires a role for any something.

It seems like the delegates method create methods user_id and user for Something object, but doesn't initializes :user_id and :user entries in attributes hash.

irb(main):001:0> a = Something.find(2)
  Something Load (43.5ms)  SELECT ...
=> #<Something id: 2, ...>
irb(main):003:0> a.user_id
  Anything Load (20.8ms)  SELECT ...
  User Load (4.9ms)  SELECT ...
=> 2
irb(main):004:0> a[:user_id]
=> nil

Thus, TheRoleUserModel#owner? method can't correctly check for ownership, as in app/models/concerns/the_role_user_model.rb on line 32 used check through attributes hash.

Can it be changed to method calls instead?

Rails 3.2.14 + devise 2.1

"Rails 3 version (not recommended for use)" - is not an obvious message.

What is the reason? Is 1.7.0 version not supported anymore? Is it incompatible with newest Rails 3.2.14 ?

I have big troubles when trying to use this version with Rails 3.2.14 and devise 2.1

  1. Tried 1.7.0 and got strange "unintialized constant Admin::BaseHelper" error.
    Though this helper is an ordinary helper and lays in app/helpers/admin folder.
  2. Tried 2.0.* version with Rails 3.2.14
    When followed instructions from readme I got errors "uninitialized constant User::TheRoleUserModel" or "undefined method `password_salt' for #User:0xa7ebe2c" or "unintialized constant Role::RoleModel".

rails generate the_role admin fails

When running rails g the_role admin, I'm getting the following error (Rails 4, Sqlite database backend)

D, [2014-01-16T17:28:36.368676 #8835] DEBUG -- :   Role Load (0.2ms)  SELECT "roles".* FROM "roles" WHERE "roles"."name" = 'admin' ORDER BY "roles"."id" ASC LIMIT 1
W, [2014-01-16T17:28:36.371479 #8835]  WARN -- : WARNING: Can't mass-assign protected attributes for Role: name, title, description

D, [2014-01-16T17:28:36.371830 #8835] DEBUG -- :    (0.1ms)  begin transaction
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales 
D, [2014-01-16T17:28:36.398300 #8835] DEBUG -- :   Role Exists (0.2ms)  SELECT 1 AS one FROM "roles" WHERE "roles"."name" IS NULL LIMIT 1
D, [2014-01-16T17:28:36.400086 #8835] DEBUG -- :   Role Exists (0.1ms)  SELECT 1 AS one FROM "roles" WHERE "roles"."title" IS NULL LIMIT 1
D, [2014-01-16T17:28:36.400997 #8835] DEBUG -- :    (0.1ms)  rollback transaction
.rvm/gems/ruby-2.1.0/gems/the_role-2.3/app/models/concerns/role.rb:46:in `create_section': undefined method `[]' for nil:NilClass (NoMethodError)
  from .rvm/gems/ruby-2.1.0/gems/the_role-2.3/app/models/concerns/role.rb:53:in `create_rule'
  from .rvm/gems/ruby-2.1.0/gems/the_role-2.3/lib/generators/the_role/the_role_generator.rb:51:in `create_admin_role'
  from .rvm/gems/ruby-2.1.0/gems/the_role-2.3/lib/generators/the_role/the_role_generator.rb:14:in `generate_controllers'
  from .rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
  from .rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
  from .rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `block in invoke_all'
  from .rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `each'
  from .rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `map'
  from .rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `invoke_all'
  from .rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/group.rb:233:in `dispatch'
  from .rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
  from .rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/generators.rb:156:in `invoke'
  from .rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands/generate.rb:11:in `<top (required)>'
  from .rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
  from .rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
  from .rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
  from .rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
  from .rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:48:in `<top (required)>'
  from script/rails:6:in `require'
  from script/rails:6:in `<main>'

Any ideas, or some incompatibilities that I was overlooking?

assets:precompile - .border-radius is undefined

Hi Teacher,

The gem is an interesting alternative to cancan. Testing it out on a new project. However doing an asset precompile gives the following error:

.border-radius is undefined
(in .../gems/the_role-1.6.5/app/assets/stylesheets/alerts.less)

No route matches [PATCH] "/admin/roles/1/change"

When try to edit a role, for exemple, edit the title of the role from the admin role page, when submit (clic the green button for update the edition of the title), this error occur.
This occur also on your DummyApp application test.

Unit Testing?

Hi,

First, congratulations for your work. Nice project! :)

But.. Where are the tests?

Without tests... its not reliable for large projects.. :/

The rule for admin role is empty

I've followed your instructions to get 'the_role' fully installed. Everything went smoothly until I did rails g the_role admin The rule is created in the database but the_role attribute is empty, no json string. Below is the log from console:

=> #<Role id: 1, name: "admin", title: "role for admin", description: "this user can do anything", the_role: {}, created_at: "2014-06-11 14:11:57", updated_at: "2014-06-11 14:11:57">
irb(main):031:0> r.the_role => {}

I'm assuming the_role should show with the below json string? I've tried creating the rule again and nothing changes. Is there anything I can try to get this working?

{ :system => { :administrator => true } }

Rails 4.1.1
jRuby 1.7.9
Postgresql 9.3.4

set default user not working

Im not sure if its really a bug or I did something wrong, but when a new user register it should get the default role specified in the_role initializer, right? Well, instead I only get null on the role_id field for the User. I followed the readme instructions but didn't figure it out...
Im using devise with default configs. for now I need to set role manually for new registered users.

My initializer/the_role.rb:

# TheRole.config.param_name => value

TheRole.configure do |config|
  config.layout                     = :application

  config.default_user_role          = :user
  config.first_user_should_be_admin = false
  config.access_denied_method       = :access_denied
  config.login_required_method      = :authenticate_user!
  # config.destroy_strategy           = :restrict_with_exception # can be nil
end

an error when try to ask for admin role

in the doc i see it with rails c (and works):
After update the first user as admin (role_id becomes 1)
User.first.admin?
=> true
After update the user number 34 as admin role
User.find(34).admin?
=> false
but... the user with id 34 is an admin and in the database the role_id is 1 (so i see the update pointed on User.find(34) worked).
is it normal (i think not) and/or what i forget ?
i use database postgresql-9.4.4 (but normal id system, no uuid used). I see .find (ids) method from activeRecord works fine, so... maybe not from gem pg nor ActiveRecord.
Do you have an idea in case of this is not normal ?

"include TheRoleUserModel" needs to be added manually?

Not sure if this is a bug. I have to add this: "include TheRoleUserModel" to my model user.rb. If this is required, you should add it to the ReadMe directions? I needed to do this manually on two different projects, one was Rails 4.0 + Ruby 2.0, the other is Rails 4.0 and Ruby 1.9.3.

Rails 5 compatibility?

Anyone working on a Rails 5 compatibility? As far as I can see there are only some deprecation warnings but not sure if that's all? Many thanks!

Access to certain items?

Guess this doesn't support access to certain items, for example if user have posts in the blog then restrict him to access only those posts which he owns? This is achievable in cancan pretty simple.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.