diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-12-24 12:24:57 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-12-24 12:24:57 +0000 |
commit | 76b7e24f855c99814fc09e286fb061b7aea3954c (patch) | |
tree | 498970380a63da563d29b24078bf293ce66a7658 /app/helpers/tree_helper.rb | |
parent | 84e75ebd4cd463cf5e0dea9c46e7bcef50b98f50 (diff) | |
parent | cfa716ebe0f149fd3f152d90c4dcf32ea450b486 (diff) | |
download | gitlab-ce-76b7e24f855c99814fc09e286fb061b7aea3954c.tar.gz |
Merge branch 'edit-on-fork' into 'master'
Automatically fork a project when not allowed to edit a file.
Fixes #3215.
To do:
- [ ] Add tests
-----
## "Edit" button on file in a project the user does NOT have write access to

## Clicking will automatically create a fork

## When the fork has been created, the user is returned to the edit page on the original project with a notice

## The user cannot change the target branch and is informed that editing will start an MR

## Hitting "Commit changes" will commit and start an MR from my fork to the origin project

-----
## "Create file, "Upload file" and "New directory" buttons in a project the user does NOT have write access to

## Clicking any of these options will automatically create a fork

## When the fork has been created, the user is returned to the tree page on the original project with a notice

## Clicking "New directory" again will show the modal. The user cannot change the target branch and is informed that editing will start an MR

## Hitting "Create directory" will commit and start an MR from my fork to the origin project

cc @dzaporozhets @skyruler
See merge request !2145
Diffstat (limited to 'app/helpers/tree_helper.rb')
-rw-r--r-- | app/helpers/tree_helper.rb | 41 |
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 = "" |