summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-11-15 16:09:27 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2018-11-15 16:09:27 +0100
commit0aa386f75c96356a7f40c0b8029f9df608babe99 (patch)
treee2aad7e4a44d82bc144556aa43e3c18763145f6c
parent379ed169f7a848d5f946e01f08fb8354b7a59d9d (diff)
downloadgitlab-ce-refactor-member-add-user-for-ee.tar.gz
Refactor Member#add_user for GitLab EErefactor-member-add-user-for-ee
GitLab EE extends Member#add_user by adding some LDAP specific flags. Prior to these changes, the only way this could be done was by modifying Member#add_user in place. This could lead to merge conflicts whenever a developer wants to change this method. To resolve this issue, the logic that EE extends has been moved into a separate method with the appropriate arguments. This allows EE to extend the logic by prepending the method using an EE specific module.
-rw-r--r--app/models/member.rb24
1 files changed, 19 insertions, 5 deletions
diff --git a/app/models/member.rb b/app/models/member.rb
index 0696ea46c8b..bc8ac14d148 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -152,11 +152,13 @@ class Member < ActiveRecord::Base
return member unless can_update_member?(current_user, member)
- member.attributes = {
- created_by: member.created_by || current_user,
- access_level: access_level,
- expires_at: expires_at
- }
+ set_member_attributes(
+ member,
+ access_level,
+ current_user: current_user,
+ expires_at: expires_at,
+ ldap: ldap
+ )
if member.request?
::Members::ApproveAccessRequestService.new(
@@ -175,6 +177,18 @@ class Member < ActiveRecord::Base
# rubocop: enable CodeReuse/ServiceClass
end
+ # Populates the attributes of a member.
+ #
+ # This logic resides in a separate method so that EE can extend this logic,
+ # without having to patch the `add_user` method directly.
+ def set_member_attributes(member, access_level, current_user: nil, expires_at: nil, ldap: false)
+ member.attributes = {
+ created_by: member.created_by || current_user,
+ access_level: access_level,
+ expires_at: expires_at
+ }
+ end
+
def add_users(source, users, access_level, current_user: nil, expires_at: nil)
return [] unless users.present?