@@ -5,19 +5,19 | |||||
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. | |
8 |
# |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 |
# |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class UsersController < ApplicationController |
|
18 | class UsersController < ApplicationController | |
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin, :except => :show |
|
21 | before_filter :require_admin, :except => :show | |
22 | before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership] |
|
22 | before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership] | |
23 | accept_api_auth :index, :show, :create, :update, :destroy |
|
23 | accept_api_auth :index, :show, :create, :update, :destroy | |
@@ -25,22 +25,22 class UsersController < ApplicationController | |||||
25 | helper :sort |
|
25 | helper :sort | |
26 | include SortHelper |
|
26 | include SortHelper | |
27 | helper :custom_fields |
|
27 | helper :custom_fields | |
28 |
include CustomFieldsHelper |
|
28 | include CustomFieldsHelper | |
29 |
|
29 | |||
30 | def index |
|
30 | def index | |
31 | sort_init 'login', 'asc' |
|
31 | sort_init 'login', 'asc' | |
32 | sort_update %w(login firstname lastname mail admin created_on last_login_on) |
|
32 | sort_update %w(login firstname lastname mail admin created_on last_login_on) | |
33 |
|
33 | |||
34 | case params[:format] |
|
34 | case params[:format] | |
35 | when 'xml', 'json' |
|
35 | when 'xml', 'json' | |
36 | @offset, @limit = api_offset_and_limit |
|
36 | @offset, @limit = api_offset_and_limit | |
37 | else |
|
37 | else | |
38 | @limit = per_page_option |
|
38 | @limit = per_page_option | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | scope = User |
|
41 | scope = User | |
42 | scope = scope.in_group(params[:group_id].to_i) if params[:group_id].present? |
|
42 | scope = scope.in_group(params[:group_id].to_i) if params[:group_id].present? | |
43 |
|
43 | |||
44 | @status = params[:status] ? params[:status].to_i : 1 |
|
44 | @status = params[:status] ? params[:status].to_i : 1 | |
45 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
|
45 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
46 |
|
46 | |||
@@ -48,7 +48,7 class UsersController < ApplicationController | |||||
48 | name = "%#{params[:name].strip.downcase}%" |
|
48 | name = "%#{params[:name].strip.downcase}%" | |
49 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] |
|
49 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | @user_count = scope.count(:conditions => c.conditions) |
|
52 | @user_count = scope.count(:conditions => c.conditions) | |
53 | @user_pages = Paginator.new self, @user_count, @limit, params['page'] |
|
53 | @user_pages = Paginator.new self, @user_count, @limit, params['page'] | |
54 | @offset ||= @user_pages.current.offset |
|
54 | @offset ||= @user_pages.current.offset | |
@@ -66,21 +66,21 class UsersController < ApplicationController | |||||
66 | format.api |
|
66 | format.api | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | def show |
|
70 | def show | |
71 | # show projects based on current user visibility |
|
71 | # show projects based on current user visibility | |
72 | @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) |
|
72 | @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) | |
73 |
|
73 | |||
74 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) |
|
74 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) | |
75 | @events_by_day = events.group_by(&:event_date) |
|
75 | @events_by_day = events.group_by(&:event_date) | |
76 |
|
76 | |||
77 | unless User.current.admin? |
|
77 | unless User.current.admin? | |
78 | if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?) |
|
78 | if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?) | |
79 | render_404 |
|
79 | render_404 | |
80 | return |
|
80 | return | |
81 | end |
|
81 | end | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | respond_to do |format| |
|
84 | respond_to do |format| | |
85 | format.html { render :layout => 'base' } |
|
85 | format.html { render :layout => 'base' } | |
86 | format.api |
|
86 | format.api | |
@@ -91,7 +91,7 class UsersController < ApplicationController | |||||
91 | @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) |
|
91 | @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) | |
92 | @auth_sources = AuthSource.find(:all) |
|
92 | @auth_sources = AuthSource.find(:all) | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
|
95 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |
96 | def create |
|
96 | def create | |
97 | @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) |
|
97 | @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) | |
@@ -109,12 +109,12 class UsersController < ApplicationController | |||||
109 | @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) |
|
109 | @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) | |
110 |
|
110 | |||
111 | Mailer.deliver_account_information(@user, params[:user][:password]) if params[:send_information] |
|
111 | Mailer.deliver_account_information(@user, params[:user][:password]) if params[:send_information] | |
112 |
|
112 | |||
113 | respond_to do |format| |
|
113 | respond_to do |format| | |
114 | format.html { |
|
114 | format.html { | |
115 | flash[:notice] = l(:notice_successful_create) |
|
115 | flash[:notice] = l(:notice_successful_create) | |
116 |
redirect_to(params[:continue] ? |
|
116 | redirect_to(params[:continue] ? | |
117 |
{:controller => 'users', :action => 'new'} : |
|
117 | {:controller => 'users', :action => 'new'} : | |
118 | {:controller => 'users', :action => 'edit', :id => @user} |
|
118 | {:controller => 'users', :action => 'edit', :id => @user} | |
119 | ) |
|
119 | ) | |
120 | } |
|
120 | } | |
@@ -136,7 +136,7 class UsersController < ApplicationController | |||||
136 | @auth_sources = AuthSource.find(:all) |
|
136 | @auth_sources = AuthSource.find(:all) | |
137 | @membership ||= Member.new |
|
137 | @membership ||= Member.new | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
|
140 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
141 | def update |
|
141 | def update | |
142 | @user.admin = params[:user][:admin] if params[:user][:admin] |
|
142 | @user.admin = params[:user][:admin] if params[:user][:admin] | |
@@ -160,7 +160,7 class UsersController < ApplicationController | |||||
160 | elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil? |
|
160 | elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil? | |
161 | Mailer.deliver_account_information(@user, params[:user][:password]) |
|
161 | Mailer.deliver_account_information(@user, params[:user][:password]) | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | respond_to do |format| |
|
164 | respond_to do |format| | |
165 | format.html { |
|
165 | format.html { | |
166 | flash[:notice] = l(:notice_successful_update) |
|
166 | flash[:notice] = l(:notice_successful_update) | |
@@ -213,7 +213,7 class UsersController < ApplicationController | |||||
213 | end |
|
213 | end | |
214 | end |
|
214 | end | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | def destroy_membership |
|
217 | def destroy_membership | |
218 | @membership = Member.find(params[:membership_id]) |
|
218 | @membership = Member.find(params[:membership_id]) | |
219 | if request.post? && @membership.deletable? |
|
219 | if request.post? && @membership.deletable? | |
@@ -224,9 +224,9 class UsersController < ApplicationController | |||||
224 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } |
|
224 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } | |
225 | end |
|
225 | end | |
226 | end |
|
226 | end | |
227 |
|
227 | |||
228 | private |
|
228 | private | |
229 |
|
229 | |||
230 | def find_user |
|
230 | def find_user | |
231 | if params[:id] == 'current' |
|
231 | if params[:id] == 'current' | |
232 | require_login || return |
|
232 | require_login || return |
General Comments 0
You need to be logged in to leave comments.
Login now