##// END OF EJS Templates
Merged r14140 (#19161)....
Jean-Philippe Lang -
r13767:5eb1b2626de8
parent child
Show More
@@ -1,188 +1,188
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class UsersController < ApplicationController
19 19 layout 'admin'
20 20
21 21 before_filter :require_admin, :except => :show
22 22 before_filter :find_user, :only => [:show, :edit, :update, :destroy]
23 23 accept_api_auth :index, :show, :create, :update, :destroy
24 24
25 25 helper :sort
26 26 include SortHelper
27 27 helper :custom_fields
28 28 include CustomFieldsHelper
29 29 helper :principal_memberships
30 30
31 31 def index
32 32 sort_init 'login', 'asc'
33 sort_update %w(login firstname lastname mail admin created_on last_login_on)
33 sort_update %w(login firstname lastname admin created_on last_login_on)
34 34
35 35 case params[:format]
36 36 when 'xml', 'json'
37 37 @offset, @limit = api_offset_and_limit
38 38 else
39 39 @limit = per_page_option
40 40 end
41 41
42 42 @status = params[:status] || 1
43 43
44 44 scope = User.logged.status(@status).preload(:email_address)
45 45 scope = scope.like(params[:name]) if params[:name].present?
46 46 scope = scope.in_group(params[:group_id]) if params[:group_id].present?
47 47
48 48 @user_count = scope.count
49 49 @user_pages = Paginator.new @user_count, @limit, params['page']
50 50 @offset ||= @user_pages.offset
51 51 @users = scope.order(sort_clause).limit(@limit).offset(@offset).to_a
52 52
53 53 respond_to do |format|
54 54 format.html {
55 55 @groups = Group.all.sort
56 56 render :layout => !request.xhr?
57 57 }
58 58 format.api
59 59 end
60 60 end
61 61
62 62 def show
63 63 unless @user.visible?
64 64 render_404
65 65 return
66 66 end
67 67
68 68 # show projects based on current user visibility
69 69 @memberships = @user.memberships.where(Project.visible_condition(User.current)).to_a
70 70
71 71 respond_to do |format|
72 72 format.html {
73 73 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
74 74 @events_by_day = events.group_by(&:event_date)
75 75 render :layout => 'base'
76 76 }
77 77 format.api
78 78 end
79 79 end
80 80
81 81 def new
82 82 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
83 83 @user.safe_attributes = params[:user]
84 84 @auth_sources = AuthSource.all
85 85 end
86 86
87 87 def create
88 88 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
89 89 @user.safe_attributes = params[:user]
90 90 @user.admin = params[:user][:admin] || false
91 91 @user.login = params[:user][:login]
92 92 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
93 93 @user.pref.attributes = params[:pref] if params[:pref]
94 94
95 95 if @user.save
96 96 Mailer.account_information(@user, @user.password).deliver if params[:send_information]
97 97
98 98 respond_to do |format|
99 99 format.html {
100 100 flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
101 101 if params[:continue]
102 102 attrs = params[:user].slice(:generate_password)
103 103 redirect_to new_user_path(:user => attrs)
104 104 else
105 105 redirect_to edit_user_path(@user)
106 106 end
107 107 }
108 108 format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
109 109 end
110 110 else
111 111 @auth_sources = AuthSource.all
112 112 # Clear password input
113 113 @user.password = @user.password_confirmation = nil
114 114
115 115 respond_to do |format|
116 116 format.html { render :action => 'new' }
117 117 format.api { render_validation_errors(@user) }
118 118 end
119 119 end
120 120 end
121 121
122 122 def edit
123 123 @auth_sources = AuthSource.all
124 124 @membership ||= Member.new
125 125 end
126 126
127 127 def update
128 128 @user.admin = params[:user][:admin] if params[:user][:admin]
129 129 @user.login = params[:user][:login] if params[:user][:login]
130 130 if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
131 131 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
132 132 end
133 133 @user.safe_attributes = params[:user]
134 134 # Was the account actived ? (do it before User#save clears the change)
135 135 was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
136 136 # TODO: Similar to My#account
137 137 @user.pref.attributes = params[:pref] if params[:pref]
138 138
139 139 if @user.save
140 140 @user.pref.save
141 141
142 142 if was_activated
143 143 Mailer.account_activated(@user).deliver
144 144 elsif @user.active? && params[:send_information] && @user.password.present? && @user.auth_source_id.nil?
145 145 Mailer.account_information(@user, @user.password).deliver
146 146 end
147 147
148 148 respond_to do |format|
149 149 format.html {
150 150 flash[:notice] = l(:notice_successful_update)
151 151 redirect_to_referer_or edit_user_path(@user)
152 152 }
153 153 format.api { render_api_ok }
154 154 end
155 155 else
156 156 @auth_sources = AuthSource.all
157 157 @membership ||= Member.new
158 158 # Clear password input
159 159 @user.password = @user.password_confirmation = nil
160 160
161 161 respond_to do |format|
162 162 format.html { render :action => :edit }
163 163 format.api { render_validation_errors(@user) }
164 164 end
165 165 end
166 166 end
167 167
168 168 def destroy
169 169 @user.destroy
170 170 respond_to do |format|
171 171 format.html { redirect_back_or_default(users_path) }
172 172 format.api { render_api_ok }
173 173 end
174 174 end
175 175
176 176 private
177 177
178 178 def find_user
179 179 if params[:id] == 'current'
180 180 require_login || return
181 181 @user = User.current
182 182 else
183 183 @user = User.find(params[:id])
184 184 end
185 185 rescue ActiveRecord::RecordNotFound
186 186 render_404
187 187 end
188 188 end
@@ -1,58 +1,58
1 1 <div class="contextual">
2 2 <%= link_to l(:label_user_new), new_user_path, :class => 'icon icon-add' %>
3 3 </div>
4 4
5 5 <h2><%=l(:label_user_plural)%></h2>
6 6
7 7 <%= form_tag(users_path, :method => :get) do %>
8 8 <fieldset><legend><%= l(:label_filter_plural) %></legend>
9 9 <label for='status'><%= l(:field_status) %>:</label>
10 10 <%= select_tag 'status', users_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
11 11
12 12 <% if @groups.present? %>
13 13 <label for='group_id'><%= l(:label_group) %>:</label>
14 14 <%= select_tag 'group_id', content_tag('option') + options_from_collection_for_select(@groups, :id, :name, params[:group_id].to_i), :onchange => "this.form.submit(); return false;" %>
15 15 <% end %>
16 16
17 17 <label for='name'><%= l(:label_user) %>:</label>
18 18 <%= text_field_tag 'name', params[:name], :size => 30 %>
19 19 <%= submit_tag l(:button_apply), :class => "small", :name => nil %>
20 20 <%= link_to l(:button_clear), users_path, :class => 'icon icon-reload' %>
21 21 </fieldset>
22 22 <% end %>
23 23 &nbsp;
24 24
25 25 <div class="autoscroll">
26 26 <table class="list">
27 27 <thead><tr>
28 28 <%= sort_header_tag('login', :caption => l(:field_login)) %>
29 29 <%= sort_header_tag('firstname', :caption => l(:field_firstname)) %>
30 30 <%= sort_header_tag('lastname', :caption => l(:field_lastname)) %>
31 <%= sort_header_tag('mail', :caption => l(:field_mail)) %>
31 <th><%= l(:field_mail) %></th>
32 32 <%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %>
33 33 <%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %>
34 34 <%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %>
35 35 <th></th>
36 36 </tr></thead>
37 37 <tbody>
38 38 <% for user in @users -%>
39 39 <tr class="<%= user.css_classes %> <%= cycle("odd", "even") %>">
40 40 <td class="username"><%= avatar(user, :size => "14") %><%= link_to h(user.login), edit_user_path(user) %></td>
41 41 <td class="firstname"><%= h(user.firstname) %></td>
42 42 <td class="lastname"><%= h(user.lastname) %></td>
43 43 <td class="email"><%= mail_to(h(user.mail)) %></td>
44 44 <td class="tick"><%= checked_image user.admin? %></td>
45 45 <td class="created_on"><%= format_time(user.created_on) %></td>
46 46 <td class="last_login_on"><%= format_time(user.last_login_on) unless user.last_login_on.nil? %></td>
47 47 <td class="buttons">
48 48 <%= change_status_link(user) %>
49 49 <%= delete_link user_path(user, :back_url => request.original_fullpath) unless User.current == user %>
50 50 </td>
51 51 </tr>
52 52 <% end -%>
53 53 </tbody>
54 54 </table>
55 55 </div>
56 56 <p class="pagination"><%= pagination_links_full @user_pages, @user_count %></p>
57 57
58 58 <% html_title(l(:label_user_plural)) -%>
General Comments 0
You need to be logged in to leave comments. Login now