comparison app/controllers/groups_controller.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
17 17
18 class GroupsController < ApplicationController 18 class GroupsController < ApplicationController
19 layout 'admin' 19 layout 'admin'
20 20
21 before_filter :require_admin 21 before_filter :require_admin
22 before_filter :find_group, :except => [:index, :new, :create]
23 accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
22 24
23 helper :custom_fields 25 helper :custom_fields
24 26
25 # GET /groups
26 # GET /groups.xml
27 def index 27 def index
28 @groups = Group.find(:all, :order => 'lastname') 28 @groups = Group.sorted.all
29 29
30 respond_to do |format| 30 respond_to do |format|
31 format.html # index.html.erb 31 format.html
32 format.xml { render :xml => @groups } 32 format.api
33 end 33 end
34 end 34 end
35 35
36 # GET /groups/1
37 # GET /groups/1.xml
38 def show 36 def show
39 @group = Group.find(params[:id])
40
41 respond_to do |format| 37 respond_to do |format|
42 format.html # show.html.erb 38 format.html
43 format.xml { render :xml => @group } 39 format.api
44 end 40 end
45 end 41 end
46 42
47 # GET /groups/new
48 # GET /groups/new.xml
49 def new 43 def new
50 @group = Group.new 44 @group = Group.new
51
52 respond_to do |format|
53 format.html # new.html.erb
54 format.xml { render :xml => @group }
55 end
56 end 45 end
57 46
58 # GET /groups/1/edit
59 def edit
60 @group = Group.find(params[:id], :include => :projects)
61 end
62
63 # POST /groups
64 # POST /groups.xml
65 def create 47 def create
66 @group = Group.new(params[:group]) 48 @group = Group.new
49 @group.safe_attributes = params[:group]
67 50
68 respond_to do |format| 51 respond_to do |format|
69 if @group.save 52 if @group.save
70 format.html { 53 format.html {
71 flash[:notice] = l(:notice_successful_create) 54 flash[:notice] = l(:notice_successful_create)
72 redirect_to(params[:continue] ? new_group_path : groups_path) 55 redirect_to(params[:continue] ? new_group_path : groups_path)
73 } 56 }
74 format.xml { render :xml => @group, :status => :created, :location => @group } 57 format.api { render :action => 'show', :status => :created, :location => group_url(@group) }
75 else 58 else
76 format.html { render :action => "new" } 59 format.html { render :action => "new" }
77 format.xml { render :xml => @group.errors, :status => :unprocessable_entity } 60 format.api { render_validation_errors(@group) }
78 end 61 end
79 end 62 end
80 end 63 end
81 64
82 # PUT /groups/1 65 def edit
83 # PUT /groups/1.xml 66 end
67
84 def update 68 def update
85 @group = Group.find(params[:id]) 69 @group.safe_attributes = params[:group]
86 70
87 respond_to do |format| 71 respond_to do |format|
88 if @group.update_attributes(params[:group]) 72 if @group.save
89 flash[:notice] = l(:notice_successful_update) 73 flash[:notice] = l(:notice_successful_update)
90 format.html { redirect_to(groups_path) } 74 format.html { redirect_to(groups_path) }
91 format.xml { head :ok } 75 format.api { render_api_ok }
92 else 76 else
93 format.html { render :action => "edit" } 77 format.html { render :action => "edit" }
94 format.xml { render :xml => @group.errors, :status => :unprocessable_entity } 78 format.api { render_validation_errors(@group) }
95 end 79 end
96 end 80 end
97 end 81 end
98 82
99 # DELETE /groups/1
100 # DELETE /groups/1.xml
101 def destroy 83 def destroy
102 @group = Group.find(params[:id])
103 @group.destroy 84 @group.destroy
104 85
105 respond_to do |format| 86 respond_to do |format|
106 format.html { redirect_to(groups_url) } 87 format.html { redirect_to(groups_url) }
107 format.xml { head :ok } 88 format.api { render_api_ok }
108 end 89 end
109 end 90 end
110 91
111 def add_users 92 def add_users
112 @group = Group.find(params[:id]) 93 @users = User.find_all_by_id(params[:user_id] || params[:user_ids])
113 users = User.find_all_by_id(params[:user_ids]) 94 @group.users << @users if request.post?
114 @group.users << users if request.post?
115 respond_to do |format| 95 respond_to do |format|
116 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } 96 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
117 format.js { 97 format.js
118 render(:update) {|page| 98 format.api { render_api_ok }
119 page.replace_html "tab-content-users", :partial => 'groups/users'
120 users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
121 }
122 }
123 end 99 end
124 end 100 end
125 101
126 def remove_user 102 def remove_user
127 @group = Group.find(params[:id])
128 @group.users.delete(User.find(params[:user_id])) if request.delete? 103 @group.users.delete(User.find(params[:user_id])) if request.delete?
129 respond_to do |format| 104 respond_to do |format|
130 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } 105 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
131 format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} } 106 format.js
107 format.api { render_api_ok }
132 end 108 end
133 end 109 end
134 110
135 def autocomplete_for_user 111 def autocomplete_for_user
136 @group = Group.find(params[:id])
137 @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100) 112 @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
138 render :layout => false 113 render :layout => false
139 end 114 end
140 115
141 def edit_membership 116 def edit_membership
142 @group = Group.find(params[:id])
143 @membership = Member.edit_membership(params[:membership_id], params[:membership], @group) 117 @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
144 @membership.save if request.post? 118 @membership.save if request.post?
145 respond_to do |format| 119 respond_to do |format|
146 if @membership.valid? 120 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
147 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } 121 format.js
148 format.js {
149 render(:update) {|page|
150 page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
151 page.visual_effect(:highlight, "member-#{@membership.id}")
152 }
153 }
154 else
155 format.js {
156 render(:update) {|page|
157 page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
158 }
159 }
160 end
161 end 122 end
162 end 123 end
163 124
164 def destroy_membership 125 def destroy_membership
165 @group = Group.find(params[:id])
166 Member.find(params[:membership_id]).destroy if request.post? 126 Member.find(params[:membership_id]).destroy if request.post?
167 respond_to do |format| 127 respond_to do |format|
168 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } 128 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
169 format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} } 129 format.js
170 end 130 end
171 end 131 end
132
133 private
134
135 def find_group
136 @group = Group.find(params[:id])
137 rescue ActiveRecord::RecordNotFound
138 render_404
139 end
172 end 140 end