2019-12-26 22:10:19 +05:30
|
|
|
# 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-03-13 15:44:24 +05:30
|
|
|
validates :group_access, inclusion: { in: Gitlab::Access.all_values },
|
2019-12-26 22:10:19 +05:30
|
|
|
presence: true
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
scope :non_guests, -> { where('group_access > ?', Gitlab::Access::GUEST) }
|
2020-06-23 00:09:42 +05:30
|
|
|
scope :public_or_visible_to_user, ->(group, user) { where(shared_group: group, shared_with_group: Group.public_or_visible_to_user(user)) } # rubocop:disable Cop/GroupPublicOrVisibleToUser
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
def self.access_options
|
2020-03-13 15:44:24 +05:30
|
|
|
Gitlab::Access.options_with_owner
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def self.default_access
|
|
|
|
Gitlab::Access::DEVELOPER
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
def human_access
|
|
|
|
Gitlab::Access.human_access(self.group_access)
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|