BigW Consortium Gitlab

group_member.rb 1.32 KB
Newer Older
1
class GroupMember < Member
2
  SOURCE_TYPE = 'Namespace'.freeze
3

4
  belongs_to :group, foreign_key: 'source_id'
5

6 7
  delegate :update_two_factor_requirement, to: :user

8 9
  # Make sure group member points only to group as it source
  default_value_for :source_type, SOURCE_TYPE
Douwe Maan committed
10
  validates :source_type, format: { with: /\ANamespace\z/ }
11 12
  default_scope { where(source_type: SOURCE_TYPE) }

13 14 15
  after_create :update_two_factor_requirement, unless: :invite?
  after_destroy :update_two_factor_requirement, unless: :invite?

16 17 18 19
  def self.access_level_roles
    Gitlab::Access.options_with_owner
  end

20 21 22 23
  def self.access_levels
    Gitlab::Access.sym_options_with_owner
  end

24 25 26 27 28 29 30 31
  def group
    source
  end

  def access_field
    access_level
  end

32 33 34 35 36
  # Because source_type is `Namespace`...
  def real_source_type
    'Group'
  end

37 38
  private

39 40 41 42 43 44
  def send_invite
    notification_service.invite_group_member(self, @raw_invite_token)

    super
  end

45
  def post_create_hook
46
    notification_service.new_group_member(self)
47 48

    super
49 50
  end

51
  def post_update_hook
52 53 54
    if access_level_changed?
      notification_service.update_group_member(self)
    end
55

56
    super
57
  end
58 59 60 61 62 63

  def after_accept_invite
    notification_service.accept_group_invite(self)

    super
  end
Douwe Maan committed
64 65 66 67 68 69

  def after_decline_invite
    notification_service.decline_group_invite(self)

    super
  end
70
end