diff options
author | George Thomas <iamgeorgethomas@gmail.com> | 2018-10-17 10:27:58 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-10-17 10:27:58 +0000 |
commit | 4a372af80b455806db2521029998aaeeba36fc1e (patch) | |
tree | 658e7a5bfa5da27bc0e59576de4922325c18e074 /app/controllers/projects/blob_controller.rb | |
parent | 9642a472b67d46c230adf15ece8e79c850af99e4 (diff) | |
download | gitlab-ce-4a372af80b455806db2521029998aaeeba36fc1e.tar.gz |
Resolve "In web editor, when delete a file, should navigate to enclosing directory"
Diffstat (limited to 'app/controllers/projects/blob_controller.rb')
-rw-r--r-- | app/controllers/projects/blob_controller.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 92d26a13da9..fb2cfdedd9b 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -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 |