diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-04 18:07:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-04 18:07:36 +0300 |
commit | aa542224bb345acf0cb9a1a606f0a802c16b0336 (patch) | |
tree | 496540a29aec55c6faeec7b0140824547046ae6c /app/finders | |
parent | 2494b608a460c46c759ad84bb29e6cc3447499a1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/container_repositories_finder.rb | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/app/finders/container_repositories_finder.rb b/app/finders/container_repositories_finder.rb index eb91d7f825b..34921df840b 100644 --- a/app/finders/container_repositories_finder.rb +++ b/app/finders/container_repositories_finder.rb @@ -1,34 +1,38 @@ # frozen_string_literal: true class ContainerRepositoriesFinder - # id: group or project id - # container_type: :group or :project - def initialize(id:, container_type:) - @id = id - @type = container_type.to_sym + VALID_SUBJECTS = [Group, Project].freeze + + def initialize(user:, subject:) + @user = user + @subject = subject end def execute - if project_type? - project.container_repositories - else - group.container_repositories - end + 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) end private - attr_reader :id, :type + def valid_subject_type? + VALID_SUBJECTS.include?(@subject.class) + end + + def project_repositories + return unless @subject.container_registry_enabled - def project_type? - type == :project + @subject.container_repositories end - def project - Project.find(id) + def group_repositories + ContainerRepository.for_group_and_its_subgroups(@subject) end - def group - Group.find(id) + def authorized? + Ability.allowed?(@user, :read_container_image, @subject) end end |