summaryrefslogtreecommitdiff
path: root/app/controllers/projects/registry/repositories_controller.rb
blob: 89093e4172aed9a36c60b5ab8f67b76564158bc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module Projects
  module Registry
    class RepositoriesController < ::Projects::Registry::ApplicationController
      before_action :authorize_update_container_image!, only: [:destroy]
      before_action :ensure_root_container_repository!, only: [:index]

      def index
        @images = project.container_repositories

        respond_to do |format|
          format.html
          format.json do
           # render json: @images
            render json: [
              {
                name: 'gitlab-org/omnibus-gitlab/foo',
                tags_path: 'foo',
                destroy_path: 'bar',
                location: 'foo',
                id: '134',
                destroy_path: 'bar'
              },
              {
                name: 'gitlab-org/omnibus-gitlab',
                tags_path: 'foo',
                destroy_path: 'bar',
                location: 'foo',
                id: '123',
              },
              {
                name: 'gitlab-org/omnibus-gitlab/bar',
                tags_path: 'foo',
                destroy_path: 'bar',
                location: 'foo',
                id: '973',
              }
            ]
          end
        end
      end

      def destroy
        if image.destroy
          redirect_to project_container_registry_index_path(@project),
                      status: 302,
                      notice: 'Image repository has been removed successfully!'
        else
          redirect_to project_container_registry_index_path(@project),
                      status: 302,
                      alert: 'Failed to remove image repository!'
        end
      end

      private

      def image
        @image ||= project.container_repositories.find(params[:id])
      end

      ##
      # 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|
          break if path.has_repository?

          ContainerRepository.build_from_path(path).tap do |repository|
            repository.save! if repository.has_tags?
          end
        end
      end
    end
  end
end