diff options
Diffstat (limited to 'app/models/group.rb')
-rw-r--r-- | app/models/group.rb | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index 9824bd998..7b82d1c1f 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -31,17 +31,18 @@ class Group < Principal before_destroy :remove_references_before_destroy - scope :sorted, lambda { order("#{table_name}.lastname ASC") } + scope :sorted, lambda { order("#{table_name}.type, #{table_name}.lastname ASC") } scope :named, lambda {|arg| where("LOWER(#{table_name}.lastname) = LOWER(?)", arg.to_s.strip)} + scope :givable, lambda {where(:type => 'Group')} safe_attributes 'name', 'user_ids', 'custom_field_values', 'custom_fields', - :if => lambda {|group, user| user.admin?} + :if => lambda {|group, user| user.admin? && !group.builtin?} def to_s - lastname.to_s + name.to_s end def name @@ -52,6 +53,20 @@ class Group < Principal self.lastname = arg end + def builtin_type + nil + end + + # Return true if the group is a builtin group + def builtin? + false + end + + # Returns true if the group can be given to a user + def givable? + !builtin? + end + def user_added(user) members.each do |member| next if member.project.nil? @@ -80,6 +95,18 @@ class Group < Principal super(attr_name, *args) end + def self.builtin_id(arg) + (arg.anonymous? ? GroupAnonymous : GroupNonMember).instance_id + end + + def self.anonymous + GroupAnonymous.load_instance + end + + def self.non_member + GroupNonMember.load_instance + end + private # Removes references that are not handled by associations @@ -89,3 +116,5 @@ class Group < Principal Issue.where(['assigned_to_id = ?', id]).update_all('assigned_to_id = NULL') end end + +require_dependency "group_builtin" |