Class: Group

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

Overview

– copyright ChiliProject is a project management system.

Copyright (C) 2010-2013 the ChiliProject Team

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.

See doc/COPYRIGHT.rdoc for more details. ++

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Principal

#<=>, #active?, #allowed_to?, #allowed_to_globally?, #logged?, #name, #roles_for_project, #to_liquid

Class Method Details

.human_attribute_name(attribute_name) ⇒ Object


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

def self.human_attribute_name(attribute_name)
  attribute_name = "name" if attribute_name == "lastname"
  super(attribute_name)
end

Instance Method Details

#mailsObject

Returns an array of all of the email addresses of the group's users


26
27
28
# File 'app/models/group.rb', line 26

def mails
  users.collect(&:mail)
end

#to_sObject


30
31
32
# File 'app/models/group.rb', line 30

def to_s
  lastname.to_s
end

#user_added(user) ⇒ Object


34
35
36
37
38
39
40
41
42
43
# File 'app/models/group.rb', line 34

def user_added(user)
  members.each do |member|
    next if member.project.nil?
    user_member = Member.find_by_project_id_and_user_id(member.project_id, user.id) || Member.new(:project_id => member.project_id, :user_id => user.id)
    member.member_roles.each do |member_role|
      user_member.member_roles << MemberRole.new(:role => member_role.role, :inherited_from => member_role.id)
    end
    user_member.save!
  end
end

#user_removed(user) ⇒ Object


45
46
47
48
49
50
# File 'app/models/group.rb', line 45

def user_removed(user)
  members.each do |member|
    MemberRole.find(:all, :include => :member,
                          :conditions => ["#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids]).each(&:destroy)
  end
end