summaryrefslogtreecommitdiff
path: root/app/helpers/tree_helper.rb
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axilleas@axilleas.me>2015-12-25 01:31:02 +0200
committerAchilleas Pipinellis <axilleas@axilleas.me>2015-12-25 01:31:02 +0200
commitd18fd3f6489ad2a8065f8ddd80ca51100eb50b5e (patch)
tree1e809b9c4f694e20e9cc7dff06a9cb7f2f56aef2 /app/helpers/tree_helper.rb
parente74affcfa84acaddc236d6dfed7be1a61470dc0e (diff)
parent350d65503f0fa34ae397942578c5ea8b2a46a629 (diff)
downloadgitlab-ce-ci_triggers_docs.tar.gz
Merge branch 'master' into ci_triggers_docsci_triggers_docs
Diffstat (limited to 'app/helpers/tree_helper.rb')
-rw-r--r--app/helpers/tree_helper.rb41
1 files changed, 33 insertions, 8 deletions
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index f448dd0ab61..2ad7c80dae0 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -50,24 +50,49 @@ module TreeHelper
project.repository.branch_names.include?(ref)
end
- def allowed_tree_edit?(project = nil, ref = nil)
+ def can_edit_tree?(project = nil, ref = nil)
project ||= @project
ref ||= @ref
+
return false unless on_top_of_branch?(project, ref)
- can?(current_user, :push_code, project)
+ can?(current_user, :push_code, project) ||
+ (current_user && current_user.already_forked?(project))
end
def tree_edit_branch(project = @project, ref = @ref)
- if allowed_tree_edit?(project, ref)
- if can_push_branch?(project, ref)
- ref
- else
- project.repository.next_patch_branch
- end
+ return unless can_edit_tree?(project, ref)
+
+ if can_push_branch?(project, ref)
+ ref
+ else
+ project = tree_edit_project(project)
+ project.repository.next_patch_branch
+ end
+ end
+
+ def tree_edit_project(project = @project)
+ if can?(current_user, :push_code, project)
+ project
+ elsif current_user && current_user.already_forked?(project)
+ current_user.fork_of(project)
end
end
+ def edit_in_new_fork_notice_now
+ "You're not allowed to make changes to this project directly." +
+ " A fork of this project is being created that you can make changes in, so you can submit a merge request."
+ end
+
+ def edit_in_new_fork_notice
+ "You're not allowed to make changes to this project directly." +
+ " A fork of this project has been created that you can make changes in, so you can submit a merge request."
+ end
+
+ def commit_in_fork_help
+ "A new branch will be created in your fork and a new merge request will be started."
+ end
+
def tree_breadcrumbs(tree, max_links = 2)
if @path.present?
part_path = ""