summaryrefslogtreecommitdiffstats
path: root/modules
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 /modules
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 'modules')
-rw-r--r--modules/context/context.go13
-rw-r--r--modules/context/permission.go10
-rw-r--r--modules/context/repo.go33
-rw-r--r--modules/convert/convert.go3
-rw-r--r--modules/convert/repository.go13
-rw-r--r--modules/doctor/fix16961.go15
-rw-r--r--modules/notification/webhook/webhook.go5
7 files changed, 49 insertions, 43 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
}
}
diff --git a/modules/convert/convert.go b/modules/convert/convert.go
index 2960f7741a..9c5e2037c5 100644
--- a/modules/convert/convert.go
+++ b/modules/convert/convert.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/login"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs"
@@ -35,7 +36,7 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.
var hasPerm bool
var err error
if user != nil {
- hasPerm, err = models.HasAccessUnit(user, repo, models.UnitTypeCode, models.AccessModeWrite)
+ hasPerm, err = models.HasAccessUnit(user, repo, unit.TypeCode, models.AccessModeWrite)
if err != nil {
return nil, err
}
diff --git a/modules/convert/repository.go b/modules/convert/repository.go
index 7f3d67137f..bb8217908d 100644
--- a/modules/convert/repository.go
+++ b/modules/convert/repository.go
@@ -6,6 +6,7 @@ package convert
import (
"code.gitea.io/gitea/models"
+ unit_model "code.gitea.io/gitea/models/unit"
api "code.gitea.io/gitea/modules/structs"
)
@@ -37,7 +38,7 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool)
hasIssues := false
var externalTracker *api.ExternalTracker
var internalTracker *api.InternalTracker
- if unit, err := repo.GetUnit(models.UnitTypeIssues); err == nil {
+ if unit, err := repo.GetUnit(unit_model.TypeIssues); err == nil {
config := unit.IssuesConfig()
hasIssues = true
internalTracker = &api.InternalTracker{
@@ -45,7 +46,7 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool)
AllowOnlyContributorsToTrackTime: config.AllowOnlyContributorsToTrackTime,
EnableIssueDependencies: config.EnableDependencies,
}
- } else if unit, err := repo.GetUnit(models.UnitTypeExternalTracker); err == nil {
+ } else if unit, err := repo.GetUnit(unit_model.TypeExternalTracker); err == nil {
config := unit.ExternalTrackerConfig()
hasIssues = true
externalTracker = &api.ExternalTracker{
@@ -56,9 +57,9 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool)
}
hasWiki := false
var externalWiki *api.ExternalWiki
- if _, err := repo.GetUnit(models.UnitTypeWiki); err == nil {
+ if _, err := repo.GetUnit(unit_model.TypeWiki); err == nil {
hasWiki = true
- } else if unit, err := repo.GetUnit(models.UnitTypeExternalWiki); err == nil {
+ } else if unit, err := repo.GetUnit(unit_model.TypeExternalWiki); err == nil {
hasWiki = true
config := unit.ExternalWikiConfig()
externalWiki = &api.ExternalWiki{
@@ -72,7 +73,7 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool)
allowRebaseMerge := false
allowSquash := false
defaultMergeStyle := models.MergeStyleMerge
- if unit, err := repo.GetUnit(models.UnitTypePullRequests); err == nil {
+ if unit, err := repo.GetUnit(unit_model.TypePullRequests); err == nil {
config := unit.PullRequestsConfig()
hasPullRequests = true
ignoreWhitespaceConflicts = config.IgnoreWhitespaceConflicts
@@ -83,7 +84,7 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool)
defaultMergeStyle = config.GetDefaultMergeStyle()
}
hasProjects := false
- if _, err := repo.GetUnit(models.UnitTypeProjects); err == nil {
+ if _, err := repo.GetUnit(unit_model.TypeProjects); err == nil {
hasProjects = true
}
diff --git a/modules/doctor/fix16961.go b/modules/doctor/fix16961.go
index 60cc5ffe2f..e0e44b414b 100644
--- a/modules/doctor/fix16961.go
+++ b/modules/doctor/fix16961.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
"xorm.io/builder"
@@ -212,34 +213,34 @@ func fixBrokenRepoUnit16961(repoUnit *models.RepoUnit, bs []byte) (fixed bool, e
return false, nil
}
- switch models.UnitType(repoUnit.Type) {
- case models.UnitTypeCode, models.UnitTypeReleases, models.UnitTypeWiki, models.UnitTypeProjects:
+ switch unit.Type(repoUnit.Type) {
+ case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects:
cfg := &models.UnitConfig{}
repoUnit.Config = cfg
if fixed, err := fixUnitConfig16961(bs, cfg); !fixed {
return false, err
}
- case models.UnitTypeExternalWiki:
+ case unit.TypeExternalWiki:
cfg := &models.ExternalWikiConfig{}
repoUnit.Config = cfg
if fixed, err := fixExternalWikiConfig16961(bs, cfg); !fixed {
return false, err
}
- case models.UnitTypeExternalTracker:
+ case unit.TypeExternalTracker:
cfg := &models.ExternalTrackerConfig{}
repoUnit.Config = cfg
if fixed, err := fixExternalTrackerConfig16961(bs, cfg); !fixed {
return false, err
}
- case models.UnitTypePullRequests:
+ case unit.TypePullRequests:
cfg := &models.PullRequestsConfig{}
repoUnit.Config = cfg
if fixed, err := fixPullRequestsConfig16961(bs, cfg); !fixed {
return false, err
}
- case models.UnitTypeIssues:
+ case unit.TypeIssues:
cfg := &models.IssuesConfig{}
repoUnit.Config = cfg
if fixed, err := fixIssuesConfig16961(bs, cfg); !fixed {
@@ -256,7 +257,7 @@ func fixBrokenRepoUnits16961(logger log.Logger, autofix bool) error {
type RepoUnit struct {
ID int64
RepoID int64
- Type models.UnitType
+ Type unit.Type
Config []byte
CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"`
}
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go
index c767acf134..35f0cdc596 100644
--- a/modules/notification/webhook/webhook.go
+++ b/modules/notification/webhook/webhook.go
@@ -6,6 +6,7 @@ package webhook
import (
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -136,7 +137,7 @@ func (m *webhookNotifier) NotifyMigrateRepository(doer *models.User, u *models.U
func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
if issue.IsPull {
- mode, _ := models.AccessLevelUnit(doer, issue.Repo, models.UnitTypePullRequests)
+ mode, _ := models.AccessLevelUnit(doer, issue.Repo, unit.TypePullRequests)
if err := issue.LoadPullRequest(); err != nil {
log.Error("LoadPullRequest failed: %v", err)
@@ -160,7 +161,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *mo
return
}
} else {
- mode, _ := models.AccessLevelUnit(doer, issue.Repo, models.UnitTypeIssues)
+ mode, _ := models.AccessLevelUnit(doer, issue.Repo, unit.TypeIssues)
apiIssue := &api.IssuePayload{
Index: issue.Index,
Issue: convert.ToAPIIssue(issue),