Mercurial > hg > soundsoftware-site
diff app/controllers/users_controller.rb @ 1338:25603efa57b5
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 20 Jun 2013 13:14:14 +0100 |
parents | 96790506f247 |
children | 4f746d8966dd 51364c0cd58f |
line wrap: on
line diff
--- a/app/controllers/users_controller.rb Wed Jan 23 13:11:25 2013 +0000 +++ b/app/controllers/users_controller.rb Thu Jun 20 13:14:14 2013 +0100 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2011 Jean-Philippe Lang +# Copyright (C) 2006-2012 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -38,23 +38,17 @@ @limit = per_page_option end - scope = User - scope = scope.in_group(params[:group_id].to_i) if params[:group_id].present? + @status = params[:status] || 1 - @status = params[:status] ? params[:status].to_i : 1 - c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) + scope = User.logged.status(@status) + scope = scope.like(params[:name]) if params[:name].present? + scope = scope.in_group(params[:group_id]) if params[:group_id].present? - unless params[:name].blank? - name = "%#{params[:name].strip.downcase}%" - c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] - end - - @user_count = scope.count(:conditions => c.conditions) + @user_count = scope.count @user_pages = Paginator.new self, @user_count, @limit, params['page'] @offset ||= @user_pages.current.offset @users = scope.find :all, :order => sort_clause, - :conditions => c.conditions, :limit => @limit, :offset => @offset @@ -71,15 +65,7 @@ if @user.ssamr_user_detail != nil @description = @user.ssamr_user_detail.description - - if @user.ssamr_user_detail.institution_type != nil - # institution_type is true for listed institutions - if (@user.ssamr_user_detail.institution_type) - @institution_name = Institution.find(@user.ssamr_user_detail.institution_id).name - else - @institution_name = @user.ssamr_user_detail.other_institution - end - end + @institution_name = @user.ssamr_user_detail.institution_name end # show projects based on current user visibility @@ -108,7 +94,6 @@ @ssamr_user_details = SsamrUserDetail.new end - verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } def create @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) @user.safe_attributes = params[:user] @@ -127,16 +112,18 @@ @user.ssamr_user_detail = @ssamr_user_details if @user.save + @user.pref.attributes = params[:pref] + @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') @user.pref.save @ssamr_user_details.save! - Mailer.deliver_account_information(@user, params[:user][:password]) if params[:send_information] + Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information] respond_to do |format| format.html { - flash[:notice] = l(:notice_successful_create) + flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user))) redirect_to(params[:continue] ? {:controller => 'users', :action => 'new'} : {:controller => 'users', :action => 'edit', :id => @user} @@ -170,7 +157,6 @@ @membership ||= Member.new end - verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } def update @user.admin = params[:user][:admin] if params[:user][:admin] @user.login = params[:user][:login] if params[:user][:login] @@ -209,17 +195,17 @@ @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) if was_activated - Mailer.deliver_account_activated(@user) + Mailer.account_activated(@user).deliver elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil? - Mailer.deliver_account_information(@user, params[:user][:password]) + Mailer.account_information(@user, params[:user][:password]).deliver end respond_to do |format| format.html { flash[:notice] = l(:notice_successful_update) - redirect_to :back + redirect_to_referer_or edit_user_path(@user) } - format.api { head :ok } + format.api { render_api_ok } end else @auth_sources = AuthSource.find(:all) @@ -232,49 +218,33 @@ format.api { render_validation_errors(@user) } end end - rescue ::ActionController::RedirectBackError - redirect_to :controller => 'users', :action => 'edit', :id => @user end - verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } def destroy @user.destroy respond_to do |format| - format.html { redirect_to(users_url) } - format.api { head :ok } + format.html { redirect_back_or_default(users_url) } + format.api { render_api_ok } end end def edit_membership @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) - @membership.save if request.post? + @membership.save respond_to do |format| - 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 + format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } + format.js end end def destroy_membership @membership = Member.find(params[:membership_id]) - if request.post? && @membership.deletable? + if @membership.deletable? @membership.destroy end 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'} } + format.js end end