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

68 lines
2 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
2021-01-03 14:25:43 +05:30
include PackagesHelper
2017-08-17 22:00:37 +05:30
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-05-24 23:13:21 +05:30
@images = ContainerRepositoriesFinder.new(user: current_user, subject: project, params: params.slice(:name))
.execute
2020-03-13 15:44:24 +05:30
2021-01-03 14:25:43 +05:30
track_package_event(:list_repositories, :container)
2020-03-13 15:44:24 +05:30
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-22 19:07:51 +05:30
render json: serializer.with_pagination(request, response).represent(@images)
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-04-22 19:07:51 +05:30
image.delete_scheduled!
2020-03-13 15:44:24 +05:30
DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id) # rubocop:disable CodeReuse/Worker
2021-01-03 14:25:43 +05:30
track_package_event(:delete_repository, :container)
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