BigW Consortium Gitlab

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

4
  belongs_to :group, foreign_key: 'source_id'
5

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

  def self.access_level_roles
    Gitlab::Access.options_with_owner
  end

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  def self.access_levels
    Gitlab::Access.sym_options_with_owner
  end

  def self.add_users_to_group(group, users, access_level, current_user: nil, expires_at: nil)
    self.transaction do
      add_users_to_source(
        group,
        users,
        access_level,
        current_user: current_user,
        expires_at: expires_at
      )
    end
  end

31 32 33 34 35 36 37 38
  def group
    source
  end

  def access_field
    access_level
  end

39 40 41 42 43
  # Because source_type is `Namespace`...
  def real_source_type
    'Group'
  end

44 45
  private

46 47 48 49 50 51
  def send_invite
    notification_service.invite_group_member(self, @raw_invite_token)

    super
  end

52
  def post_create_hook
53
    notification_service.new_group_member(self)
54 55

    super
56 57
  end

58
  def post_update_hook
59 60 61
    if access_level_changed?
      notification_service.update_group_member(self)
    end
62

63
    super
64
  end
65 66 67 68 69 70

  def after_accept_invite
    notification_service.accept_group_invite(self)

    super
  end
Douwe Maan committed
71 72 73 74 75 76

  def after_decline_invite
    notification_service.decline_group_invite(self)

    super
  end
77
end