2009-10-29 21:37:00 +03:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
2007-03-12 20:59:02 +03:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
class UsersController < ApplicationController
|
2009-12-17 21:21:02 +03:00
|
|
|
layout 'admin'
|
|
|
|
|
2009-10-29 21:37:00 +03:00
|
|
|
before_filter :require_admin, :except => :show
|
2007-03-12 20:59:02 +03:00
|
|
|
|
|
|
|
helper :sort
|
|
|
|
include SortHelper
|
|
|
|
helper :custom_fields
|
|
|
|
include CustomFieldsHelper
|
2006-07-09 20:30:01 +04:00
|
|
|
|
|
|
|
def index
|
2007-03-12 20:59:02 +03:00
|
|
|
sort_init 'login', 'asc'
|
2008-12-24 13:03:13 +03:00
|
|
|
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
2007-03-18 23:44:33 +03:00
|
|
|
|
2008-02-03 22:53:52 +03:00
|
|
|
@status = params[:status] ? params[:status].to_i : 1
|
2008-10-24 20:59:15 +04:00
|
|
|
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
|
|
|
|
|
|
|
unless params[:name].blank?
|
|
|
|
name = "%#{params[:name].strip.downcase}%"
|
2009-10-24 16:21:09 +04:00
|
|
|
c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name]
|
2008-10-24 20:59:15 +04:00
|
|
|
end
|
2007-03-18 23:44:33 +03:00
|
|
|
|
2008-10-24 20:59:15 +04:00
|
|
|
@user_count = User.count(:conditions => c.conditions)
|
2007-03-12 20:59:02 +03:00
|
|
|
@user_pages = Paginator.new self, @user_count,
|
2007-12-29 14:36:30 +03:00
|
|
|
per_page_option,
|
2007-03-12 20:59:02 +03:00
|
|
|
params['page']
|
|
|
|
@users = User.find :all,:order => sort_clause,
|
2008-10-24 20:59:15 +04:00
|
|
|
:conditions => c.conditions,
|
2007-03-12 20:59:02 +03:00
|
|
|
:limit => @user_pages.items_per_page,
|
|
|
|
:offset => @user_pages.current.offset
|
|
|
|
|
2009-10-29 21:48:19 +03:00
|
|
|
render :layout => !request.xhr?
|
2006-07-09 20:30:01 +04:00
|
|
|
end
|
2009-10-29 21:37:00 +03:00
|
|
|
|
|
|
|
def show
|
2010-02-26 18:50:16 +03:00
|
|
|
@user = User.find(params[:id])
|
2009-10-29 21:37:00 +03:00
|
|
|
@custom_values = @user.custom_values
|
|
|
|
|
2010-08-19 08:33:11 +04:00
|
|
|
# show projects based on current user visibility
|
|
|
|
@memberships = @user.memberships.all(:conditions => Project.visible_by(User.current))
|
2009-10-29 21:37:00 +03:00
|
|
|
|
|
|
|
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
|
|
|
|
@events_by_day = events.group_by(&:event_date)
|
|
|
|
|
2010-02-26 18:50:16 +03:00
|
|
|
unless User.current.admin?
|
|
|
|
if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
|
|
|
|
render_404
|
|
|
|
return
|
|
|
|
end
|
2009-10-29 21:37:00 +03:00
|
|
|
end
|
2009-12-17 21:21:02 +03:00
|
|
|
render :layout => 'base'
|
|
|
|
|
2009-10-29 21:37:00 +03:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
|
2006-07-09 20:30:01 +04:00
|
|
|
def add
|
2007-03-12 20:59:02 +03:00
|
|
|
if request.get?
|
|
|
|
@user = User.new(:language => Setting.default_language)
|
2006-07-09 20:30:01 +04:00
|
|
|
else
|
2007-03-12 20:59:02 +03:00
|
|
|
@user = User.new(params[:user])
|
|
|
|
@user.admin = params[:user][:admin] || false
|
|
|
|
@user.login = params[:user][:login]
|
|
|
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
|
2006-07-09 20:30:01 +04:00
|
|
|
if @user.save
|
2007-05-27 14:57:13 +04:00
|
|
|
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
|
2006-07-30 14:47:02 +04:00
|
|
|
flash[:notice] = l(:notice_successful_create)
|
2009-12-20 13:51:33 +03:00
|
|
|
redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} :
|
|
|
|
{:controller => 'users', :action => 'edit', :id => @user})
|
|
|
|
return
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
end
|
2006-11-12 21:50:30 +03:00
|
|
|
@auth_sources = AuthSource.find(:all)
|
2006-07-09 20:30:01 +04:00
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
|
2006-07-09 20:30:01 +04:00
|
|
|
def edit
|
|
|
|
@user = User.find(params[:id])
|
2008-06-28 00:13:56 +04:00
|
|
|
if request.post?
|
2007-03-12 20:59:02 +03:00
|
|
|
@user.admin = params[:user][:admin] if params[:user][:admin]
|
|
|
|
@user.login = params[:user][:login] if params[:user][:login]
|
|
|
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
|
2009-09-12 12:36:46 +04:00
|
|
|
@user.group_ids = params[:user][:group_ids] if params[:user][:group_ids]
|
2009-02-20 20:04:47 +03:00
|
|
|
@user.attributes = params[:user]
|
|
|
|
# Was the account actived ? (do it before User#save clears the change)
|
|
|
|
was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
|
|
|
|
if @user.save
|
2009-07-05 18:06:14 +04:00
|
|
|
if was_activated
|
|
|
|
Mailer.deliver_account_activated(@user)
|
|
|
|
elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil?
|
|
|
|
Mailer.deliver_account_information(@user, params[:password])
|
|
|
|
end
|
2006-07-30 14:47:02 +04:00
|
|
|
flash[:notice] = l(:notice_successful_update)
|
2009-09-12 12:36:46 +04:00
|
|
|
redirect_to :back
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2006-07-09 20:30:01 +04:00
|
|
|
end
|
2007-03-12 20:59:02 +03:00
|
|
|
@auth_sources = AuthSource.find(:all)
|
|
|
|
@membership ||= Member.new
|
2009-09-12 12:36:46 +04:00
|
|
|
rescue ::ActionController::RedirectBackError
|
|
|
|
redirect_to :controller => 'users', :action => 'edit', :id => @user
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit_membership
|
|
|
|
@user = User.find(params[:id])
|
2010-03-18 18:49:11 +03:00
|
|
|
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
|
2008-05-02 19:21:21 +04:00
|
|
|
@membership.save if request.post?
|
2009-05-10 14:54:31 +04:00
|
|
|
respond_to do |format|
|
2010-08-19 08:33:05 +04:00
|
|
|
if @membership.valid?
|
|
|
|
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
|
|
|
|
format.js {
|
|
|
|
render(:update) {|page|
|
|
|
|
page.replace_html "tab-content-memberships", :partial => 'users/memberships'
|
|
|
|
page.visual_effect(:highlight, "member-#{@membership.id}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
format.js {
|
|
|
|
render(:update) {|page|
|
|
|
|
page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_membership
|
|
|
|
@user = User.find(params[:id])
|
2009-09-12 12:36:46 +04:00
|
|
|
@membership = Member.find(params[:membership_id])
|
|
|
|
if request.post? && @membership.deletable?
|
|
|
|
@membership.destroy
|
|
|
|
end
|
2009-05-10 14:54:31 +04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
|
|
|
|
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} }
|
|
|
|
end
|
2006-07-09 20:30:01 +04:00
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|