Skip to content

Commit 8214177

Browse files
committed
Fix bug when a token is given public only
1 parent e530568 commit 8214177

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

routers/api/v1/api.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,21 @@ func reqRepoReader(unitType unit.Type) func(ctx *context.APIContext) {
407407
ctx.Error(http.StatusForbidden, "reqRepoReader", "user should have specific read permission or be a repo admin or a site admin")
408408
return
409409
}
410+
411+
if true == ctx.Data["IsApiToken"] {
412+
switch unitType {
413+
case unit.TypeCode:
414+
publicRepo, pubRepoExists := ctx.Data["ApiTokenScopePublicRepoOnly"]
415+
416+
if pubRepoExists && publicRepo.(bool) &&
417+
ctx.Repo.Repository != nil && ctx.Repo.Repository.IsPrivate {
418+
ctx.Error(http.StatusForbidden, "reqToken", "token scope is limited to public repos")
419+
return
420+
}
421+
422+
return
423+
}
424+
}
410425
}
411426
}
412427

0 commit comments

Comments
 (0)