BigW Consortium Gitlab

repositories_controller.rb 1.32 KB
Newer Older
1 2 3 4
module Projects
  module Registry
    class RepositoriesController < ::Projects::Registry::ApplicationController
      before_action :authorize_update_container_image!, only: [:destroy]
5
      before_action :ensure_root_container_repository!, only: [:index]
6 7 8 9 10 11 12

      def index
        @images = project.container_repositories
      end

      def destroy
        if image.destroy
13
          redirect_to project_container_registry_index_path(@project),
14
                      status: 302,
15
                      notice: 'Image repository has been removed successfully!'
16
        else
17
          redirect_to project_container_registry_index_path(@project),
18
                      status: 302,
19
                      alert: 'Failed to remove image repository!'
20 21 22
        end
      end

23
      private
24 25

      def image
26
        @image ||= project.container_repositories.find(params[:id])
27
      end
28 29 30 31 32 33 34 35

      ##
      # Container repository object for root project path.
      #
      # Needed to maintain a backwards compatibility.
      #
      def ensure_root_container_repository!
        ContainerRegistry::Path.new(@project.full_path).tap do |path|
36
          break if path.has_repository?
37 38

          ContainerRepository.build_from_path(path).tap do |repository|
39
            repository.save! if repository.has_tags?
40 41 42
          end
        end
      end
43 44 45
    end
  end
end