end
@roles = scope.to_a
@permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
- if request.post?
- @roles.each do |role|
- role.permissions = params[:permissions][role.id.to_s]
- role.save
- end
- flash[:notice] = l(:notice_successful_update)
- redirect_to roles_path
+ end
+
+ def update_permissions
+ @roles = Role.where(:id => params[:permissions].keys)
+ @roles.each do |role|
+ role.permissions = params[:permissions][role.id.to_s]
+ role.save
end
+ flash[:notice] = l(:notice_successful_update)
+ redirect_to roles_path
end
private
</div>
<%= form_tag(permissions_roles_path, :id => 'permissions_form') do %>
-<%= hidden_field_tag 'permissions[0]', '', :id => nil %>
-<%= hidden_field_tag 'ids[]', @roles.map(&:id) %>
+<% @roles.each do |role| %>
+ <%= hidden_field_tag "permissions[#{role.id}][]", '', :id => nil %>
+<% end %>
<div class="autoscroll">
<table class="list permissions">
<thead>
end
resources :roles do
collection do
- match 'permissions', :via => [:get, :post]
+ get 'permissions'
+ post 'permissions', :to => 'roles#update_permissions'
end
end
resources :enumerations, :except => :show
assert_not_nil Role.find_by_id(1)
end
- def test_get_permissions
+ def test_permissions
get :permissions
assert_response :success
assert_select 'input[name=?][type=checkbox][value=delete_issues]:not([checked])', 'permissions[3][]'
end
- def test_get_permissions_with_filter
+ def test_permissions_with_filter
get :permissions, :params => {
:ids => ['2', '3']
}
assert_select 'input[name=?][type=checkbox][value=delete_issues]:not([checked])', 'permissions[3][]'
end
- def test_post_permissions
- post :permissions, :params => {
+ def test_update_permissions
+ post :update_permissions, :params => {
:permissions => {
- '0' => '',
'1' => ['edit_issues'],
'3' => ['add_issues', 'delete_issues']
}
assert_equal [:edit_issues], Role.find(1).permissions
assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
- assert Role.find(2).permissions.empty?
end
- def test_clear_all_permissions
- post :permissions, :params => {:permissions => { '0' => '' }}
- assert_redirected_to '/roles'
- assert Role.find(1).permissions.empty?
+ def test_update_permissions_should_not_update_other_roles
+ assert_no_changes -> { Role.find(2).permissions } do
+ assert_changes -> { Role.find(1).permissions } do
+ post :update_permissions, :params => {
+ :permissions => {
+ '1' => ['edit_issues']
+ }
+ }
+ end
+ end
end
def test_move_highest