Skip to content

Commit 6a9a833

Browse files
committed
check if the doer is a maintainer
1 parent 99d0510 commit 6a9a833

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
887887
}
888888

889889
if pull.HeadRepo != nil {
890-
ctx.Data["SourcePath"] = pull.HeadRepo.Link() + "/src/commit/" + endCommitID
890+
ctx.Data["SourcePath"] = pull.BaseRepo.Link() + "/src/commit/" + endCommitID
891891

892892
if !pull.HasMerged && ctx.Doer != nil {
893893
perm, err := access_model.GetUserRepoPermission(ctx, pull.HeadRepo, ctx.Doer)

services/context/permission.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ func RequireRepoWriterOr(unitTypes ...unit.Type) func(ctx *Context) {
5858
func RequireRepoReader(unitType unit.Type) func(ctx *Context) {
5959
return func(ctx *Context) {
6060
if !ctx.Repo.CanRead(unitType) {
61+
if unitType == unit.TypeCode && canWriteAsMaintainer(ctx) {
62+
return
63+
}
6164
if log.IsTrace() {
6265
if ctx.IsSigned {
6366
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+

services/context/repo.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
374374
return
375375
}
376376

377-
if !ctx.Repo.Permission.HasAnyUnitAccessOrEveryoneAccess() {
377+
if !canWriteAsMaintainer(ctx) && !ctx.Repo.Permission.HasAnyUnitAccessOrEveryoneAccess() {
378378
if ctx.FormString("go-get") == "1" {
379379
EarlyResponseForGoGetMeta(ctx)
380380
return
@@ -1048,3 +1048,11 @@ func GitHookService() func(ctx *Context) {
10481048
}
10491049
}
10501050
}
1051+
1052+
// canWriteAsMaintainer check if the doer can write to a branch as a maintainer
1053+
func canWriteAsMaintainer(ctx *Context) bool {
1054+
// There is no need to check if the branch exists.
1055+
// If the branch does not exist, CanMaintainerWriteToBranch will return false.
1056+
branchName := getRefNameFromPath(ctx.Repo, ctx.PathParam("*"), func(_ string) bool { return true })
1057+
return issues_model.CanMaintainerWriteToBranch(ctx, ctx.Repo.Permission, branchName, ctx.Doer)
1058+
}

0 commit comments

Comments
 (0)