gitlab-org--gitlab-foss/app/models/group.rb

41 lines
914 B
Ruby
Raw Normal View History

2012-11-19 13:24:05 -05:00
# == Schema Information
#
2012-11-24 15:16:51 -05:00
# Table name: namespaces
2012-11-19 13:24:05 -05:00
#
2013-02-07 05:42:52 -05:00
# id :integer not null, primary key
# name :string(255) not null
# path :string(255) not null
# owner_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# type :string(255)
2013-03-15 09:16:02 -04:00
# description :string(255) default(""), not null
2012-11-19 13:24:05 -05:00
#
class Group < Namespace
has_many :users_groups, dependent: :destroy
has_many :users, through: :users_groups
2013-04-02 18:28:12 -04:00
after_create :add_owner
def human_name
name
end
2012-12-30 07:26:19 -05:00
def owners
@owners ||= (users_groups.owners.map(&:user) << owner)
end
def add_users(user_ids, group_access)
user_ids.compact.each do |user_id|
self.users_groups.create(user_id: user_id, group_access: group_access)
end
end
private
def add_owner
self.add_users([owner.id], UsersGroup::OWNER)
end
2012-10-02 11:17:12 -04:00
end