2014-09-14 12:32:51 -04:00
|
|
|
class GroupMember < Member
|
2014-09-14 14:52:54 -04:00
|
|
|
SOURCE_TYPE = 'Namespace'
|
2014-09-14 12:32:51 -04:00
|
|
|
|
2014-09-14 13:38:57 -04:00
|
|
|
belongs_to :group, class_name: 'Group', foreign_key: 'source_id'
|
|
|
|
|
2014-09-14 12:32:51 -04:00
|
|
|
# Make sure group member points only to group as it source
|
|
|
|
default_value_for :source_type, SOURCE_TYPE
|
2014-09-14 14:52:54 -04:00
|
|
|
validates_format_of :source_type, with: /\ANamespace\z/
|
2014-09-14 12:32:51 -04:00
|
|
|
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
|
|
|
|
|
2015-04-10 09:09:37 -04:00
|
|
|
private
|
|
|
|
|
2015-04-10 09:23:38 -04:00
|
|
|
def send_invite
|
|
|
|
notification_service.invite_group_member(self, @raw_invite_token)
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2014-08-21 06:53:32 -04:00
|
|
|
def post_create_hook
|
2014-09-14 12:32:51 -04:00
|
|
|
notification_service.new_group_member(self)
|
2015-04-10 09:09:37 -04:00
|
|
|
|
|
|
|
super
|
2014-09-14 12:32:51 -04:00
|
|
|
end
|
|
|
|
|
2015-04-10 09:09:37 -04:00
|
|
|
def post_update_hook
|
2014-09-14 12:32:51 -04:00
|
|
|
if access_level_changed?
|
|
|
|
notification_service.update_group_member(self)
|
|
|
|
end
|
2014-08-21 06:53:32 -04:00
|
|
|
|
2015-04-10 09:09:37 -04:00
|
|
|
super
|
2014-09-14 12:32:51 -04:00
|
|
|
end
|
2015-04-10 09:23:38 -04:00
|
|
|
|
|
|
|
def after_accept_invite
|
|
|
|
notification_service.accept_group_invite(self)
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
2015-04-10 10:37:02 -04:00
|
|
|
|
|
|
|
def after_decline_invite
|
|
|
|
notification_service.decline_group_invite(self)
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
2014-09-14 12:32:51 -04:00
|
|
|
end
|