Add button to revert commit on Commit detail page.

This commit is contained in:
Rubén Dávila 2016-02-03 16:11:59 -05:00 committed by Robert Speicher
parent 006089f972
commit 34e26b8212
4 changed files with 27 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"