From 7e7ac5340a281ed767066af0b5f4dd45a3d7076f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 28 Sep 2014 14:51:08 +0000 Subject: 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 --- app/models/group.rb | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'app/models/group.rb') 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" -- cgit v1.2.3