debian-mirror-gitlab/app/controllers/projects/registry/repositories_controller.rb

68 lines
1.9 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
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
2018-03-17 18:26:18 +05:30
respond_to do |format|
format.html
format.json do
2020-03-13 15:44:24 +05:30
@images = project.container_repositories
track_event(:list_repositories)
serializer = ContainerRepositoriesSerializer
2018-03-17 18:26:18 +05:30
.new(project: project, current_user: current_user)
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
if Feature.enabled?(:vue_container_registry_explorer, project.group)
2020-03-13 15:44:24 +05:30
render json: serializer.with_pagination(request, response).represent(@images)
else
render json: serializer.represent(@images)
end
2018-03-17 18:26:18 +05:30
end
end
2017-08-17 22:00:37 +05:30
end
2020-03-13 15:44:24 +05:30
# The show action renders index to allow frontend routing to work on page refresh
def show
render :index
end
2017-08-17 22:00:37 +05:30
def destroy
2020-03-13 15:44:24 +05:30
DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id) # rubocop:disable CodeReuse/Worker
2019-12-21 20:55:43 +05:30
track_event(:delete_repository)
2018-11-20 20:47:30 +05:30
respond_to do |format|
format.json { head :no_content }
2017-08-17 22:00:37 +05:30
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!
2018-11-20 20:47:30 +05:30
::ContainerRegistry::Path.new(@project.full_path).tap do |path|
2017-08-17 22:00:37 +05:30
break if path.has_repository?
2018-11-20 20:47:30 +05:30
::ContainerRepository.build_from_path(path).tap do |repository|
2017-08-17 22:00:37 +05:30
repository.save! if repository.has_tags?
end
end
2019-09-30 21:07:59 +05:30
rescue ContainerRegistry::Path::InvalidRegistryPathError
@character_error = true
2017-08-17 22:00:37 +05:30
end
end
end
end