@@ -1,144 +1,146 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2009 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 | |
|
23 | 23 | helper :sort |
|
24 | 24 | include SortHelper |
|
25 | 25 | helper :custom_fields |
|
26 | 26 | include CustomFieldsHelper |
|
27 | 27 | |
|
28 | 28 | def index |
|
29 | 29 | sort_init 'login', 'asc' |
|
30 | 30 | sort_update %w(login firstname lastname mail admin created_on last_login_on) |
|
31 | 31 | |
|
32 | 32 | @status = params[:status] ? params[:status].to_i : 1 |
|
33 | 33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
|
34 | 34 | |
|
35 | 35 | unless params[:name].blank? |
|
36 | 36 | name = "%#{params[:name].strip.downcase}%" |
|
37 | 37 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | @user_count = User.count(:conditions => c.conditions) |
|
41 | 41 | @user_pages = Paginator.new self, @user_count, |
|
42 | 42 | per_page_option, |
|
43 | 43 | params['page'] |
|
44 | 44 | @users = User.find :all,:order => sort_clause, |
|
45 | 45 | :conditions => c.conditions, |
|
46 | 46 | :limit => @user_pages.items_per_page, |
|
47 | 47 | :offset => @user_pages.current.offset |
|
48 | 48 | |
|
49 | 49 | render :layout => !request.xhr? |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def show |
|
53 | 53 | @user = User.active.find(params[:id]) |
|
54 | 54 | @custom_values = @user.custom_values |
|
55 | 55 | |
|
56 | 56 | # show only public projects and private projects that the logged in user is also a member of |
|
57 | 57 | @memberships = @user.memberships.select do |membership| |
|
58 | 58 | membership.project.is_public? || (User.current.member_of?(membership.project)) |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) |
|
62 | 62 | @events_by_day = events.group_by(&:event_date) |
|
63 | 63 | |
|
64 | 64 | if @user != User.current && !User.current.admin? && @memberships.empty? && events.empty? |
|
65 | 65 | render_404 |
|
66 | 66 | return |
|
67 | 67 | end |
|
68 | 68 | render :layout => 'base' |
|
69 | 69 | |
|
70 | 70 | rescue ActiveRecord::RecordNotFound |
|
71 | 71 | render_404 |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | def add |
|
75 | 75 | if request.get? |
|
76 | 76 | @user = User.new(:language => Setting.default_language) |
|
77 | 77 | else |
|
78 | 78 | @user = User.new(params[:user]) |
|
79 | 79 | @user.admin = params[:user][:admin] || false |
|
80 | 80 | @user.login = params[:user][:login] |
|
81 | 81 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id |
|
82 | 82 | if @user.save |
|
83 | 83 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] |
|
84 | 84 | flash[:notice] = l(:notice_successful_create) |
|
85 |
redirect_to :controller => 'users', :action => ' |
|
|
85 | redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} : | |
|
86 | {:controller => 'users', :action => 'edit', :id => @user}) | |
|
87 | return | |
|
86 | 88 | end |
|
87 | 89 | end |
|
88 | 90 | @auth_sources = AuthSource.find(:all) |
|
89 | 91 | end |
|
90 | 92 | |
|
91 | 93 | def edit |
|
92 | 94 | @user = User.find(params[:id]) |
|
93 | 95 | if request.post? |
|
94 | 96 | @user.admin = params[:user][:admin] if params[:user][:admin] |
|
95 | 97 | @user.login = params[:user][:login] if params[:user][:login] |
|
96 | 98 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id |
|
97 | 99 | @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] |
|
98 | 100 | @user.attributes = params[:user] |
|
99 | 101 | # Was the account actived ? (do it before User#save clears the change) |
|
100 | 102 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) |
|
101 | 103 | if @user.save |
|
102 | 104 | if was_activated |
|
103 | 105 | Mailer.deliver_account_activated(@user) |
|
104 | 106 | elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? |
|
105 | 107 | Mailer.deliver_account_information(@user, params[:password]) |
|
106 | 108 | end |
|
107 | 109 | flash[:notice] = l(:notice_successful_update) |
|
108 | 110 | redirect_to :back |
|
109 | 111 | end |
|
110 | 112 | end |
|
111 | 113 | @auth_sources = AuthSource.find(:all) |
|
112 | 114 | @membership ||= Member.new |
|
113 | 115 | rescue ::ActionController::RedirectBackError |
|
114 | 116 | redirect_to :controller => 'users', :action => 'edit', :id => @user |
|
115 | 117 | end |
|
116 | 118 | |
|
117 | 119 | def edit_membership |
|
118 | 120 | @user = User.find(params[:id]) |
|
119 | 121 | @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:principal => @user) |
|
120 | 122 | @membership.attributes = params[:membership] |
|
121 | 123 | @membership.save if request.post? |
|
122 | 124 | respond_to do |format| |
|
123 | 125 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } |
|
124 | 126 | format.js { |
|
125 | 127 | render(:update) {|page| |
|
126 | 128 | page.replace_html "tab-content-memberships", :partial => 'users/memberships' |
|
127 | 129 | page.visual_effect(:highlight, "member-#{@membership.id}") |
|
128 | 130 | } |
|
129 | 131 | } |
|
130 | 132 | end |
|
131 | 133 | end |
|
132 | 134 | |
|
133 | 135 | def destroy_membership |
|
134 | 136 | @user = User.find(params[:id]) |
|
135 | 137 | @membership = Member.find(params[:membership_id]) |
|
136 | 138 | if request.post? && @membership.deletable? |
|
137 | 139 | @membership.destroy |
|
138 | 140 | end |
|
139 | 141 | respond_to do |format| |
|
140 | 142 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } |
|
141 | 143 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } |
|
142 | 144 | end |
|
143 | 145 | end |
|
144 | 146 | end |
@@ -1,7 +1,10 | |||
|
1 | 1 | <h2><%= link_to l(:label_user_plural), :controller => 'users', :action => 'index' %> » <%=l(:label_user_new)%></h2> |
|
2 | 2 | |
|
3 | 3 | <% labelled_tabular_form_for :user, @user, :url => { :action => "add" }, :html => { :class => nil } do |f| %> |
|
4 | 4 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
5 | 5 | <p><label><%= check_box_tag 'send_information', 1, true %> <%= l(:label_send_information) %></label></p> |
|
6 | <p><%= submit_tag l(:button_create) %></p> | |
|
6 | <p> | |
|
7 | <%= submit_tag l(:button_create) %> | |
|
8 | <%= submit_tag l(:button_create_and_continue), :name => 'continue' %> | |
|
9 | </p> | |
|
7 | 10 | <% end %> |
General Comments 0
You need to be logged in to leave comments.
Login now