BigW Consortium Gitlab

Commit 6c1af645 by Dmitriy Zaporozhets

Merge branch 'improve/edit_cancel' into 'master'

Better redirect for edit blobs from MergeRequest
parents 5d6e4bd2 a9280de1
......@@ -210,4 +210,8 @@ class ApplicationController < ActionController::Base
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email, :password, :login, :remember_me) }
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :name, :password, :password_confirmation) }
end
def hexdigest(string)
Digest::SHA1.hexdigest string
end
end
......@@ -2,6 +2,8 @@ class Projects::EditTreeController < Projects::BaseTreeController
before_filter :require_branch_head
before_filter :blob
before_filter :authorize_push!
before_filter :from_merge_request
before_filter :after_edit_path
def show
@last_commit = Gitlab::Git::Commit.last_for_path(@repository, @ref, @path).sha
......@@ -13,15 +15,11 @@ class Projects::EditTreeController < Projects::BaseTreeController
if result[:status] == :success
flash[:notice] = "Your changes have been successfully committed"
# If blob edit was initiated from merge request page
from_merge_request = MergeRequest.find_by(id: params[:from_merge_request_id])
if from_merge_request
from_merge_request.reload_code
redirect_to diffs_project_merge_request_path(from_merge_request.target_project, from_merge_request)
else
redirect_to project_blob_path(@project, @id)
end
redirect_to after_edit_path
else
flash[:alert] = result[:error]
render :show
......@@ -33,4 +31,19 @@ class Projects::EditTreeController < Projects::BaseTreeController
def blob
@blob ||= @repository.blob_at(@commit.id, @path)
end
def after_edit_path
@after_edit_path ||=
if from_merge_request
diffs_project_merge_request_path(from_merge_request.target_project, from_merge_request) +
"#file-path-#{hexdigest(@path)}"
else
project_blob_path(@project, @id)
end
end
def from_merge_request
# If blob edit was initiated from merge request page
@from_merge_request ||= MergeRequest.find_by(id: params[:from_merge_request_id])
end
end
......@@ -45,7 +45,7 @@
- file = project.repository.blob_at(@commit.parent_id, diff.old_path) unless file
- next unless file
.diff-file{id: "diff-#{i}"}
.diff-header
.diff-header{id: "file-path-#{hexdigest(diff.new_path || diff.old_path)}"}
- if diff.deleted_file
%span= diff.old_path
......
......@@ -11,7 +11,7 @@
%strong= @ref
%span.options
.btn-group.tree-btn-group
= link_to "Cancel", project_blob_path(@project, @id), class: "btn btn-tiny btn-cancel", data: { confirm: leave_edit_message }
= link_to "Cancel", @after_edit_path, class: "btn btn-tiny btn-cancel", data: { confirm: leave_edit_message }
.file-content.code
%pre#editor= @blob.data
......@@ -29,7 +29,7 @@
.message
to branch
%strong= @ref
= link_to "Cancel", project_blob_path(@project, @id), class: "btn btn-cancel", data: { confirm: leave_edit_message}
= link_to "Cancel", @after_edit_path, class: "btn btn-cancel", data: { confirm: leave_edit_message}
:javascript
ace.config.set("modePath", gon.relative_url_root + "#{Gitlab::Application.config.assets.prefix}/ace")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment