annotate .svn/pristine/ff/ff04cf077140b4271f4635f43f1e5b7cbcdbac00.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 Group < Principal
Chris@1517 19 include Redmine::SafeAttributes
Chris@1517 20
Chris@1517 21 has_and_belongs_to_many :users,
Chris@1517 22 :join_table => "#{table_name_prefix}groups_users#{table_name_suffix}",
Chris@1517 23 :after_add => :user_added,
Chris@1517 24 :after_remove => :user_removed
Chris@1517 25
Chris@1517 26 acts_as_customizable
Chris@1517 27
Chris@1517 28 validates_presence_of :lastname
Chris@1517 29 validates_uniqueness_of :lastname, :case_sensitive => false
Chris@1517 30 validates_length_of :lastname, :maximum => 255
Chris@1517 31
Chris@1517 32 before_destroy :remove_references_before_destroy
Chris@1517 33
Chris@1517 34 scope :sorted, lambda { order("#{table_name}.lastname ASC") }
Chris@1517 35 scope :named, lambda {|arg| where("LOWER(#{table_name}.lastname) = LOWER(?)", arg.to_s.strip)}
Chris@1517 36
Chris@1517 37 safe_attributes 'name',
Chris@1517 38 'user_ids',
Chris@1517 39 'custom_field_values',
Chris@1517 40 'custom_fields',
Chris@1517 41 :if => lambda {|group, user| user.admin?}
Chris@1517 42
Chris@1517 43 def to_s
Chris@1517 44 lastname.to_s
Chris@1517 45 end
Chris@1517 46
Chris@1517 47 def name
Chris@1517 48 lastname
Chris@1517 49 end
Chris@1517 50
Chris@1517 51 def name=(arg)
Chris@1517 52 self.lastname = arg
Chris@1517 53 end
Chris@1517 54
Chris@1517 55 def user_added(user)
Chris@1517 56 members.each do |member|
Chris@1517 57 next if member.project.nil?
Chris@1517 58 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@1517 59 member.member_roles.each do |member_role|
Chris@1517 60 user_member.member_roles << MemberRole.new(:role => member_role.role, :inherited_from => member_role.id)
Chris@1517 61 end
Chris@1517 62 user_member.save!
Chris@1517 63 end
Chris@1517 64 end
Chris@1517 65
Chris@1517 66 def user_removed(user)
Chris@1517 67 members.each do |member|
Chris@1517 68 MemberRole.
Chris@1517 69 includes(:member).
Chris@1517 70 where("#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids).
Chris@1517 71 each(&:destroy)
Chris@1517 72 end
Chris@1517 73 end
Chris@1517 74
Chris@1517 75 def self.human_attribute_name(attribute_key_name, *args)
Chris@1517 76 attr_name = attribute_key_name.to_s
Chris@1517 77 if attr_name == 'lastname'
Chris@1517 78 attr_name = "name"
Chris@1517 79 end
Chris@1517 80 super(attr_name, *args)
Chris@1517 81 end
Chris@1517 82
Chris@1517 83 private
Chris@1517 84
Chris@1517 85 # Removes references that are not handled by associations
Chris@1517 86 def remove_references_before_destroy
Chris@1517 87 return if self.id.nil?
Chris@1517 88
Chris@1517 89 Issue.where(['assigned_to_id = ?', id]).update_all('assigned_to_id = NULL')
Chris@1517 90 end
Chris@1517 91 end