summaryrefslogtreecommitdiffstats
path: root/modules/context
diff options
context:
space:
mode:
Diffstat (limited to 'modules/context')
-rw-r--r--modules/context/context.go13
-rw-r--r--modules/context/permission.go10
-rw-r--r--modules/context/repo.go33
3 files changed, 29 insertions, 27 deletions
diff --git a/modules/context/context.go b/modules/context/context.go
index f652d3845a..cb7131907e 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -21,6 +21,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/base"
mc "code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/json"
@@ -90,7 +91,7 @@ func (ctx *Context) IsUserRepoAdmin() bool {
}
// IsUserRepoWriter returns true if current user has write privilege in current repo
-func (ctx *Context) IsUserRepoWriter(unitTypes []models.UnitType) bool {
+func (ctx *Context) IsUserRepoWriter(unitTypes []unit.Type) bool {
for _, unitType := range unitTypes {
if ctx.Repo.CanWrite(unitType) {
return true
@@ -101,7 +102,7 @@ func (ctx *Context) IsUserRepoWriter(unitTypes []models.UnitType) bool {
}
// IsUserRepoReaderSpecific returns true if current user can read current repo's specific part
-func (ctx *Context) IsUserRepoReaderSpecific(unitType models.UnitType) bool {
+func (ctx *Context) IsUserRepoReaderSpecific(unitType unit.Type) bool {
return ctx.Repo.CanRead(unitType)
}
@@ -733,10 +734,10 @@ func Contexter() func(next http.Handler) http.Handler {
ctx.Data["ManifestData"] = setting.ManifestData
- ctx.Data["UnitWikiGlobalDisabled"] = models.UnitTypeWiki.UnitGlobalDisabled()
- ctx.Data["UnitIssuesGlobalDisabled"] = models.UnitTypeIssues.UnitGlobalDisabled()
- ctx.Data["UnitPullsGlobalDisabled"] = models.UnitTypePullRequests.UnitGlobalDisabled()
- ctx.Data["UnitProjectsGlobalDisabled"] = models.UnitTypeProjects.UnitGlobalDisabled()
+ ctx.Data["UnitWikiGlobalDisabled"] = unit.TypeWiki.UnitGlobalDisabled()
+ ctx.Data["UnitIssuesGlobalDisabled"] = unit.TypeIssues.UnitGlobalDisabled()
+ ctx.Data["UnitPullsGlobalDisabled"] = unit.TypePullRequests.UnitGlobalDisabled()
+ ctx.Data["UnitProjectsGlobalDisabled"] = unit.TypeProjects.UnitGlobalDisabled()
ctx.Data["i18n"] = locale
ctx.Data["Tr"] = i18n.Tr
diff --git a/modules/context/permission.go b/modules/context/permission.go
index b9cdf93de2..2b87aa4591 100644
--- a/modules/context/permission.go
+++ b/modules/context/permission.go
@@ -5,7 +5,7 @@
package context
import (
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/log"
)
@@ -20,7 +20,7 @@ func RequireRepoAdmin() func(ctx *Context) {
}
// RequireRepoWriter returns a middleware for requiring repository write to the specify unitType
-func RequireRepoWriter(unitType models.UnitType) func(ctx *Context) {
+func RequireRepoWriter(unitType unit.Type) func(ctx *Context) {
return func(ctx *Context) {
if !ctx.Repo.CanWrite(unitType) {
ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
@@ -30,7 +30,7 @@ func RequireRepoWriter(unitType models.UnitType) func(ctx *Context) {
}
// RequireRepoWriterOr returns a middleware for requiring repository write to one of the unit permission
-func RequireRepoWriterOr(unitTypes ...models.UnitType) func(ctx *Context) {
+func RequireRepoWriterOr(unitTypes ...unit.Type) func(ctx *Context) {
return func(ctx *Context) {
for _, unitType := range unitTypes {
if ctx.Repo.CanWrite(unitType) {
@@ -42,7 +42,7 @@ func RequireRepoWriterOr(unitTypes ...models.UnitType) func(ctx *Context) {
}
// RequireRepoReader returns a middleware for requiring repository read to the specify unitType
-func RequireRepoReader(unitType models.UnitType) func(ctx *Context) {
+func RequireRepoReader(unitType unit.Type) func(ctx *Context) {
return func(ctx *Context) {
if !ctx.Repo.CanRead(unitType) {
if log.IsTrace() {
@@ -68,7 +68,7 @@ func RequireRepoReader(unitType models.UnitType) func(ctx *Context) {
}
// RequireRepoReaderOr returns a middleware for requiring repository write to one of the unit permission
-func RequireRepoReaderOr(unitTypes ...models.UnitType) func(ctx *Context) {
+func RequireRepoReaderOr(unitTypes ...unit.Type) func(ctx *Context) {
return func(ctx *Context) {
for _, unitType := range unitTypes {
if ctx.Repo.CanRead(unitType) {
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 88f4d27658..d5763c78a3 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -14,6 +14,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ unit_model "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -72,12 +73,12 @@ type Repository struct {
// CanEnableEditor returns true if repository is editable and user has proper access level.
func (r *Repository) CanEnableEditor() bool {
- return r.Permission.CanWrite(models.UnitTypeCode) && r.Repository.CanEnableEditor() && r.IsViewBranch && !r.Repository.IsArchived
+ return r.Permission.CanWrite(unit_model.TypeCode) && r.Repository.CanEnableEditor() && r.IsViewBranch && !r.Repository.IsArchived
}
// CanCreateBranch returns true if repository is editable and user has proper access level.
func (r *Repository) CanCreateBranch() bool {
- return r.Permission.CanWrite(models.UnitTypeCode) && r.Repository.CanCreateBranch()
+ return r.Permission.CanWrite(unit_model.TypeCode) && r.Repository.CanCreateBranch()
}
// RepoMustNotBeArchived checks if a repo is archived
@@ -276,7 +277,7 @@ func RetrieveTemplateRepo(ctx *Context, repo *models.Repository) {
return
}
- if !perm.CanRead(models.UnitTypeCode) {
+ if !perm.CanRead(unit_model.TypeCode) {
repo.TemplateID = 0
}
}
@@ -461,7 +462,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
ctx.Data["RepoLink"] = ctx.Repo.RepoLink
ctx.Data["RepoRelPath"] = ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name
- unit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
+ unit, err := ctx.Repo.Repository.GetUnit(unit_model.TypeExternalTracker)
if err == nil {
ctx.Data["RepoExternalIssuesLink"] = unit.ExternalTrackerConfig().ExternalTrackerURL
}
@@ -485,9 +486,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner()
ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
ctx.Data["RepoOwnerIsOrganization"] = repo.Owner.IsOrganization()
- ctx.Data["CanWriteCode"] = ctx.Repo.CanWrite(models.UnitTypeCode)
- ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(models.UnitTypeIssues)
- ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(models.UnitTypePullRequests)
+ ctx.Data["CanWriteCode"] = ctx.Repo.CanWrite(unit_model.TypeCode)
+ ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(unit_model.TypeIssues)
+ ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(unit_model.TypePullRequests)
if ctx.Data["CanSignedUserFork"], err = ctx.Repo.Repository.CanUserFork(ctx.User); err != nil {
ctx.ServerError("CanUserFork", err)
@@ -577,7 +578,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
ctx.Data["CommitID"] = ctx.Repo.CommitID
// People who have push access or have forked repository can propose a new pull request.
- canPush := ctx.Repo.CanWrite(models.UnitTypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID))
+ canPush := ctx.Repo.CanWrite(unit_model.TypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID))
canCompare := false
// Pull request is allowed if this is a fork repository
@@ -897,14 +898,14 @@ func GitHookService() func(ctx *Context) {
// UnitTypes returns a middleware to set unit types to context variables.
func UnitTypes() func(ctx *Context) {
return func(ctx *Context) {
- ctx.Data["UnitTypeCode"] = models.UnitTypeCode
- ctx.Data["UnitTypeIssues"] = models.UnitTypeIssues
- ctx.Data["UnitTypePullRequests"] = models.UnitTypePullRequests
- ctx.Data["UnitTypeReleases"] = models.UnitTypeReleases
- ctx.Data["UnitTypeWiki"] = models.UnitTypeWiki
- ctx.Data["UnitTypeExternalWiki"] = models.UnitTypeExternalWiki
- ctx.Data["UnitTypeExternalTracker"] = models.UnitTypeExternalTracker
- ctx.Data["UnitTypeProjects"] = models.UnitTypeProjects
+ ctx.Data["UnitTypeCode"] = unit_model.TypeCode
+ ctx.Data["UnitTypeIssues"] = unit_model.TypeIssues
+ ctx.Data["UnitTypePullRequests"] = unit_model.TypePullRequests
+ ctx.Data["UnitTypeReleases"] = unit_model.TypeReleases
+ ctx.Data["UnitTypeWiki"] = unit_model.TypeWiki
+ ctx.Data["UnitTypeExternalWiki"] = unit_model.TypeExternalWiki
+ ctx.Data["UnitTypeExternalTracker"] = unit_model.TypeExternalTracker
+ ctx.Data["UnitTypeProjects"] = unit_model.TypeProjects
}
}