Skip to content

Commit f42198e

Browse files
brechtvlbartvdbraak
authored andcommitted
BLENDER: Edit file workflow for creating a fork and proposing changes
When viewing a file that the user can't edit because they can't write to the branch, the new, upload, patch, edit and delete functionality is no no longer disabled. If no user fork of the repository exists, there is now a page to create one. It will automatically create a fork with a single branch matching the one being viewed, and a unique repository name will be automatically picked. When a fork exists, but it's archived, a mirror or the user can't write code to it, there will instead be a missing explaining the situation. If the fork exists, a message will appear at the top of the edit page explaining that the changes will be applied to a branch in the fork. The base repository branch will be pushed to a new branch to the fork, and then the edits will be applied on top. The suggestion to fork happens when accessing /_edit/, so that for example online documentation can have an "edit this page" link to the base repository that does the right thing.
1 parent ddbef5f commit f42198e

35 files changed

+949
-237
lines changed

models/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ func (repo *Repository) AllowsPulls(ctx context.Context) bool {
653653

654654
// CanEnableEditor returns true if repository meets the requirements of web editor.
655655
func (repo *Repository) CanEnableEditor() bool {
656-
return !repo.IsMirror
656+
return !repo.IsMirror && !repo.IsArchived
657657
}
658658

659659
// DescriptionHTML does special handles to description and return HTML string.

options/locale/locale_en-US.ini

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,9 +1348,9 @@ editor.cannot_edit_non_text_files = Binary files cannot be edited in the web int
13481348
editor.edit_this_file = Edit File
13491349
editor.this_file_locked = File is locked
13501350
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file.
1351-
editor.fork_before_edit = You must fork this repository to make or propose changes to this file.
13521351
editor.delete_this_file = Delete File
13531352
editor.must_have_write_access = You must have write access to make or propose changes to this file.
1353+
editor.must_be_signed_in = You must be signed in to make or propose changes.
13541354
editor.file_delete_success = File "%s" has been deleted.
13551355
editor.name_your_file = Name your file…
13561356
editor.filename_help = Add a directory by typing its name followed by a slash ('/'). Remove a directory by typing backspace at the beginning of the input field.
@@ -1408,6 +1408,15 @@ editor.user_no_push_to_branch = User cannot push to branch
14081408
editor.require_signed_commit = Branch requires a signed commit
14091409
editor.cherry_pick = Cherry-pick %s onto:
14101410
editor.revert = Revert %s onto:
1411+
editor.fork_create = Fork Repository to Propose Changes
1412+
editor.fork_create_description = You can not edit this repository directly. Instead you can create a fork, make edits and create a pull request.
1413+
editor.fork_edit_description = You can not edit this repository directly. The changes will be written to your fork <b>%s</b>, so you can create a pull request.
1414+
editor.fork_failed_to_push_branch = Failed to push branch %s to your repoitory.
1415+
editor.cannot_find_editable_repo = Can not find repository to apply the edit to. Was it deleted while editing?
1416+
editor.fork_not_editable = Fork Repository Not Editable
1417+
editor.fork_is_archived = Your repository <b>%s</b> is archived. Unarchive it in repository settings to make changes.
1418+
editor.fork_code_disabled = Code is disabled in your repository <b>%s</b>. Enable code in repository settings to make changes.
1419+
editor.fork_no_permission = You do not have permission to write to repository <b>%s</b>.
14111420
14121421
commits.desc = Browse source code change history.
14131422
commits.commits = Commits

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ func reqRepoWriter(unitTypes ...unit.Type) func(ctx *context.APIContext) {
458458
// reqRepoBranchWriter user should have a permission to write to a branch, or be a site admin
459459
func reqRepoBranchWriter(ctx *context.APIContext) {
460460
options, ok := web.GetForm(ctx).(api.FileOptionInterface)
461-
if !ok || (!ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, options.Branch()) && !ctx.IsUserSiteAdmin()) {
461+
if !ok || (!context.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.Repository, options.Branch()) && !ctx.IsUserSiteAdmin()) {
462462
ctx.APIError(http.StatusForbidden, "user should have a permission to write to this branch")
463463
return
464464
}

routers/api/v1/repo/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func GetEditorconfig(ctx *context.APIContext) {
407407

408408
// canWriteFiles returns true if repository is editable and user has proper access level.
409409
func canWriteFiles(ctx *context.APIContext, branch string) bool {
410-
return ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, branch) &&
410+
return context.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.Repository, branch) &&
411411
!ctx.Repo.Repository.IsMirror &&
412412
!ctx.Repo.Repository.IsArchived
413413
}

routers/web/repo/cherry_pick.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ func CherryPick(ctx *context.Context) {
4747
ctx.Data["commit_message"] = splits[1]
4848
}
4949

50-
canCommit := renderCommitRights(ctx)
50+
canCommit := renderCommitRights(ctx, ctx.Repo.Repository)
5151
ctx.Data["TreePath"] = ""
5252

5353
if canCommit {
5454
ctx.Data["commit_choice"] = frmCommitChoiceDirect
5555
} else {
5656
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch
5757
}
58-
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
58+
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx, ctx.Repo.Repository)
5959
ctx.Data["last_commit"] = ctx.Repo.CommitID
6060
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
6161
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
@@ -75,7 +75,7 @@ func CherryPickPost(ctx *context.Context) {
7575
ctx.Data["CherryPickType"] = "cherry-pick"
7676
}
7777

78-
canCommit := renderCommitRights(ctx)
78+
canCommit := renderCommitRights(ctx, ctx.Repo.Repository)
7979
branchName := ctx.Repo.BranchName
8080
if form.CommitChoice == frmCommitChoiceNewBranch {
8181
branchName = form.NewBranchName

0 commit comments

Comments
 (0)