diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-09-28 14:51:08 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-09-28 14:51:08 +0000 |
commit | 7e7ac5340a281ed767066af0b5f4dd45a3d7076f (patch) | |
tree | 891640b0548c0d3063daddb219006d120fa312c3 /app/models/group.rb | |
parent | 9a7fb0ad7be0ee3403f5b89eb0c16b68c991d519 (diff) | |
download | redmine-7e7ac5340a281ed767066af0b5f4dd45a3d7076f.tar.gz redmine-7e7ac5340a281ed767066af0b5f4dd45a3d7076f.zip |
Adds buit-in groups to give specific permissions to anonymous and non members users per project (#17976).
git-svn-id: http://svn.redmine.org/redmine/trunk@13417 e93f8b46-1217-0410-a6f0-8f06a7374b81
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" |