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

4
5
  belongs_to :group, class_name: 'Group', foreign_key: 'source_id'

6
7
  # Make sure group member points only to group as it source
  default_value_for :source_type, SOURCE_TYPE
8
  validates_format_of :source_type, with: /\ANamespace\z/
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  default_scope { where(source_type: SOURCE_TYPE) }

  def self.access_level_roles
    Gitlab::Access.options_with_owner
  end

  def group
    source
  end

  def access_field
    access_level
  end

23
24
25
26
27
  # Because source_type is `Namespace`...
  def real_source_type
    'Group'
  end

Douwe Maan's avatar
Douwe Maan committed
28
29
  private

Douwe Maan's avatar
Douwe Maan committed
30
31
32
33
34
35
  def send_invite
    notification_service.invite_group_member(self, @raw_invite_token)

    super
  end

36
  def post_create_hook
37
    notification_service.new_group_member(self)
Douwe Maan's avatar
Douwe Maan committed
38
39

    super
40
41
  end

Douwe Maan's avatar
Douwe Maan committed
42
  def post_update_hook
43
44
45
    if access_level_changed?
      notification_service.update_group_member(self)
    end
46

Douwe Maan's avatar
Douwe Maan committed
47
    super
48
  end
Douwe Maan's avatar
Douwe Maan committed
49
50
51
52
53
54

  def after_accept_invite
    notification_service.accept_group_invite(self)

    super
  end
Douwe Maan's avatar
Douwe Maan committed
55
56
57
58
59
60

  def after_decline_invite
    notification_service.decline_group_invite(self)

    super
  end
61
end