2014-10-09 11:22:20 -04:00
|
|
|
# == 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
|
|
|
|
# user_id :integer not null
|
|
|
|
# notification_level :integer not null
|
|
|
|
# type :string(255)
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
#
|
|
|
|
|
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
|
|
|
default_value_for :notification_level, Notification::N_GLOBAL
|
|
|
|
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) }
|
|
|
|
|
2014-08-21 06:53:32 -04:00
|
|
|
after_create :post_create_hook
|
2014-09-14 12:32:51 -04:00
|
|
|
after_update :notify_update
|
2014-08-21 06:53:32 -04:00
|
|
|
after_destroy :post_destroy_hook
|
2014-09-14 12:32:51 -04:00
|
|
|
|
|
|
|
def self.access_level_roles
|
|
|
|
Gitlab::Access.options_with_owner
|
|
|
|
end
|
|
|
|
|
|
|
|
def group
|
|
|
|
source
|
|
|
|
end
|
|
|
|
|
|
|
|
def access_field
|
|
|
|
access_level
|
|
|
|
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)
|
2014-08-21 06:53:32 -04:00
|
|
|
system_hook_service.execute_hooks_for(self, :create)
|
2014-09-14 12:32:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def notify_update
|
|
|
|
if access_level_changed?
|
|
|
|
notification_service.update_group_member(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-21 06:53:32 -04:00
|
|
|
def post_destroy_hook
|
|
|
|
system_hook_service.execute_hooks_for(self, :destroy)
|
|
|
|
end
|
|
|
|
|
|
|
|
def system_hook_service
|
|
|
|
SystemHooksService.new
|
|
|
|
end
|
|
|
|
|
2014-09-14 12:32:51 -04:00
|
|
|
def notification_service
|
|
|
|
NotificationService.new
|
|
|
|
end
|
|
|
|
end
|