Skip to content

Commit b3582d0

Browse files
committed
rename the error name and add detection method
1 parent 070ff9b commit b3582d0

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

models/perm/access/repo_permission.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ import (
1818
"code.gitea.io/gitea/modules/util"
1919
)
2020

21-
type ErrNoPermission struct {
21+
type ErrPermissionDenied struct {
2222
RepoID int64
2323
Unit unit.Type
2424
Perm perm_model.AccessMode
2525
}
2626

27-
func (e ErrNoPermission) Error() string {
28-
return fmt.Sprintf("no permission to access repo %d unit %s with mode %s", e.RepoID, e.Unit.LogString(), e.Perm.LogString())
27+
func (e ErrPermissionDenied) Error() string {
28+
return fmt.Sprintf("permission denied to access repo %d unit %s with mode %s", e.RepoID, e.Unit.LogString(), e.Perm.LogString())
29+
}
30+
31+
func IsErrPermissionDenied(err error) bool {
32+
_, ok := err.(ErrPermissionDenied)
33+
return ok
2934
}
3035

3136
// Permission contains all the permissions related variables to a repository for a user

routers/web/repo/pull.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,10 +1436,10 @@ func CleanUpPullRequest(ctx *context.Context) {
14361436
}
14371437

14381438
if err := repo_service.CanDeleteBranch(ctx, pr.HeadRepo, pr.HeadBranch, ctx.Doer); err != nil {
1439-
if errors.Is(err, access_model.ErrNoPermission{}) {
1440-
ctx.NotFound("CleanUpPullRequest", nil)
1439+
if access_model.IsErrPermissionDenied(err) {
1440+
ctx.NotFound("CanDeleteBranch", nil)
14411441
} else {
1442-
ctx.ServerError("GetUserRepoPermission", err)
1442+
ctx.ServerError("CanDeleteBranch", err)
14431443
}
14441444
return
14451445
}

services/repository/branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func CanDeleteBranch(ctx context.Context, repo *repo_model.Repository, branchNam
476476
return err
477477
}
478478
if !perm.CanWrite(unit.TypeCode) {
479-
return access_model.ErrNoPermission{
479+
return access_model.ErrPermissionDenied{
480480
RepoID: repo.ID,
481481
Unit: unit.TypeCode,
482482
Perm: perm_model.AccessModeWrite,

0 commit comments

Comments
 (0)