Commit 66880cf7 authored by Yorick Peterse's avatar Yorick Peterse

Refactor Member#add_user for GitLab 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.
parent 0dfac552
......@@ -9,7 +9,6 @@ class Member < ActiveRecord::Base
include Presentable
attr_accessor :raw_invite_token
attr_accessor :skip_notification
belongs_to :created_by, class_name: "User"
belongs_to :user
......@@ -153,18 +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
}
## EE-only START
member.attributes = {
skip_notification: ldap,
set_member_attributes(
member,
access_level,
current_user: current_user,
expires_at: expires_at,
ldap: ldap
}
## EE-only END
)
if member.request?
::Members::ApproveAccessRequestService.new(
......@@ -183,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?
......@@ -425,3 +431,5 @@ class Member < ActiveRecord::Base
{}
end
end
Member.prepend(EE::Member)
# frozen_string_literal: true
module EE
module Member
extend ActiveSupport::Concern
attr_accessor :skip_notification
class_methods do
extend ::Gitlab::Utils::Override
override :set_member_attributes
def set_member_attributes(member, access_level, current_user: nil, expires_at: nil, ldap: false)
super
member.attributes = {
skip_notification: ldap,
ldap: ldap
}
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment