Commit 76ed18942b5f0c43af17a678ea7d18de1a599f6e
Committed by
Antonio Terceiro
1 parent
ae454ce9
Exists in
staging
and in
42 other branches
ActionItem1204: made role kind always be defined
Showing
2 changed files
with
14 additions
and
1 deletions
Show diff stats
test/functional/role_controller_test.rb
| ... | ... | @@ -82,4 +82,12 @@ class RoleControllerTest < Test::Unit::TestCase |
| 82 | 82 | assert_not_nil assigns(:role) |
| 83 | 83 | end |
| 84 | 84 | end |
| 85 | + | |
| 86 | + should 'not crash when editing role with no permissions' do | |
| 87 | + role = Role.create!(:name => 'test_role', :environment => Environment.default) | |
| 88 | + | |
| 89 | + assert_nothing_raised do | |
| 90 | + get :edit, :id => role.id | |
| 91 | + end | |
| 92 | + end | |
| 85 | 93 | end | ... | ... |
vendor/plugins/access_control/lib/role.rb
| ... | ... | @@ -32,7 +32,12 @@ class Role < ActiveRecord::Base |
| 32 | 32 | end |
| 33 | 33 | |
| 34 | 34 | def kind |
| 35 | - perms.keys.detect{|k| perms[k].keys.include?(permissions[0]) } | |
| 35 | + env_perms = perms['Environment'].keys | |
| 36 | + if permissions.any?{ |perm| env_perms.include?(perm) } | |
| 37 | + 'Environment' | |
| 38 | + else | |
| 39 | + 'Profile' | |
| 40 | + end | |
| 36 | 41 | end |
| 37 | 42 | |
| 38 | 43 | def name | ... | ... |