summaryrefslogtreecommitdiffstats
path: root/routers/private
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-10 03:57:58 +0800
committerGitHub <noreply@github.com>2021-11-09 20:57:58 +0100
commit99b2858e628d92bba252be72def409af77af735b (patch)
tree56159cf10b271307911e6f01626c0c3efba789ab /routers/private
parentb6b1e716654fec3b16d245ef65cf42e57e1bb5b6 (diff)
downloadgitea-99b2858e628d92bba252be72def409af77af735b.tar.gz
gitea-99b2858e628d92bba252be72def409af77af735b.zip
Move unit into models/unit/ (#17576)
* Move unit into models/unit/ * Rename unit.UnitType as unit.Type
Diffstat (limited to 'routers/private')
-rw-r--r--routers/private/hook_pre_receive.go5
-rw-r--r--routers/private/serv.go9
2 files changed, 8 insertions, 6 deletions
diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go
index 3e4995376c..04c334b38f 100644
--- a/routers/private/hook_pre_receive.go
+++ b/routers/private/hook_pre_receive.go
@@ -12,6 +12,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
gitea_context "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -58,7 +59,7 @@ func (ctx *preReceiveContext) Perm() *models.Permission {
// CanWriteCode returns true if can write code
func (ctx *preReceiveContext) CanWriteCode() bool {
if !ctx.checkedCanWriteCode {
- ctx.canWriteCode = ctx.Perm().CanWrite(models.UnitTypeCode)
+ ctx.canWriteCode = ctx.Perm().CanWrite(unit.TypeCode)
ctx.checkedCanWriteCode = true
}
return ctx.canWriteCode
@@ -81,7 +82,7 @@ func (ctx *preReceiveContext) AssertCanWriteCode() bool {
// CanCreatePullRequest returns true if can create pull requests
func (ctx *preReceiveContext) CanCreatePullRequest() bool {
if !ctx.checkedCanCreatePullRequest {
- ctx.canCreatePullRequest = ctx.Perm().CanRead(models.UnitTypePullRequests)
+ ctx.canCreatePullRequest = ctx.Perm().CanRead(unit.TypePullRequests)
ctx.checkedCanCreatePullRequest = true
}
return ctx.canCreatePullRequest
diff --git a/routers/private/serv.go b/routers/private/serv.go
index b3edd7fc24..a7ef980d2d 100644
--- a/routers/private/serv.go
+++ b/routers/private/serv.go
@@ -11,6 +11,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -93,12 +94,12 @@ func ServCommand(ctx *context.PrivateContext) {
}
// The default unit we're trying to look at is code
- unitType := models.UnitTypeCode
+ unitType := unit.TypeCode
// Unless we're a wiki...
if strings.HasSuffix(repoName, ".wiki") {
// in which case we need to look at the wiki
- unitType = models.UnitTypeWiki
+ unitType = unit.TypeWiki
// And we'd better munge the reponame and tell downstream we're looking at a wiki
results.IsWiki = true
results.RepoName = repoName[:len(repoName)-5]
@@ -295,7 +296,7 @@ func ServCommand(ctx *context.PrivateContext) {
}
} else {
// Because of the special ref "refs/for" we will need to delay write permission check
- if git.SupportProcReceive && unitType == models.UnitTypeCode {
+ if git.SupportProcReceive && unitType == unit.TypeCode {
mode = models.AccessModeRead
}
@@ -362,7 +363,7 @@ func ServCommand(ctx *context.PrivateContext) {
if results.IsWiki {
// Ensure the wiki is enabled before we allow access to it
- if _, err := repo.GetUnit(models.UnitTypeWiki); err != nil {
+ if _, err := repo.GetUnit(unit.TypeWiki); err != nil {
if models.IsErrUnitTypeNotExist(err) {
ctx.JSON(http.StatusForbidden, private.ErrServCommand{
Results: results,