@@ -637,12 +637,14 class ApplicationController < ActionController::Base | |||
|
637 | 637 | end |
|
638 | 638 | |
|
639 | 639 | # Renders API response on validation failure |
|
640 | # for an object or an array of objects | |
|
640 | 641 | def render_validation_errors(objects) |
|
641 | if objects.is_a?(Array) | |
|
642 | @error_messages = objects.map {|object| object.errors.full_messages}.flatten | |
|
643 | else | |
|
644 | @error_messages = objects.errors.full_messages | |
|
642 | messages = Array.wrap(objects).map {|object| object.errors.full_messages}.flatten | |
|
643 | render_api_errors(messages) | |
|
645 | 644 |
|
|
645 | ||
|
646 | def render_api_errors(*messages) | |
|
647 | @error_messages = messages.flatten | |
|
646 | 648 | render :template => 'common/error_messages.api', :status => :unprocessable_entity, :layout => nil |
|
647 | 649 | end |
|
648 | 650 |
@@ -95,12 +95,18 class GroupsController < ApplicationController | |||
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | def add_users |
|
98 |
@users = User.where(:id => (params[:user_id] || params[:user_ids])).a |
|
|
99 |
@group.users << @users |
|
|
98 | @users = User.not_in_group(@group).where(:id => (params[:user_id] || params[:user_ids])).to_a | |
|
99 | @group.users << @users | |
|
100 | 100 | respond_to do |format| |
|
101 | 101 | format.html { redirect_to edit_group_path(@group, :tab => 'users') } |
|
102 | 102 | format.js |
|
103 |
format.api { |
|
|
103 | format.api { | |
|
104 | if @users.any? | |
|
105 | render_api_ok | |
|
106 | else | |
|
107 | render_api_errors "#{l(:label_user)} #{l('activerecord.errors.messages.invalid')}" | |
|
108 | end | |
|
109 | } | |
|
104 | 110 | end |
|
105 | 111 | end |
|
106 | 112 |
@@ -189,6 +189,19 class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base | |||
|
189 | 189 | assert_include User.find(5), Group.find(10).users |
|
190 | 190 | end |
|
191 | 191 | |
|
192 | test "POST /groups/:id/users.xml should not add the user if already added" do | |
|
193 | Group.find(10).users << User.find(5) | |
|
194 | ||
|
195 | assert_no_difference 'Group.find(10).users.count' do | |
|
196 | post '/groups/10/users.xml', {:user_id => 5}, credentials('admin') | |
|
197 | assert_response :unprocessable_entity | |
|
198 | end | |
|
199 | ||
|
200 | assert_select 'errors' do | |
|
201 | assert_select 'error', :text => /User is invalid/ | |
|
202 | end | |
|
203 | end | |
|
204 | ||
|
192 | 205 | test "DELETE /groups/:id/users/:user_id.xml should remove user from the group" do |
|
193 | 206 | assert_difference 'Group.find(10).users.count', -1 do |
|
194 | 207 | delete '/groups/10/users/8.xml', {}, credentials('admin') |
General Comments 0
You need to be logged in to leave comments.
Login now