annotate .svn/pristine/49/495cc5a283de3e4fafefb5b73cc74e75d6f168ab.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 e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 class Group < Principal
Chris@1494 19 include Redmine::SafeAttributes
Chris@1494 20
Chris@1494 21 has_and_belongs_to_many :users, :after_add => :user_added,
Chris@1494 22 :after_remove => :user_removed
Chris@1494 23
Chris@1494 24 acts_as_customizable
Chris@1494 25
Chris@1494 26 validates_presence_of :lastname
Chris@1494 27 validates_uniqueness_of :lastname, :case_sensitive => false
Chris@1494 28 validates_length_of :lastname, :maximum => 255
Chris@1494 29
Chris@1494 30 before_destroy :remove_references_before_destroy
Chris@1494 31
Chris@1494 32 scope :sorted, lambda { order("#{table_name}.lastname ASC") }
Chris@1494 33 scope :named, lambda {|arg| where("LOWER(#{table_name}.lastname) = LOWER(?)", arg.to_s.strip)}
Chris@1494 34
Chris@1494 35 safe_attributes 'name',
Chris@1494 36 'user_ids',
Chris@1494 37 'custom_field_values',
Chris@1494 38 'custom_fields',
Chris@1494 39 :if => lambda {|group, user| user.admin?}
Chris@1494 40
Chris@1494 41 def to_s
Chris@1494 42 lastname.to_s
Chris@1494 43 end
Chris@1494 44
Chris@1494 45 def name
Chris@1494 46 lastname
Chris@1494 47 end
Chris@1494 48
Chris@1494 49 def name=(arg)
Chris@1494 50 self.lastname = arg
Chris@1494 51 end
Chris@1494 52
Chris@1494 53 def user_added(user)
Chris@1494 54 members.each do |member|
Chris@1494 55 next if member.project.nil?
Chris@1494 56 user_member = Member.find_by_project_id_and_user_id(member.project_id, user.id) || Member.new(:project_id => member.project_id, :user_id => user.id)
Chris@1494 57 member.member_roles.each do |member_role|
Chris@1494 58 user_member.member_roles << MemberRole.new(:role => member_role.role, :inherited_from => member_role.id)
Chris@1494 59 end
Chris@1494 60 user_member.save!
Chris@1494 61 end
Chris@1494 62 end
Chris@1494 63
Chris@1494 64 def user_removed(user)
Chris@1494 65 members.each do |member|
Chris@1494 66 MemberRole.
Chris@1494 67 includes(:member).
Chris@1494 68 where("#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids).
Chris@1494 69 all.
Chris@1494 70 each(&:destroy)
Chris@1494 71 end
Chris@1494 72 end
Chris@1494 73
Chris@1494 74 def self.human_attribute_name(attribute_key_name, *args)
Chris@1494 75 attr_name = attribute_key_name.to_s
Chris@1494 76 if attr_name == 'lastname'
Chris@1494 77 attr_name = "name"
Chris@1494 78 end
Chris@1494 79 super(attr_name, *args)
Chris@1494 80 end
Chris@1494 81
Chris@1494 82 private
Chris@1494 83
Chris@1494 84 # Removes references that are not handled by associations
Chris@1494 85 def remove_references_before_destroy
Chris@1494 86 return if self.id.nil?
Chris@1494 87
Chris@1494 88 Issue.update_all 'assigned_to_id = NULL', ['assigned_to_id = ?', id]
Chris@1494 89 end
Chris@1494 90 end