2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class GroupMember < Member
|
2017-08-17 22:00:37 +05:30
|
|
|
SOURCE_TYPE = 'Namespace'.freeze
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
belongs_to :group, foreign_key: 'source_id'
|
|
|
|
|
|
|
|
delegate :update_two_factor_requirement, to: :user
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
# Make sure group member points only to group as it source
|
|
|
|
default_value_for :source_type, SOURCE_TYPE
|
2017-08-17 22:00:37 +05:30
|
|
|
validates :source_type, format: { with: /\ANamespace\z/ }
|
2015-04-26 12:48:37 +05:30
|
|
|
default_scope { where(source_type: SOURCE_TYPE) }
|
|
|
|
|
2019-01-03 12:48:30 +05:30
|
|
|
scope :in_groups, ->(groups) { where(source_id: groups.select(:id)) }
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
after_create :update_two_factor_requirement, unless: :invite?
|
|
|
|
after_destroy :update_two_factor_requirement, unless: :invite?
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def self.access_level_roles
|
|
|
|
Gitlab::Access.options_with_owner
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
def self.access_levels
|
|
|
|
Gitlab::Access.sym_options_with_owner
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def group
|
|
|
|
source
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
# Because source_type is `Namespace`...
|
|
|
|
def real_source_type
|
|
|
|
'Group'
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def notifiable_options
|
|
|
|
{ group: group }
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def send_invite
|
2018-10-15 14:42:47 +05:30
|
|
|
run_after_commit_or_now { notification_service.invite_group_member(self, @raw_invite_token) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def post_create_hook
|
2018-10-15 14:42:47 +05:30
|
|
|
run_after_commit_or_now { notification_service.new_group_member(self) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def post_update_hook
|
|
|
|
if access_level_changed?
|
2018-10-15 14:42:47 +05:30
|
|
|
run_after_commit { notification_service.update_group_member(self) }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_accept_invite
|
|
|
|
notification_service.accept_group_invite(self)
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_decline_invite
|
|
|
|
notification_service.decline_group_invite(self)
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|