Commit 8bcf8c4fae2f01ed3ea2771aa2d5072be5f0e5b8
1 parent
148b47c5
Exists in
master
and in
29 other branches
Added permission to manage_custom_roles and started test for the controller
Signed-off-by: Hebert Douglas <hebertdougl@gmail.com> Signed-off-by: Filipe Ribeiro <firibeiro77@live.com> Signed-off-by: André Bernardes <andrebsguedes@gmail.com>
Showing
5 changed files
with
56 additions
and
6 deletions
Show diff stats
app/controllers/my_profile/profile_roles_controller.rb
app/models/profile.rb
... | ... | @@ -43,7 +43,7 @@ class Profile < ActiveRecord::Base |
43 | 43 | find_role('editor', env_id) |
44 | 44 | end |
45 | 45 | def self.organization_member_roles(env_id) |
46 | - all_roles(env_id, nil).select{ |r| r.key.match(/^profile_/) unless r.key.blank? } | |
46 | + all_roles(env_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? } | |
47 | 47 | end |
48 | 48 | def self.organization_custom_roles(env_id, profile_id) |
49 | 49 | all_roles(env_id, profile_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? } |
... | ... | @@ -51,7 +51,7 @@ class Profile < ActiveRecord::Base |
51 | 51 | def self.organization_all_roles(env_id, profile_id) |
52 | 52 | self.organization_member_roles(env_id) + self.organization_custom_roles(env_id, profile_id) |
53 | 53 | end |
54 | - def self.all_roles(env_id, profile_id) | |
54 | + def self.all_roles(env_id, profile_id=nil) | |
55 | 55 | Role.all :conditions => { :profile_id => profile_id, :environment_id => env_id } |
56 | 56 | end |
57 | 57 | def self.method_missing(m, *args, &block) |
... | ... | @@ -81,6 +81,7 @@ class Profile < ActiveRecord::Base |
81 | 81 | 'publish_content' => N_('Publish content'), |
82 | 82 | 'invite_members' => N_('Invite members'), |
83 | 83 | 'send_mail_to_members' => N_('Send e-Mail to members'), |
84 | + 'manage_custom_roles' => N_('Manage custom roles'), | |
84 | 85 | } |
85 | 86 | |
86 | 87 | acts_as_accessible | ... | ... |
app/views/tasks/_add_member_accept_details.html.erb
1 | 1 | <%= content = _("Roles:")+"<br />" |
2 | -roles = Profile::Roles.organization_member_roles(task.target.environment.id) | |
2 | +roles = Profile::Roles.organization_all_roles(task.target.environment.id) | |
3 | 3 | roles.each do |role| |
4 | 4 | content += labelled_check_box(role.name, "tasks[#{task.id}][task][roles][]", role.id, false)+"<br />" |
5 | 5 | end |
6 | 6 | content_tag('p', content, :class => 'member-classify-suggestion') |
7 | 7 | %> |
8 | - | ... | ... |
db/migrate/20150210143723_add_custom_roles_permission_to_admin_roles.rb
0 → 100644
... | ... | @@ -0,0 +1,18 @@ |
1 | +class AddCustomRolesPermissionToAdminRoles < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + environment_admin = Role.find_by_key("environment_administrator") | |
4 | + profile_admin = Role.find_by_key("profile_admin") | |
5 | + environment_admin.permissions.append("manage_custom_roles") | |
6 | + profile_admin.permissions.append("manage_custom_roles") | |
7 | + environment_admin.save! | |
8 | + profile_admin.save! | |
9 | + end | |
10 | + def self.down | |
11 | + environment_admin = Role.find_by_key("environment_administrator") | |
12 | + profile_admin = Role.find_by_key("profile_admin") | |
13 | + environment_admin.permissions.delete("manage_custom_roles") | |
14 | + profile_admin.permissions.delete("manage_custom_roles") | |
15 | + environment_admin.save! | |
16 | + profile_admin.save! | |
17 | + end | |
18 | +end | ... | ... |
... | ... | @@ -0,0 +1,32 @@ |
1 | +class ProfileRolesController < ActionController::TestCase | |
2 | + | |
3 | + def setup | |
4 | + @controller = RoleController.new | |
5 | + @request = ActionController::TestRequest.new | |
6 | + @response = ActionController::TestResponse.new | |
7 | + @role = Role.find(:first) | |
8 | + login_as(:ze) | |
9 | + end | |
10 | + | |
11 | + should 'create a custom role' do | |
12 | + | |
13 | + | |
14 | + end | |
15 | + | |
16 | + should 'delete a custom role not used' do | |
17 | + | |
18 | + end | |
19 | + | |
20 | + should 'delete a custom role being used' do | |
21 | + | |
22 | + end | |
23 | + | |
24 | + should 'assign a custom role to single user' do | |
25 | + | |
26 | + end | |
27 | + | |
28 | + should 'replace a role with a custom role' do | |
29 | + | |
30 | + end | |
31 | + role = Role.create!(:name => 'environment_role', :key => 'environment_role', :environment => Environment.default) | |
32 | +end | ... | ... |