annotate app/models/group.rb @ 45:65d9e2cabaa3 luisf

Added tipoftheday to the config/settings in order to correct previous issues. Tip of the day is now working correctly. Added the heading strings to the locales files.
author luisf
date Tue, 23 Nov 2010 11:50:01 +0000
parents 513646585e45
children af80e5618e9b
rev   line source
Chris@0 1 # Redmine - project management software
Chris@0 2 # Copyright (C) 2006-2009 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class Group < Principal
Chris@0 19 has_and_belongs_to_many :users, :after_add => :user_added,
Chris@0 20 :after_remove => :user_removed
Chris@0 21
Chris@0 22 acts_as_customizable
Chris@0 23
Chris@0 24 validates_presence_of :lastname
Chris@0 25 validates_uniqueness_of :lastname, :case_sensitive => false
Chris@0 26 validates_length_of :lastname, :maximum => 30
Chris@0 27
Chris@0 28 def to_s
Chris@0 29 lastname.to_s
Chris@0 30 end
Chris@0 31
Chris@0 32 def user_added(user)
Chris@0 33 members.each do |member|
Chris@0 34 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@0 35 member.member_roles.each do |member_role|
Chris@0 36 user_member.member_roles << MemberRole.new(:role => member_role.role, :inherited_from => member_role.id)
Chris@0 37 end
Chris@0 38 user_member.save!
Chris@0 39 end
Chris@0 40 end
Chris@0 41
Chris@0 42 def user_removed(user)
Chris@0 43 members.each do |member|
Chris@0 44 MemberRole.find(:all, :include => :member,
Chris@0 45 :conditions => ["#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids]).each(&:destroy)
Chris@0 46 end
Chris@0 47 end
Chris@0 48 end