Move unit into models/unit/ (#17576)

* Move unit into models/unit/

* Rename unit.UnitType as unit.Type
This commit is contained in:
Lunny Xiao 2021-11-10 03:57:58 +08:00 committed by GitHub
parent b6b1e71665
commit 99b2858e62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
68 changed files with 556 additions and 491 deletions

View file

@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
unit_model "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/charset"
@ -353,7 +354,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
}
// Check permission to add or upload new file.
if ctx.Repo.CanWrite(models.UnitTypeCode) && ctx.Repo.IsViewBranch {
if ctx.Repo.CanWrite(unit_model.TypeCode) && ctx.Repo.IsViewBranch {
ctx.Data["CanAddFile"] = !ctx.Repo.Repository.IsArchived
ctx.Data["CanUploadFile"] = setting.Repository.Upload.Enabled && !ctx.Repo.Repository.IsArchived
}
@ -514,7 +515,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}
} else if !ctx.Repo.IsViewBranch {
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
} else if !ctx.Repo.CanWrite(models.UnitTypeCode) {
} else if !ctx.Repo.CanWrite(unit_model.TypeCode) {
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit")
}
}
@ -563,7 +564,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}
} else if !ctx.Repo.IsViewBranch {
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
} else if !ctx.Repo.CanWrite(models.UnitTypeCode) {
} else if !ctx.Repo.CanWrite(unit_model.TypeCode) {
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_have_write_access")
}
}
@ -607,13 +608,13 @@ func checkHomeCodeViewable(ctx *context.Context) {
}
}
var firstUnit *models.Unit
var firstUnit *unit_model.Unit
for _, repoUnit := range ctx.Repo.Units {
if repoUnit.Type == models.UnitTypeCode {
if repoUnit.Type == unit_model.TypeCode {
return
}
unit, ok := models.Units[repoUnit.Type]
unit, ok := unit_model.Units[repoUnit.Type]
if ok && (firstUnit == nil || !firstUnit.IsLessThan(unit)) {
firstUnit = &unit
}