Commit 88c9310717d9cb288fe845449bbfa12c9b33d1ce
Exists in
master
and in
29 other branches
Merge branch 'fix_role_edition' of https://gitlab.com/participa/noosfero into role-edition
Showing
5 changed files
with
35 additions
and
6 deletions
Show diff stats
app/helpers/role_helper.rb
app/views/role/_form.html.erb
@@ -6,10 +6,14 @@ | @@ -6,10 +6,14 @@ | ||
6 | 6 | ||
7 | <%= required f.text_field(:name) %> | 7 | <%= required f.text_field(:name) %> |
8 | 8 | ||
9 | - <p><%= _('Permissions:') %><p> | ||
10 | - <% permissions.keys.each do |p| %> | ||
11 | - <%= check_box_tag("role[permissions][]", p, role.has_permission?(p), { :id => p }) %> | ||
12 | - <%= content_tag(:label, permission_name(p), { :for => p }) %><br/> | 9 | + <% permissions.each do |key| %> |
10 | + <div class="permissions <%= key.downcase %>"> | ||
11 | + <h4><%= _('%s Permissions:' % key) %></h4> | ||
12 | + <% ActiveRecord::Base::PERMISSIONS[key].keys.each do |p| %> | ||
13 | + <%= check_box_tag("role[permissions][]", p, role.has_permission?(p), { :id => p }) %> | ||
14 | + <%= content_tag(:label, permission_name(p), { :for => p }) %><br/> | ||
15 | + <% end %> | ||
16 | + </div> | ||
13 | <% end %> | 17 | <% end %> |
14 | 18 | ||
15 | <% button_bar do %> | 19 | <% button_bar do %> |
app/views/role/edit.html.erb
1 | <h2> <%= _("Editing #{@role.name}") %> </h2> | 1 | <h2> <%= _("Editing #{@role.name}") %> </h2> |
2 | 2 | ||
3 | -<%= render :partial => 'form', :locals => { :mode => :edit, :role => @role, :permissions => ActiveRecord::Base::PERMISSIONS[@role.kind] } %> | 3 | +<%= render :partial => 'form', :locals => { :mode => :edit, :role => @role, :permissions => role_available_permissions(@role) } %> |
app/views/role/new.html.erb
1 | <h2> <%= _("Create a new role") %> </h2> | 1 | <h2> <%= _("Create a new role") %> </h2> |
2 | 2 | ||
3 | -<%= render :partial => 'form', :locals => { :mode => :create, :role => @role, :permissions => ActiveRecord::Base::PERMISSIONS[@role.kind] } %> | 3 | +<%= render :partial => 'form', :locals => { :mode => :create, :role => @role, :permissions => role_available_permissions(@role) } %> |
test/functional/role_controller_test.rb
@@ -78,4 +78,24 @@ class RoleControllerTest < ActionController::TestCase | @@ -78,4 +78,24 @@ class RoleControllerTest < ActionController::TestCase | ||
78 | get :edit, :id => role.id | 78 | get :edit, :id => role.id |
79 | end | 79 | end |
80 | end | 80 | end |
81 | + | ||
82 | + should 'display permissions for both environment and profile when editing a environment role' do | ||
83 | + role = Role.create!(:name => 'environment_role', :key => 'environment_role', :environment => Environment.default) | ||
84 | + get :edit, :id => role.id | ||
85 | + ['Environment', 'Profile'].each do |key| | ||
86 | + ActiveRecord::Base::PERMISSIONS[key].each do |permission, value| | ||
87 | + assert_select ".permissions.#{key.downcase} input##{permission}" | ||
88 | + end | ||
89 | + end | ||
90 | + end | ||
91 | + | ||
92 | + should 'display permissions only for profile when editing a profile role' do | ||
93 | + role = Role.create!(:name => 'profile_role', :key => 'profile_role', :environment => Environment.default) | ||
94 | + get :edit, :id => role.id | ||
95 | + ActiveRecord::Base::PERMISSIONS['Profile'].each do |permission, value| | ||
96 | + assert_select "input##{permission}" | ||
97 | + end | ||
98 | + assert_select ".permissions.environment", false | ||
99 | + end | ||
100 | + | ||
81 | end | 101 | end |