2018-08-03 13:22:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-14 12:32:51 -04:00
|
|
|
class GroupMember < Member
|
2017-02-21 18:32:18 -05:00
|
|
|
SOURCE_TYPE = 'Namespace'.freeze
|
2014-09-14 12:32:51 -04:00
|
|
|
|
2016-10-18 17:20:36 -04:00
|
|
|
belongs_to :group, foreign_key: 'source_id'
|
2014-09-14 13:38:57 -04:00
|
|
|
|
2017-01-24 16:09:58 -05:00
|
|
|
delegate :update_two_factor_requirement, to: :user
|
|
|
|
|
2014-09-14 12:32:51 -04:00
|
|
|
# Make sure group member points only to group as it source
|
|
|
|
default_value_for :source_type, SOURCE_TYPE
|
2017-02-21 19:40:04 -05:00
|
|
|
validates :source_type, format: { with: /\ANamespace\z/ }
|
2014-09-14 12:32:51 -04:00
|
|
|
default_scope { where(source_type: SOURCE_TYPE) }
|
|
|
|
|
2017-01-24 16:09:58 -05:00
|
|
|
after_create :update_two_factor_requirement, unless: :invite?
|
|
|
|
after_destroy :update_two_factor_requirement, unless: :invite?
|
|
|
|
|
2014-09-14 12:32:51 -04:00
|
|
|
def self.access_level_roles
|
|
|
|
Gitlab::Access.options_with_owner
|
|
|
|
end
|
|
|
|
|
2016-09-16 11:54:21 -04:00
|
|
|
def self.access_levels
|
|
|
|
Gitlab::Access.sym_options_with_owner
|
|
|
|
end
|
|
|
|
|
2014-09-14 12:32:51 -04:00
|
|
|
def group
|
|
|
|
source
|
|
|
|
end
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
# Because source_type is `Namespace`...
|
|
|
|
def real_source_type
|
|
|
|
'Group'
|
|
|
|
end
|
|
|
|
|
2017-08-04 16:56:33 -04:00
|
|
|
def notifiable_options
|
|
|
|
{ group: group }
|
2017-08-04 14:53:36 -04:00
|
|
|
end
|
|
|
|
|
2015-04-10 09:09:37 -04:00
|
|
|
private
|
|
|
|
|
2015-04-10 09:23:38 -04:00
|
|
|
def send_invite
|
2018-04-23 10:38:37 -04:00
|
|
|
run_after_commit_or_now { notification_service.invite_group_member(self, @raw_invite_token) }
|
2015-04-10 09:23:38 -04:00
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2014-08-21 06:53:32 -04:00
|
|
|
def post_create_hook
|
2018-04-23 10:38:37 -04:00
|
|
|
run_after_commit_or_now { notification_service.new_group_member(self) }
|
2015-04-10 09:09:37 -04:00
|
|
|
|
|
|
|
super
|
2014-09-14 12:32:51 -04:00
|
|
|
end
|
|
|
|
|
2015-04-10 09:09:37 -04:00
|
|
|
def post_update_hook
|
2014-09-14 12:32:51 -04:00
|
|
|
if access_level_changed?
|
2018-04-23 10:38:37 -04:00
|
|
|
run_after_commit { notification_service.update_group_member(self) }
|
2014-09-14 12:32:51 -04:00
|
|
|
end
|
2014-08-21 06:53:32 -04:00
|
|
|
|
2015-04-10 09:09:37 -04:00
|
|
|
super
|
2014-09-14 12:32:51 -04:00
|
|
|
end
|
2015-04-10 09:23:38 -04:00
|
|
|
|
|
|
|
def after_accept_invite
|
|
|
|
notification_service.accept_group_invite(self)
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
2015-04-10 10:37:02 -04:00
|
|
|
|
|
|
|
def after_decline_invite
|
|
|
|
notification_service.decline_group_invite(self)
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
2014-09-14 12:32:51 -04:00
|
|
|
end
|