From ffe6cb57a64021dc593037ec18464fd728168ad1 Mon Sep 17 00:00:00 2001 From: Luke Picciau Date: Wed, 29 May 2019 20:18:40 +0000 Subject: Redirect to admin projects index if project was deleted from admin page --- app/controllers/admin/projects_controller.rb | 11 ++++++++++- app/views/admin/projects/_projects.html.haml | 4 ++-- config/routes/admin.rb | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index aeff0c96b64..70db15916b9 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -3,7 +3,7 @@ class Admin::ProjectsController < Admin::ApplicationController include MembersPresentation - before_action :project, only: [:show, :transfer, :repository_check] + before_action :project, only: [:show, :transfer, :repository_check, :destroy] before_action :group, only: [:show, :transfer] def index @@ -35,6 +35,15 @@ class Admin::ProjectsController < Admin::ApplicationController end # rubocop: enable CodeReuse/ActiveRecord + def destroy + ::Projects::DestroyService.new(@project, current_user, {}).async_execute + flash[:notice] = _("Project '%{project_name}' is in the process of being deleted.") % { project_name: @project.full_name } + + redirect_to admin_projects_path, status: :found + rescue Projects::DestroyService::DestroyError => ex + redirect_to admin_projects_path, status: 302, alert: ex.message + end + # rubocop: disable CodeReuse/ActiveRecord def transfer namespace = Namespace.find_by(id: params[:new_namespace_id]) diff --git a/app/views/admin/projects/_projects.html.haml b/app/views/admin/projects/_projects.html.haml index 9117f63f939..2f7ad35eb3e 100644 --- a/app/views/admin/projects/_projects.html.haml +++ b/app/views/admin/projects/_projects.html.haml @@ -7,7 +7,7 @@ = link_to 'Edit', edit_project_path(project), id: "edit_#{dom_id(project)}", class: "btn" %button.delete-project-button.btn.btn-danger{ data: { toggle: 'modal', target: '#delete-project-modal', - delete_project_url: project_path(project), + delete_project_url: admin_project_path(project), project_name: project.name }, type: 'button' } = s_('AdminProjects|Delete') @@ -17,7 +17,7 @@ - if project.archived %span.badge.badge-warning archived .title - = link_to(admin_namespace_project_path(project.namespace, project)) do + = link_to(admin_project_path(project)) do .dash-project-avatar .avatar-container.rect-avatar.s40 = project_icon(project, alt: '', class: 'avatar project-avatar s40', width: 40, height: 40) diff --git a/config/routes/admin.rb b/config/routes/admin.rb index bc19219a0b8..ae79beb1dba 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -83,7 +83,7 @@ namespace :admin do resources(:projects, path: '/', constraints: { id: Gitlab::PathRegex.project_route_regex }, - only: [:show]) do + only: [:show, :destroy]) do member do put :transfer -- cgit v1.2.1