BigW Consortium Gitlab

group_member.rb 1.74 KB
Newer Older
Valery Sizov committed
1 2 3 4 5 6 7 8
# == Schema Information
#
# Table name: members
#
#  id                 :integer          not null, primary key
#  access_level       :integer          not null
#  source_id          :integer          not null
#  source_type        :string(255)      not null
Stan Hu committed
9
#  user_id            :integer
Valery Sizov committed
10 11 12 13
#  notification_level :integer          not null
#  type               :string(255)
#  created_at         :datetime
#  updated_at         :datetime
Stan Hu committed
14 15 16 17
#  created_by_id      :integer
#  invite_email       :string(255)
#  invite_token       :string(255)
#  invite_accepted_at :datetime
Valery Sizov committed
18 19
#

20
class GroupMember < Member
21
  SOURCE_TYPE = 'Namespace'
22

23 24
  belongs_to :group, class_name: 'Group', foreign_key: 'source_id'

25 26
  # Make sure group member points only to group as it source
  default_value_for :source_type, SOURCE_TYPE
27 28
  default_value_for :notification_level, Notification::N_GLOBAL
  validates_format_of :source_type, with: /\ANamespace\z/
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
  default_scope { where(source_type: SOURCE_TYPE) }

  scope :with_group, ->(group) { where(source_id: group.id) }
  scope :with_user, ->(user) { where(user_id: user.id) }

  def self.access_level_roles
    Gitlab::Access.options_with_owner
  end

  def group
    source
  end

  def access_field
    access_level
  end

46 47
  private

48 49 50 51 52 53
  def send_invite
    notification_service.invite_group_member(self, @raw_invite_token)

    super
  end

54
  def post_create_hook
55
    notification_service.new_group_member(self)
56 57

    super
58 59
  end

60
  def post_update_hook
61 62 63
    if access_level_changed?
      notification_service.update_group_member(self)
    end
64

65
    super
66
  end
67 68 69 70 71 72

  def after_accept_invite
    notification_service.accept_group_invite(self)

    super
  end
Douwe Maan committed
73 74 75 76 77 78

  def after_decline_invite
    notification_service.decline_group_invite(self)

    super
  end
79
end