Commit 00319e59 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Move code related to registry to multiple controllers

parent f32d269c
......@@ -3,8 +3,14 @@ module Projects
class ApplicationController < Projects::ApplicationController
layout 'project'
before_action :verify_registry_enabled
before_action :verify_registry_enabled!
before_action :authorize_read_container_image!
private
def verify_registry_enabled!
render_404 unless Gitlab.config.registry.enabled
end
end
end
end
......@@ -8,47 +8,19 @@ module Projects
end
def destroy
if tag
delete_tag
else
delete_image
end
end
private
def registry_url
@registry_url ||= namespace_project_container_registry_index_path(project.namespace, project)
end
def verify_registry_enabled
render_404 unless Gitlab.config.registry.enabled
end
def delete_image
if image.destroy
redirect_to registry_url
redirect_to project_container_registry_path(@project)
else
redirect_to registry_url, alert: 'Failed to remove image'
redirect_to project_container_registry_path(@project),
alert: 'Failed to remove images repository!'
end
end
def delete_tag
if tag.delete
image.destroy if image.tags.empty?
redirect_to registry_url
else
redirect_to registry_url, alert: 'Failed to remove tag'
end
end
private
def image
@image ||= project.container_repositories.find_by(id: params[:id])
end
def tag
@tag ||= image.tag(params[:tag]) if params[:tag].present?
end
end
end
end
......@@ -2,6 +2,26 @@ module Projects
module Registry
class TagsController < ::Projects::Registry::ApplicationController
before_action :authorize_update_container_image!, only: [:destroy]
def destroy
if tag.delete
redirect_to project_container_registry_path(@project)
else
redirect_to project_container_registry_path(@project),
alert: 'Failed to remove repository tag!'
end
end
private
def repository
@image ||= project.container_repositories
.find_by(id: params[:repository_id])
end
def tag
@tag ||= repository.tag(params[:id]) if params[:id].present?
end
end
end
end
......@@ -25,5 +25,10 @@
- if can?(current_user, :update_container_image, @project)
%td.content
.controls.hidden-xs.pull-right
= link_to namespace_project_container_registry_path(@project.namespace, @project, { id: tag.repository.id, tag: tag.name} ), class: 'btn btn-remove has-tooltip', title: "Remove tag", data: { confirm: "Due to a Docker limitation, all tags with the same ID will also be deleted. Are you sure?" }, method: :delete do
= icon("trash cred")
- notice = 'Due to a Docker limitation, all tags with the same ID will also be deleted. Are you sure?'
= link_to namespace_project_registry_repository_tag_path(@project.namespace, @project, tag.repository, tag.name),
method: :delete,
class: 'btn btn-remove has-tooltip',
title: 'Remove image tag',
data: { confirm: notice } do
= icon('trash cred')
......@@ -224,6 +224,12 @@ constraints(ProjectUrlConstrainer.new) do
only: [:index, :destroy],
constraints: { id: Gitlab::Regex.container_registry_reference_regex }
namespace :registry do
resources :repository, only: [] do
resources :tags, only: [:destroy]
end
end
resources :milestones, constraints: { id: /\d+/ } do
member do
put :sort_issues
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment