From 00319e595ab52906d12ef027a10e08ac92ea1337 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 31 Mar 2017 13:56:07 +0200 Subject: [PATCH] Move code related to registry to multiple controllers --- .../registry/application_controller.rb | 8 ++++- .../registry/repositories_controller.rb | 36 +++---------------- .../projects/registry/tags_controller.rb | 20 +++++++++++ .../registry/repositories/_tag.html.haml | 9 +++-- config/routes/project.rb | 6 ++++ 5 files changed, 44 insertions(+), 35 deletions(-) diff --git a/app/controllers/projects/registry/application_controller.rb b/app/controllers/projects/registry/application_controller.rb index 8710c219553..a56f9c58726 100644 --- a/app/controllers/projects/registry/application_controller.rb +++ b/app/controllers/projects/registry/application_controller.rb @@ -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 diff --git a/app/controllers/projects/registry/repositories_controller.rb b/app/controllers/projects/registry/repositories_controller.rb index b953d5b3378..e3e30176b30 100644 --- a/app/controllers/projects/registry/repositories_controller.rb +++ b/app/controllers/projects/registry/repositories_controller.rb @@ -8,47 +8,19 @@ module Projects end def destroy - if tag - delete_tag + if image.destroy + redirect_to project_container_registry_path(@project) else - delete_image + redirect_to project_container_registry_path(@project), + alert: 'Failed to remove images repository!' 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 - else - redirect_to registry_url, alert: 'Failed to remove image' - 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 - 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 diff --git a/app/controllers/projects/registry/tags_controller.rb b/app/controllers/projects/registry/tags_controller.rb index e40489f67ad..8f0a1aff394 100644 --- a/app/controllers/projects/registry/tags_controller.rb +++ b/app/controllers/projects/registry/tags_controller.rb @@ -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 diff --git a/app/views/projects/registry/repositories/_tag.html.haml b/app/views/projects/registry/repositories/_tag.html.haml index f7161e85428..c9b3644ff93 100644 --- a/app/views/projects/registry/repositories/_tag.html.haml +++ b/app/views/projects/registry/repositories/_tag.html.haml @@ -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') diff --git a/config/routes/project.rb b/config/routes/project.rb index 34f4bd917f7..0269857f9fb 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -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