Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
4a372af8
Commit
4a372af8
authored
Oct 17, 2018
by
George Thomas
Committed by
Rémy Coutable
Oct 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "In web editor, when delete a file, should navigate to enclosing directory"
parent
9642a472
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
5 deletions
+93
-5
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+14
-4
changelogs/unreleased/37727-fix-file-delete-redirect.yml
changelogs/unreleased/37727-fix-file-delete-redirect.yml
+6
-0
spec/controllers/projects/blob_controller_spec.rb
spec/controllers/projects/blob_controller_spec.rb
+72
-0
spec/features/projects/files/user_deletes_files_spec.rb
spec/features/projects/files/user_deletes_files_spec.rb
+1
-1
No files found.
app/controllers/projects/blob_controller.rb
View file @
4a372af8
...
...
@@ -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
changelogs/unreleased/37727-fix-file-delete-redirect.yml
0 → 100644
View file @
4a372af8
---
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
spec/controllers/projects/blob_controller_spec.rb
View file @
4a372af8
...
...
@@ -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
spec/features/projects/files/user_deletes_files_spec.rb
View file @
4a372af8
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment