# HG changeset patch # User Chris Cannam # Date 1381506164 -3600 # Node ID ea2a09a0fd907be181faf6a8b872f17fb9cf88fe # Parent 96973aaacd75300b93bbf7c9215da5fd51525d29# Parent 23b4cba01fc1e9702a75691d7c57988558187391 Merge from luisf branch diff -r 96973aaacd75 -r ea2a09a0fd90 plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Oct 11 09:24:18 2013 +0100 +++ b/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Oct 11 16:42:44 2013 +0100 @@ -203,7 +203,8 @@ # todo: make sure query works with both pgres and mysql ~lf.20131010 authors_list = Author.joins(:authorships).where("LOWER(authorships.name_on_paper) LIKE LOWER(?)", "%#{params[:term]}%").uniq - users_list = User.active.like(params[:term]).find(:all, :limit => 100) + # name_like scope, defined in lib/user_author patch + users_list = User.active.name_like(params[:term]).find(:all, :limit => 100) logger.debug "Query for \"#{params[:term]}\" returned \"#{authors_list.size}\" authors and \"#{users_list.size}\" users" diff -r 96973aaacd75 -r ea2a09a0fd90 plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb --- a/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb Fri Oct 11 09:24:18 2013 +0100 +++ b/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb Fri Oct 11 16:42:44 2013 +0100 @@ -4,15 +4,34 @@ module UserAuthorPatch def self.included(base) base.send(:include, InstanceMethods) - extend ClassMethods + + base.class_eval do + # adapted from the app/models/principals_model.rb + # to remove the email address from the search + scope :name_like, lambda {|q| + q = q.to_s + if q.blank? + where({}) + else + pattern = "%#{q}%" + sql = %w(login firstname lastname).map {|column| "LOWER(#{ table_name}. #{column}) LIKE LOWER(:p)"}.join(" OR ") + params = {:p => pattern} + if q =~ /^(.+)\s+(.+)$/ + a, b = "#{$1}%", "#{$2}%" + sql << " OR (LOWER(#{table_name}.firstname) LIKE LOWER(:a) AND LOWER (#{table_name}.lastname) LIKE LOWER(:b))" + sql << " OR (LOWER(#{table_name}.firstname) LIKE LOWER(:b) AND LOWER (#{table_name}.lastname) LIKE LOWER(:a))" + params.merge!(:a => a, :b => b) + end + where(sql, params) + end + } + end #base.class_eval end #self.included - module ClassMethods - end - module InstanceMethods + # todo: deprecated? ~lf.20131011 def institution unless self.ssamr_user_detail.nil? institution_name = self.ssamr_user_detail.institution_name