gitlab-org--gitlab-foss/app/models/members/group_member.rb

83 lines
1.8 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class GroupMember < Member
include FromUnion
include CreatedAtFilterable
SOURCE_TYPE = 'Namespace'
belongs_to :group, foreign_key: 'source_id'
2017-01-24 16:09:58 -05:00
delegate :update_two_factor_requirement, to: :user
# 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/ }
default_scope { where(source_type: SOURCE_TYPE) } # rubocop:disable Cop/DefaultScope
scope :of_groups, ->(groups) { where(source_id: groups.select(:id)) }
2019-07-17 22:09:30 -04:00
scope :of_ldap_type, -> { where(ldap: true) }
scope :count_users_by_group_id, -> { group(:source_id).count }
2017-01-24 16:09:58 -05:00
after_create :update_two_factor_requirement, unless: :invite?
after_destroy :update_two_factor_requirement, unless: :invite?
def self.access_level_roles
Gitlab::Access.options_with_owner
end
def self.access_levels
Gitlab::Access.sym_options_with_owner
end
def group
source
end
# Because source_type is `Namespace`...
def real_source_type
'Group'
end
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
run_after_commit_or_now { notification_service.invite_group_member(self, @raw_invite_token) }
2015-04-10 09:23:38 -04:00
super
end
def post_create_hook
run_after_commit_or_now { notification_service.new_group_member(self) }
2015-04-10 09:09:37 -04:00
super
end
2015-04-10 09:09:37 -04:00
def post_update_hook
if saved_change_to_access_level?
run_after_commit { notification_service.update_group_member(self) }
end
2015-04-10 09:09:37 -04:00
super
end
2015-04-10 09:23:38 -04:00
def after_accept_invite
notification_service.accept_group_invite(self)
update_two_factor_requirement
2015-04-10 09:23:38 -04:00
super
end
2015-04-10 10:37:02 -04:00
def after_decline_invite
notification_service.decline_group_invite(self)
super
end
end
GroupMember.prepend_if_ee('EE::GroupMember')