annotate .svn/pristine/42/4253341f27fc3e107be2ed027175bb96fadeecca.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 class UsersController < ApplicationController
Chris@1517 19 layout 'admin'
Chris@1517 20
Chris@1517 21 before_filter :require_admin, :except => :show
Chris@1517 22 before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership]
Chris@1517 23 accept_api_auth :index, :show, :create, :update, :destroy
Chris@1517 24
Chris@1517 25 helper :sort
Chris@1517 26 include SortHelper
Chris@1517 27 helper :custom_fields
Chris@1517 28 include CustomFieldsHelper
Chris@1517 29
Chris@1517 30 def index
Chris@1517 31 sort_init 'login', 'asc'
Chris@1517 32 sort_update %w(login firstname lastname mail admin created_on last_login_on)
Chris@1517 33
Chris@1517 34 case params[:format]
Chris@1517 35 when 'xml', 'json'
Chris@1517 36 @offset, @limit = api_offset_and_limit
Chris@1517 37 else
Chris@1517 38 @limit = per_page_option
Chris@1517 39 end
Chris@1517 40
Chris@1517 41 @status = params[:status] || 1
Chris@1517 42
Chris@1517 43 scope = User.logged.status(@status)
Chris@1517 44 scope = scope.like(params[:name]) if params[:name].present?
Chris@1517 45 scope = scope.in_group(params[:group_id]) if params[:group_id].present?
Chris@1517 46
Chris@1517 47 @user_count = scope.count
Chris@1517 48 @user_pages = Paginator.new @user_count, @limit, params['page']
Chris@1517 49 @offset ||= @user_pages.offset
Chris@1517 50 @users = scope.order(sort_clause).limit(@limit).offset(@offset).all
Chris@1517 51
Chris@1517 52 respond_to do |format|
Chris@1517 53 format.html {
Chris@1517 54 @groups = Group.all.sort
Chris@1517 55 render :layout => !request.xhr?
Chris@1517 56 }
Chris@1517 57 format.api
Chris@1517 58 end
Chris@1517 59 end
Chris@1517 60
Chris@1517 61 def show
Chris@1517 62 # show projects based on current user visibility
Chris@1517 63 @memberships = @user.memberships.where(Project.visible_condition(User.current)).all
Chris@1517 64
Chris@1517 65 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
Chris@1517 66 @events_by_day = events.group_by(&:event_date)
Chris@1517 67
Chris@1517 68 unless User.current.admin?
Chris@1517 69 if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
Chris@1517 70 render_404
Chris@1517 71 return
Chris@1517 72 end
Chris@1517 73 end
Chris@1517 74
Chris@1517 75 respond_to do |format|
Chris@1517 76 format.html { render :layout => 'base' }
Chris@1517 77 format.api
Chris@1517 78 end
Chris@1517 79 end
Chris@1517 80
Chris@1517 81 def new
Chris@1517 82 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
Chris@1517 83 @user.safe_attributes = params[:user]
Chris@1517 84 @auth_sources = AuthSource.all
Chris@1517 85 end
Chris@1517 86
Chris@1517 87 def create
Chris@1517 88 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
Chris@1517 89 @user.safe_attributes = params[:user]
Chris@1517 90 @user.admin = params[:user][:admin] || false
Chris@1517 91 @user.login = params[:user][:login]
Chris@1517 92 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
Chris@1517 93 @user.pref.attributes = params[:pref]
Chris@1517 94
Chris@1517 95 if @user.save
Chris@1517 96 Mailer.account_information(@user, @user.password).deliver if params[:send_information]
Chris@1517 97
Chris@1517 98 respond_to do |format|
Chris@1517 99 format.html {
Chris@1517 100 flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
Chris@1517 101 if params[:continue]
Chris@1517 102 attrs = params[:user].slice(:generate_password)
Chris@1517 103 redirect_to new_user_path(:user => attrs)
Chris@1517 104 else
Chris@1517 105 redirect_to edit_user_path(@user)
Chris@1517 106 end
Chris@1517 107 }
Chris@1517 108 format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
Chris@1517 109 end
Chris@1517 110 else
Chris@1517 111 @auth_sources = AuthSource.all
Chris@1517 112 # Clear password input
Chris@1517 113 @user.password = @user.password_confirmation = nil
Chris@1517 114
Chris@1517 115 respond_to do |format|
Chris@1517 116 format.html { render :action => 'new' }
Chris@1517 117 format.api { render_validation_errors(@user) }
Chris@1517 118 end
Chris@1517 119 end
Chris@1517 120 end
Chris@1517 121
Chris@1517 122 def edit
Chris@1517 123 @auth_sources = AuthSource.all
Chris@1517 124 @membership ||= Member.new
Chris@1517 125 end
Chris@1517 126
Chris@1517 127 def update
Chris@1517 128 @user.admin = params[:user][:admin] if params[:user][:admin]
Chris@1517 129 @user.login = params[:user][:login] if params[:user][:login]
Chris@1517 130 if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
Chris@1517 131 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
Chris@1517 132 end
Chris@1517 133 @user.safe_attributes = params[:user]
Chris@1517 134 # Was the account actived ? (do it before User#save clears the change)
Chris@1517 135 was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
Chris@1517 136 # TODO: Similar to My#account
Chris@1517 137 @user.pref.attributes = params[:pref]
Chris@1517 138
Chris@1517 139 if @user.save
Chris@1517 140 @user.pref.save
Chris@1517 141
Chris@1517 142 if was_activated
Chris@1517 143 Mailer.account_activated(@user).deliver
Chris@1517 144 elsif @user.active? && params[:send_information] && @user.password.present? && @user.auth_source_id.nil?
Chris@1517 145 Mailer.account_information(@user, @user.password).deliver
Chris@1517 146 end
Chris@1517 147
Chris@1517 148 respond_to do |format|
Chris@1517 149 format.html {
Chris@1517 150 flash[:notice] = l(:notice_successful_update)
Chris@1517 151 redirect_to_referer_or edit_user_path(@user)
Chris@1517 152 }
Chris@1517 153 format.api { render_api_ok }
Chris@1517 154 end
Chris@1517 155 else
Chris@1517 156 @auth_sources = AuthSource.all
Chris@1517 157 @membership ||= Member.new
Chris@1517 158 # Clear password input
Chris@1517 159 @user.password = @user.password_confirmation = nil
Chris@1517 160
Chris@1517 161 respond_to do |format|
Chris@1517 162 format.html { render :action => :edit }
Chris@1517 163 format.api { render_validation_errors(@user) }
Chris@1517 164 end
Chris@1517 165 end
Chris@1517 166 end
Chris@1517 167
Chris@1517 168 def destroy
Chris@1517 169 @user.destroy
Chris@1517 170 respond_to do |format|
Chris@1517 171 format.html { redirect_back_or_default(users_path) }
Chris@1517 172 format.api { render_api_ok }
Chris@1517 173 end
Chris@1517 174 end
Chris@1517 175
Chris@1517 176 def edit_membership
Chris@1517 177 @membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
Chris@1517 178 @membership.save
Chris@1517 179 respond_to do |format|
Chris@1517 180 format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
Chris@1517 181 format.js
Chris@1517 182 end
Chris@1517 183 end
Chris@1517 184
Chris@1517 185 def destroy_membership
Chris@1517 186 @membership = Member.find(params[:membership_id])
Chris@1517 187 if @membership.deletable?
Chris@1517 188 @membership.destroy
Chris@1517 189 end
Chris@1517 190 respond_to do |format|
Chris@1517 191 format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
Chris@1517 192 format.js
Chris@1517 193 end
Chris@1517 194 end
Chris@1517 195
Chris@1517 196 private
Chris@1517 197
Chris@1517 198 def find_user
Chris@1517 199 if params[:id] == 'current'
Chris@1517 200 require_login || return
Chris@1517 201 @user = User.current
Chris@1517 202 else
Chris@1517 203 @user = User.find(params[:id])
Chris@1517 204 end
Chris@1517 205 rescue ActiveRecord::RecordNotFound
Chris@1517 206 render_404
Chris@1517 207 end
Chris@1517 208 end