##// END OF EJS Templates
remove trailing white-spaces from app/models/group.rb....
Toshi MARUYAMA -
r6722:ce24f4fb89a7
parent child
Show More
@@ -5,12 +5,12
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -18,21 +18,21
18 class Group < Principal
18 class Group < Principal
19 has_and_belongs_to_many :users, :after_add => :user_added,
19 has_and_belongs_to_many :users, :after_add => :user_added,
20 :after_remove => :user_removed
20 :after_remove => :user_removed
21
21
22 acts_as_customizable
22 acts_as_customizable
23
23
24 validates_presence_of :lastname
24 validates_presence_of :lastname
25 validates_uniqueness_of :lastname, :case_sensitive => false
25 validates_uniqueness_of :lastname, :case_sensitive => false
26 validates_length_of :lastname, :maximum => 30
26 validates_length_of :lastname, :maximum => 30
27
27
28 before_destroy :remove_references_before_destroy
28 before_destroy :remove_references_before_destroy
29
29
30 def to_s
30 def to_s
31 lastname.to_s
31 lastname.to_s
32 end
32 end
33
33
34 alias :name :to_s
34 alias :name :to_s
35
35
36 def user_added(user)
36 def user_added(user)
37 members.each do |member|
37 members.each do |member|
38 next if member.project.nil?
38 next if member.project.nil?
@@ -43,20 +43,20 class Group < Principal
43 user_member.save!
43 user_member.save!
44 end
44 end
45 end
45 end
46
46
47 def user_removed(user)
47 def user_removed(user)
48 members.each do |member|
48 members.each do |member|
49 MemberRole.find(:all, :include => :member,
49 MemberRole.find(:all, :include => :member,
50 :conditions => ["#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids]).each(&:destroy)
50 :conditions => ["#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids]).each(&:destroy)
51 end
51 end
52 end
52 end
53
53
54 private
54 private
55
55
56 # Removes references that are not handled by associations
56 # Removes references that are not handled by associations
57 def remove_references_before_destroy
57 def remove_references_before_destroy
58 return if self.id.nil?
58 return if self.id.nil?
59
59
60 Issue.update_all 'assigned_to_id = NULL', ['assigned_to_id = ?', id]
60 Issue.update_all 'assigned_to_id = NULL', ['assigned_to_id = ?', id]
61 end
61 end
62 end
62 end
General Comments 0
You need to be logged in to leave comments. Login now