2019-10-30 11:14:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class GroupGroupLink < ApplicationRecord
|
|
|
|
include Expirable
|
|
|
|
|
|
|
|
belongs_to :shared_group, class_name: 'Group', foreign_key: :shared_group_id
|
|
|
|
belongs_to :shared_with_group, class_name: 'Group', foreign_key: :shared_with_group_id
|
|
|
|
|
|
|
|
validates :shared_group, presence: true
|
|
|
|
validates :shared_group_id, uniqueness: { scope: [:shared_with_group_id],
|
|
|
|
message: _('The group has already been shared with this group') }
|
|
|
|
validates :shared_with_group, presence: true
|
2020-02-02 19:09:03 -05:00
|
|
|
validates :group_access, inclusion: { in: Gitlab::Access.all_values },
|
2019-10-30 11:14:17 -04:00
|
|
|
presence: true
|
|
|
|
|
2020-04-09 14:09:34 -04:00
|
|
|
scope :non_guests, -> { where('group_access > ?', Gitlab::Access::GUEST) }
|
2022-01-16 19:14:49 -05:00
|
|
|
scope :preload_shared_with_groups, -> { preload(:shared_with_group) }
|
2020-04-09 14:09:34 -04:00
|
|
|
|
2019-10-30 11:14:17 -04:00
|
|
|
def self.access_options
|
2020-02-02 19:09:03 -05:00
|
|
|
Gitlab::Access.options_with_owner
|
2019-10-30 11:14:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.default_access
|
|
|
|
Gitlab::Access::DEVELOPER
|
|
|
|
end
|
2020-01-13 10:07:53 -05:00
|
|
|
|
|
|
|
def human_access
|
|
|
|
Gitlab::Access.human_access(self.group_access)
|
|
|
|
end
|
2019-10-30 11:14:17 -04:00
|
|
|
end
|