Resolve "In web editor, when delete a file, should navigate to enclosing directory"
This commit is contained in:
parent
9642a472b6
commit
4a372af80b
4 changed files with 93 additions and 5 deletions
|
@ -83,7 +83,7 @@ class Projects::BlobController < Projects::ApplicationController
|
|||
|
||||
def destroy
|
||||
create_commit(Files::DeleteService, success_notice: "The file has been successfully deleted.",
|
||||
success_path: -> { project_tree_path(@project, @branch_name) },
|
||||
success_path: -> { after_delete_path },
|
||||
failure_view: :show,
|
||||
failure_path: project_blob_path(@project, @id))
|
||||
end
|
||||
|
@ -191,6 +191,15 @@ class Projects::BlobController < Projects::ApplicationController
|
|||
end
|
||||
# rubocop: enable CodeReuse/ActiveRecord
|
||||
|
||||
def after_delete_path
|
||||
branch = BranchesFinder.new(@repository, search: @ref).execute.first
|
||||
if @repository.tree(branch.target, tree_path).entries.empty?
|
||||
project_tree_path(@project, @ref)
|
||||
else
|
||||
project_tree_path(@project, File.join(@ref, tree_path))
|
||||
end
|
||||
end
|
||||
|
||||
def editor_variables
|
||||
@branch_name = params[:branch_name]
|
||||
|
||||
|
@ -255,9 +264,6 @@ class Projects::BlobController < Projects::ApplicationController
|
|||
|
||||
def show_json
|
||||
set_last_commit_sha
|
||||
path_segments = @path.split('/')
|
||||
path_segments.pop
|
||||
tree_path = path_segments.join('/')
|
||||
|
||||
json = {
|
||||
id: @blob.id,
|
||||
|
@ -283,4 +289,8 @@ class Projects::BlobController < Projects::ApplicationController
|
|||
|
||||
render json: json
|
||||
end
|
||||
|
||||
def tree_path
|
||||
@path.rpartition('/').first
|
||||
end
|
||||
end
|
||||
|
|
6
changelogs/unreleased/37727-fix-file-delete-redirect.yml
Normal file
6
changelogs/unreleased/37727-fix-file-delete-redirect.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
title: On deletion of a file in sub directory in web IDE redirect to the sub directory
|
||||
instead of project root
|
||||
merge_request: 21465
|
||||
author: George Thomas @thegeorgeous
|
||||
type: changed
|
|
@ -343,4 +343,76 @@ describe Projects::BlobController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
let(:user) { create(:user) }
|
||||
let(:project_root_path) { project_tree_path(project, 'master') }
|
||||
|
||||
before do
|
||||
project.add_maintainer(user)
|
||||
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
context 'for a file in a subdirectory' do
|
||||
let(:default_params) do
|
||||
{
|
||||
namespace_id: project.namespace,
|
||||
project_id: project,
|
||||
id: 'master/files/whitespace',
|
||||
original_branch: 'master',
|
||||
branch_name: 'master',
|
||||
commit_message: 'Delete whitespace'
|
||||
}
|
||||
end
|
||||
|
||||
let(:after_delete_path) { project_tree_path(project, 'master/files') }
|
||||
|
||||
it 'redirects to the sub directory' do
|
||||
delete :destroy, default_params
|
||||
|
||||
expect(response).to redirect_to(after_delete_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'if deleted file is the last one in a subdirectory' do
|
||||
let(:default_params) do
|
||||
{
|
||||
namespace_id: project.namespace,
|
||||
project_id: project,
|
||||
id: 'master/bar/branch-test.txt',
|
||||
original_branch: 'master',
|
||||
branch_name: 'master',
|
||||
commit_message: 'Delete whitespace'
|
||||
}
|
||||
end
|
||||
|
||||
it 'redirects to the project root' do
|
||||
delete :destroy, default_params
|
||||
|
||||
expect(response).to redirect_to(project_root_path)
|
||||
end
|
||||
|
||||
context 'when deleting a file in a branch other than master' do
|
||||
let(:default_params) do
|
||||
{
|
||||
namespace_id: project.namespace,
|
||||
project_id: project,
|
||||
id: 'binary-encoding/foo/bar/.gitkeep',
|
||||
original_branch: 'binary-encoding',
|
||||
branch_name: 'binary-encoding',
|
||||
commit_message: 'Delete whitespace'
|
||||
}
|
||||
end
|
||||
|
||||
let(:after_delete_path) { project_tree_path(project, 'binary-encoding') }
|
||||
|
||||
it 'redirects to the project root of the branch' do
|
||||
delete :destroy, default_params
|
||||
|
||||
expect(response).to redirect_to(after_delete_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,7 +31,7 @@ describe 'Projects > Files > User deletes files', :js do
|
|||
fill_in(:commit_message, with: 'New commit message', visible: true)
|
||||
click_button('Delete file')
|
||||
|
||||
expect(current_path).to eq(project_tree_path(project, 'master'))
|
||||
expect(current_path).to eq(project_tree_path(project, 'master/'))
|
||||
expect(page).not_to have_content('.gitignore')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue