Commit b0bac8a689e2ee0e81e5f537c1714602b5576b51
1 parent
b9800000
Exists in
master
and in
22 other branches
Fix role kind resolution
Showing
3 changed files
with
13 additions
and
6 deletions
Show diff stats
test/fixtures/roles.yml
test/unit/environment_test.rb
| ... | ... | @@ -363,6 +363,14 @@ class EnvironmentTest < ActiveSupport::TestCase |
| 363 | 363 | assert_kind_of Role, Environment::Roles.admin(Environment.default.id) |
| 364 | 364 | end |
| 365 | 365 | |
| 366 | + should 'create environment and profile default roles' do | |
| 367 | + env = Environment.default | |
| 368 | + assert_equal 'Environment', env.roles.find_by_key('environment_administrator').kind | |
| 369 | + assert_equal 'Profile', env.roles.find_by_key('profile_admin').kind | |
| 370 | + assert_equal 'Profile', env.roles.find_by_key('profile_member').kind | |
| 371 | + assert_equal 'Profile', env.roles.find_by_key('profile_moderator').kind | |
| 372 | + end | |
| 373 | + | |
| 366 | 374 | should 'be able to add admins easily' do |
| 367 | 375 | env = Environment.default |
| 368 | 376 | user = create_user('testuser').person | ... | ... |
vendor/plugins/access_control/lib/role.rb
| ... | ... | @@ -35,12 +35,7 @@ class Role < ActiveRecord::Base |
| 35 | 35 | end |
| 36 | 36 | |
| 37 | 37 | def kind |
| 38 | - env_perms = perms['Environment'].keys | |
| 39 | - if permissions.any?{ |perm| env_perms.include?(perm) } | |
| 40 | - 'Environment' | |
| 41 | - else | |
| 42 | - 'Profile' | |
| 43 | - end | |
| 38 | + key.present? && key.starts_with?('environment_') ? 'Environment' : 'Profile' | |
| 44 | 39 | end |
| 45 | 40 | |
| 46 | 41 | def name | ... | ... |