debian-mirror-gitlab/app/finders/container_repositories_finder.rb

39 lines
827 B
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
class ContainerRepositoriesFinder
2019-12-26 22:10:19 +05:30
VALID_SUBJECTS = [Group, Project].freeze
def initialize(user:, subject:)
@user = user
@subject = subject
2019-10-12 21:52:04 +05:30
end
def execute
2019-12-26 22:10:19 +05:30
raise ArgumentError, "invalid subject_type" unless valid_subject_type?
return unless authorized?
return project_repositories if @subject.is_a?(Project)
return group_repositories if @subject.is_a?(Group)
2019-10-12 21:52:04 +05:30
end
private
2019-12-26 22:10:19 +05:30
def valid_subject_type?
VALID_SUBJECTS.include?(@subject.class)
end
def project_repositories
return unless @subject.container_registry_enabled
2019-10-12 21:52:04 +05:30
2019-12-26 22:10:19 +05:30
@subject.container_repositories
2019-10-12 21:52:04 +05:30
end
2019-12-26 22:10:19 +05:30
def group_repositories
ContainerRepository.for_group_and_its_subgroups(@subject)
2019-10-12 21:52:04 +05:30
end
2019-12-26 22:10:19 +05:30
def authorized?
Ability.allowed?(@user, :read_container_image, @subject)
2019-10-12 21:52:04 +05:30
end
end