Class: Group

Inherits:
Principal show all
Includes:
Redmine::SafeAttributes
Defined in:
app/models/group.rb

Overview

Redmine - project management software Copyright © 2006- Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Direct Known Subclasses

GroupBuiltin

Constant Summary

Constants inherited from Principal

Principal::STATUS_ACTIVE, Principal::STATUS_ANONYMOUS, Principal::STATUS_LOCKED, Principal::STATUS_REGISTERED

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Redmine::SafeAttributes

#delete_unsafe_attributes, included, #safe_attribute?, #safe_attribute_names, #safe_attributes=

Methods inherited from Principal

#<=>, #active?, detect_by_keyword, fields_for_order_statement, #mail, #mail=, #member_of?, #name, #nullify_projects_default_assigned_to, #project_ids, #reload, #visible?

Class Method Details

.anonymousObject



105
106
107
# File 'app/models/group.rb', line 105

def self.anonymous
  GroupAnonymous.load_instance
end

.human_attribute_name(attribute_key_name, *args) ⇒ Object



97
98
99
100
101
102
103
# File 'app/models/group.rb', line 97

def self.human_attribute_name(attribute_key_name, *args)
  attr_name = attribute_key_name.to_s
  if attr_name == 'lastname'
    attr_name = "name"
  end
  super(attr_name, *args)
end

.non_memberObject



109
110
111
# File 'app/models/group.rb', line 109

def self.non_member
  GroupNonMember.load_instance
end

Instance Method Details

#builtin?Boolean

Return true if the group is a builtin group

Returns:

  • (Boolean)


61
62
63
# File 'app/models/group.rb', line 61

def builtin?
  false
end

#builtin_typeObject



56
57
58
# File 'app/models/group.rb', line 56

def builtin_type
  nil
end

#css_classesObject



70
71
72
# File 'app/models/group.rb', line 70

def css_classes
  'group'
end

#givable?Boolean

Returns true if the group can be given to a user

Returns:

  • (Boolean)


66
67
68
# File 'app/models/group.rb', line 66

def givable?
  !builtin?
end

#to_sObject



52
53
54
# File 'app/models/group.rb', line 52

def to_s
  name.to_s
end

#user_added(user) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/group.rb', line 74

def user_added(user)
  members.preload(:member_roles).each do |member|
    next if member.project_id.nil?
    # skip if the group is a member without roles in the project
    next if member.member_roles.empty?

    user_member =
      Member.find_or_initialize_by(:project_id => member.project_id, :user_id => user.id)
    user_member.member_roles <<
      member.member_roles.pluck(:id, :role_id).map do |id, role_id|
        MemberRole.new(:role_id => role_id, :inherited_from => id)
      end
    user_member.save!
  end
end

#user_removed(user) ⇒ Object



90
91
92
93
94
95
# File 'app/models/group.rb', line 90

def user_removed(user)
  MemberRole.
    joins(:member).
    where("#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, MemberRole.select(:id).where(:member => members)).
    destroy_all
end