diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-09-26 14:49:22 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-09-26 14:49:22 +0300 |
commit | 65b9768ccfbdc3de682d66430601cf3af1b2a2f8 (patch) | |
tree | b414c17b43b098b92b27cb1bb2cf1ffe40644f0c /app/models/group.rb | |
parent | edd2143d35d439e203d53b5e413f71e9f02db139 (diff) | |
download | gitlab-ce-65b9768ccfbdc3de682d66430601cf3af1b2a2f8.tar.gz |
Group ownership completely based on users_groups relation now
Before we have only owner_id to determine group owner
With multiple owners per group we should get rid of owner_id in group.
So from now @group.owner will always be nil but
@group.owners return an actual array of users who can admin this group
Diffstat (limited to 'app/models/group.rb')
-rw-r--r-- | app/models/group.rb | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index 0b36c934375..0cc3a3a0f41 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -16,14 +16,12 @@ class Group < Namespace has_many :users_groups, dependent: :destroy has_many :users, through: :users_groups - after_create :add_owner - def human_name name end def owners - @owners ||= (users_groups.owners.map(&:user) << owner).uniq + @owners ||= users_groups.owners.map(&:user) end def add_users(user_ids, group_access) @@ -36,20 +34,19 @@ class Group < Namespace self.users_groups.create(user_id: user.id, group_access: group_access) end - def change_owner(user) - self.owner = user - membership = users_groups.where(user_id: user.id).first + def add_owner(user) + self.add_user(user, UsersGroup::OWNER) + end - if membership - membership.update_attributes(group_access: UsersGroup::OWNER) - else - add_owner - end + def has_owner?(user) + owners.include?(user) end - private + def last_owner?(user) + has_owner?(user) && owners.size == 1 + end - def add_owner - self.add_users([owner.id], UsersGroup::OWNER) + def members + users_groups end end |