summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRubén Dávila <rdavila84@gmail.com>2016-02-03 16:11:59 -0500
committerRobert Speicher <rspeicher@gmail.com>2016-02-19 13:14:50 -0500
commit34e26b8212954dba32165c39b63858658b82c0f0 (patch)
treee1f1e5f8032c94911f6be26fd79a8d258b68070e
parent006089f97219825b2ec9406c0f2abfb3b67ca68f (diff)
downloadgitlab-ce-34e26b8212954dba32165c39b63858658b82c0f0.tar.gz
Add button to revert commit on Commit detail page.
-rw-r--r--app/controllers/projects/commit_controller.rb7
-rw-r--r--app/helpers/commits_helper.rb7
-rw-r--r--app/views/projects/commit/_commit_box.html.haml13
-rw-r--r--app/views/projects/commit/show.html.haml2
4 files changed, 27 insertions, 2 deletions
diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb
index 36951b91372..96cb9761f3b 100644
--- a/app/controllers/projects/commit_controller.rb
+++ b/app/controllers/projects/commit_controller.rb
@@ -2,6 +2,8 @@
#
# Not to be confused with CommitsController, plural.
class Projects::CommitController < Projects::ApplicationController
+ include CreatesCommit
+
# Authorize
before_action :require_non_empty_project
before_action :authorize_download_code!, except: [:cancel_builds, :retry_builds]
@@ -9,6 +11,7 @@ class Projects::CommitController < Projects::ApplicationController
before_action :authorize_read_commit_status!, only: [:builds]
before_action :commit
before_action :define_show_vars, only: [:show, :builds]
+ before_action :authorize_edit_tree!, only: [:revert]
def show
apply_diff_view_cookie!
@@ -55,6 +58,10 @@ class Projects::CommitController < Projects::ApplicationController
render layout: false
end
+ def revert
+
+ end
+
private
def commit
diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb
index 1d14ee52cfc..aeb4bcabc7d 100644
--- a/app/helpers/commits_helper.rb
+++ b/app/helpers/commits_helper.rb
@@ -123,6 +123,13 @@ module CommitsHelper
)
end
+ def can_collaborate_with_project?(project = nil)
+ project ||= @project
+
+ can?(current_user, :push_code, project) ||
+ (current_user && current_user.already_forked?(project))
+ end
+
protected
# Private: Returns a link to a person. If the person has a matching user and
diff --git a/app/views/projects/commit/_commit_box.html.haml b/app/views/projects/commit/_commit_box.html.haml
index f0414b38707..eab33e80c71 100644
--- a/app/views/projects/commit/_commit_box.html.haml
+++ b/app/views/projects/commit/_commit_box.html.haml
@@ -16,8 +16,17 @@
= link_to namespace_project_tree_path(@project.namespace, @project, @commit), class: "btn btn-grouped" do
= icon('files-o')
Browse Files
- = link_to '#modal-revert-commit', { 'data-target' => '#modal-revert-commit', 'data-toggle' => 'modal', class: 'btn btn-grouped'} do
- Revert
+ - if can_collaborate_with_project?
+ = link_to '#modal-revert-commit', { 'data-target' => '#modal-revert-commit', 'data-toggle' => 'modal', class: 'btn btn-grouped'} do
+ Revert
+ - else
+ - continue_params = { to: namespace_project_commit_path(@project.namespace, @project, @commit.id),
+ notice: edit_in_new_fork_notice,
+ notice_now: edit_in_new_fork_notice_now }
+ - fork_path = namespace_project_forks_path(@project.namespace, @project, namespace_key: current_user.namespace.id,
+ continue: continue_params)
+ = link_to fork_path, { class: 'btn btn-grouped', method: :post } do
+ Revert
%div
%p
diff --git a/app/views/projects/commit/show.html.haml b/app/views/projects/commit/show.html.haml
index 05dbe5ebea4..19101eec5b1 100644
--- a/app/views/projects/commit/show.html.haml
+++ b/app/views/projects/commit/show.html.haml
@@ -12,3 +12,5 @@
= render "projects/diffs/diffs", diffs: @diffs, project: @project,
diff_refs: @diff_refs
= render "projects/notes/notes_with_form"
+- if can_collaborate_with_project?
+ = render "projects/commit/revert"