diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 058752e..1d0ffeb 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -144,6 +144,27 @@ class IssuesController < ApplicationController @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => (params[:custom_fields] ? params[:custom_fields][x.id.to_s] : nil)) } + + # Create search string to find this issues author + user_name = params[:user][:name] + case Setting.user_format + when :firstname_lastname then search = ['firstname = ? AND lastname = ?', user_name.split(' ')[0], user_name.split(' ')[1]] + when :firstname then search = ['firstname = ?', user_name] + when :lastname_firstname then search = ['lastname = ? AND firstname = ?', user_name.split(' ')[0], user_name.split(' ')[1]] + when :lastname_coma_firstname then search = ['lastname = ? AND firstname = ?', user_name.split(', ')[0], user_name.split(', ')[1]] + when :username then search = ['login = ?', user_name] + end + + # FIXME: user search below assumes there is only one + # individual with this firstname/lastname combination + @issue.author = User.find(:first, :conditions => search) + + if @issue.author.nil? + flash[:error] = "Can't find #{l(:field_author)} entered." + redirect_to :controller => 'issues', :action => 'new', :issue => params[:issue] + return + end + @issue.custom_values = @custom_values if @issue.save attach_files(@issue, params[:attachments]) @@ -157,6 +178,15 @@ class IssuesController < ApplicationController render :layout => !request.xhr? end + def auto_complete_for_user_name + search = params[:user][:name] + @users = Project.find_by_identifier(params[:project]).users.find(:all, + :conditions => ['LOWER(lastname) LIKE ?', "#{search.downcase}%"], + :order => 'lastname ASC', + :limit => 10) unless search.blank? + render :partial => "user_search" + end + # Attributes that can be updated on workflow transition (without :edit permission) # TODO: make it configurable (at least per role) UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)