summaryrefslogtreecommitdiff
path: root/app/models/group.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/group.rb')
-rw-r--r--app/models/group.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index da9621a2a1a..eec961f6012 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -46,19 +46,21 @@ class Group < Namespace
@owners ||= group_members.owners.map(&:user)
end
- def add_users(user_ids, access_level)
+ def add_users(user_ids, access_level, current_user = nil)
user_ids.compact.each do |user_id|
- user = self.group_members.find_or_initialize_by(user_id: user_id)
- user.update_attributes(access_level: access_level)
+ member = self.group_members.find_or_initialize_by(user_id: user_id)
+ member.access_level = access_level
+ member.created_by ||= current_user
+ member.save
end
end
- def add_user(user, access_level)
- self.group_members.create(user_id: user.id, access_level: access_level)
+ def add_user(user, access_level, current_user = nil)
+ add_users([user], access_level, current_user)
end
- def add_owner(user)
- self.add_user(user, Gitlab::Access::OWNER)
+ def add_owner(user, current_user = nil)
+ self.add_user(user, Gitlab::Access::OWNER, current_user)
end
def has_owner?(user)