diff options
Diffstat (limited to 'app/models/group_group_link.rb')
-rw-r--r-- | app/models/group_group_link.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/group_group_link.rb b/app/models/group_group_link.rb index c4c3fc390e1..b0020f097b5 100644 --- a/app/models/group_group_link.rb +++ b/app/models/group_group_link.rb @@ -16,6 +16,19 @@ class GroupGroupLink < ApplicationRecord scope :non_guests, -> { where('group_access > ?', Gitlab::Access::GUEST) } scope :preload_shared_with_groups, -> { preload(:shared_with_group) } + scope :distinct_on_shared_with_group_id_with_group_access, -> do + distinct_group_links = select('DISTINCT ON (shared_with_group_id) *') + .order('shared_with_group_id, group_access DESC, expires_at DESC, created_at ASC') + + unscoped.from(distinct_group_links, :group_group_links) + end + + alias_method :shared_from, :shared_group + + def self.search(query) + joins(:shared_with_group).merge(Group.search(query)) + end + def self.access_options Gitlab::Access.options_with_owner end |