@@ -455,6 +455,28 @@ func reqRepoWriter(unitTypes ...unit.Type) func(ctx *context.APIContext) {
455455 }
456456}
457457
458+ // reqRepoCommitStatusWriter user should have a permission to write to commit
459+ // statuses, or write to a repo, or be a site admin
460+ func reqRepoCommitStatusWriter (unitTypes ... unit.Type ) func (ctx * context.APIContext ) {
461+ return func (ctx * context.APIContext ) {
462+ // TODO(not7cd)
463+ if ! ctx .IsUserRepoWriter (unitTypes ) && ! ctx .IsUserRepoAdmin () && ! ctx .IsUserSiteAdmin () {
464+ ctx .APIError (http .StatusForbidden , "user should have a permission to write to a repo" )
465+ return
466+ }
467+ }
468+ }
469+
470+ // TODO(not7cd): do I need this?
471+ // // reqRepoBranchWriter user should have a permission to write to a branch, or be a site admin
472+ // func reqRepoBranchWriter(ctx *context.APIContext) {
473+ // options, ok := web.GetForm(ctx).(api.FileOptionInterface)
474+ // if !ok || (!ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, options.Branch()) && !ctx.IsUserSiteAdmin()) {
475+ // ctx.APIError(http.StatusForbidden, "user should have a permission to write to this branch")
476+ // return
477+ // }
478+ // }
479+
458480// reqRepoReader user should have specific read permission or be a repo admin or a site admin
459481func reqRepoReader (unitType unit.Type ) func (ctx * context.APIContext ) {
460482 return func (ctx * context.APIContext ) {
@@ -465,6 +487,18 @@ func reqRepoReader(unitType unit.Type) func(ctx *context.APIContext) {
465487 }
466488}
467489
490+ // reqRepoReader user should have specific commit status read permission, or
491+ // repo read permission, or be a repo admin or a site admin
492+ func reqRepoCommitStatusReader (unitType unit.Type ) func (ctx * context.APIContext ) {
493+ return func (ctx * context.APIContext ) {
494+ // TODO(not7cd)
495+ if ! ctx .Repo .CanRead (unitType ) && ! ctx .IsUserRepoAdmin () && ! ctx .IsUserSiteAdmin () {
496+ ctx .APIError (http .StatusForbidden , "user should have specific read permission or be a repo admin or a site admin" )
497+ return
498+ }
499+ }
500+ }
501+
468502// reqAnyRepoReader user should have any permission to read repository or permissions of site admin
469503func reqAnyRepoReader () func (ctx * context.APIContext ) {
470504 return func (ctx * context.APIContext ) {
@@ -1399,8 +1433,8 @@ func Routes() *web.Router {
13991433 }, mustAllowPulls , reqRepoReader (unit .TypeCode ), context .ReferencesGitRepo ())
14001434 m .Group ("/statuses" , func () {
14011435 m .Combo ("/{sha}" ).Get (repo .GetCommitStatuses ).
1402- Post (reqToken (), reqRepoWriter (unit .TypeCommitStatus ), bind (api.CreateStatusOption {}), repo .NewCommitStatus )
1403- }, reqRepoWriter (unit .TypeCommitStatus ))
1436+ Post (reqToken (), reqRepoCommitStatusWriter (unit .TypeCode ), bind (api.CreateStatusOption {}), repo .NewCommitStatus )
1437+ }, reqRepoCommitStatusReader (unit .TypeCode ))
14041438 m .Group ("/commits" , func () {
14051439 m .Get ("" , context .ReferencesGitRepo (), repo .GetAllCommits )
14061440 m .Group ("/{ref}" , func () {
0 commit comments