summaryrefslogtreecommitdiffstats
path: root/services
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 /services
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 'services')
-rw-r--r--services/forms/org.go4
-rw-r--r--services/issue/assignee.go7
-rw-r--r--services/lfs/server.go3
-rw-r--r--services/mailer/mail_issue.go5
-rw-r--r--services/pull/check.go5
-rw-r--r--services/pull/merge.go9
-rw-r--r--services/pull/patch.go3
-rw-r--r--services/wiki/wiki.go3
8 files changed, 23 insertions, 16 deletions
diff --git a/services/forms/org.go b/services/forms/org.go
index 3b994770fd..7c8f17f95e 100644
--- a/services/forms/org.go
+++ b/services/forms/org.go
@@ -8,7 +8,7 @@ package forms
import (
"net/http"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web/middleware"
@@ -66,7 +66,7 @@ type CreateTeamForm struct {
TeamName string `binding:"Required;AlphaDashDot;MaxSize(30)"`
Description string `binding:"MaxSize(255)"`
Permission string
- Units []models.UnitType
+ Units []unit.Type
RepoAccess string
CanCreateOrgRepo bool
}
diff --git a/services/issue/assignee.go b/services/issue/assignee.go
index 12addede75..290a0041ff 100644
--- a/services/issue/assignee.go
+++ b/services/issue/assignee.go
@@ -6,6 +6,7 @@ package issue
import (
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
)
@@ -109,7 +110,7 @@ func IsValidReviewRequest(reviewer, doer *models.User, isAdd bool, issue *models
var pemResult bool
if isAdd {
- pemResult = permReviewer.CanAccessAny(models.AccessModeRead, models.UnitTypePullRequests)
+ pemResult = permReviewer.CanAccessAny(models.AccessModeRead, unit.TypePullRequests)
if !pemResult {
return models.ErrNotValidReviewRequest{
Reason: "Reviewer can't read",
@@ -122,7 +123,7 @@ func IsValidReviewRequest(reviewer, doer *models.User, isAdd bool, issue *models
return nil
}
- pemResult = permDoer.CanAccessAny(models.AccessModeWrite, models.UnitTypePullRequests)
+ pemResult = permDoer.CanAccessAny(models.AccessModeWrite, unit.TypePullRequests)
if !pemResult {
pemResult, err = models.IsOfficialReviewer(issue, doer)
if err != nil {
@@ -199,7 +200,7 @@ func IsValidTeamReviewRequest(reviewer *models.Team, doer *models.User, isAdd bo
}
}
- doerCanWrite := permission.CanAccessAny(models.AccessModeWrite, models.UnitTypePullRequests)
+ doerCanWrite := permission.CanAccessAny(models.AccessModeWrite, unit.TypePullRequests)
if !doerCanWrite {
official, err := models.IsOfficialReviewer(issue, doer)
if err != nil {
diff --git a/services/lfs/server.go b/services/lfs/server.go
index 946437fb27..5ce2a5498a 100644
--- a/services/lfs/server.go
+++ b/services/lfs/server.go
@@ -18,6 +18,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/json"
lfs_module "code.gitea.io/gitea/modules/lfs"
@@ -489,7 +490,7 @@ func authenticate(ctx *context.Context, repository *models.Repository, authoriza
return false
}
- canRead := perm.CanAccess(accessMode, models.UnitTypeCode)
+ canRead := perm.CanAccess(accessMode, unit.TypeCode)
if canRead && (!requireSigned || ctx.IsSigned) {
return true
}
diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go
index 6f401e5f92..6e63162713 100644
--- a/services/mailer/mail_issue.go
+++ b/services/mailer/mail_issue.go
@@ -8,6 +8,7 @@ import (
"fmt"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
@@ -114,9 +115,9 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*models.
}
func mailIssueCommentBatch(ctx *mailCommentContext, users []*models.User, visited map[int64]bool, fromMention bool) error {
- checkUnit := models.UnitTypeIssues
+ checkUnit := unit.TypeIssues
if ctx.Issue.IsPull {
- checkUnit = models.UnitTypePullRequests
+ checkUnit = unit.TypePullRequests
}
langMap := make(map[string][]*models.User)
diff --git a/services/pull/check.go b/services/pull/check.go
index c55b177e1c..1fb167ac21 100644
--- a/services/pull/check.go
+++ b/services/pull/check.go
@@ -13,6 +13,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
@@ -139,13 +140,13 @@ func manuallyMerged(pr *models.PullRequest) bool {
return false
}
- if unit, err := pr.BaseRepo.GetUnit(models.UnitTypePullRequests); err == nil {
+ if unit, err := pr.BaseRepo.GetUnit(unit.TypePullRequests); err == nil {
config := unit.PullRequestsConfig()
if !config.AutodetectManualMerge {
return false
}
} else {
- log.Error("PullRequest[%d].BaseRepo.GetUnit(models.UnitTypePullRequests): %v", pr.ID, err)
+ log.Error("PullRequest[%d].BaseRepo.GetUnit(unit.TypePullRequests): %v", pr.ID, err)
return false
}
diff --git a/services/pull/merge.go b/services/pull/merge.go
index 4d4a64e984..f59931e1bf 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -16,6 +16,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -38,9 +39,9 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
return fmt.Errorf("LoadBaseRepo: %v", err)
}
- prUnit, err := pr.BaseRepo.GetUnit(models.UnitTypePullRequests)
+ prUnit, err := pr.BaseRepo.GetUnit(unit.TypePullRequests)
if err != nil {
- log.Error("pr.BaseRepo.GetUnit(models.UnitTypePullRequests): %v", err)
+ log.Error("pr.BaseRepo.GetUnit(unit.TypePullRequests): %v", err)
return err
}
prConfig := prUnit.PullRequestsConfig()
@@ -565,7 +566,7 @@ func IsUserAllowedToMerge(pr *models.PullRequest, p models.Permission, user *mod
return false, err
}
- if (p.CanWrite(models.UnitTypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && pr.ProtectedBranch.IsUserMergeWhitelisted(user.ID, p)) {
+ if (p.CanWrite(unit.TypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && pr.ProtectedBranch.IsUserMergeWhitelisted(user.ID, p)) {
return true, nil
}
@@ -632,7 +633,7 @@ func CheckPRReadyToMerge(pr *models.PullRequest, skipProtectedFilesCheck bool) (
// MergedManually mark pr as merged manually
func MergedManually(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository, commitID string) (err error) {
- prUnit, err := pr.BaseRepo.GetUnit(models.UnitTypePullRequests)
+ prUnit, err := pr.BaseRepo.GetUnit(unit.TypePullRequests)
if err != nil {
return
}
diff --git a/services/pull/patch.go b/services/pull/patch.go
index 27d7991919..b971eb4bf3 100644
--- a/services/pull/patch.go
+++ b/services/pull/patch.go
@@ -14,6 +14,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
@@ -142,7 +143,7 @@ func checkConflicts(pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath
}
// 4. Now get the pull request configuration to check if we need to ignore whitespace
- prUnit, err := pr.BaseRepo.GetUnit(models.UnitTypePullRequests)
+ prUnit, err := pr.BaseRepo.GetUnit(unit.TypePullRequests)
if err != nil {
return false, err
}
diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go
index 5acb23ac78..944099de1f 100644
--- a/services/wiki/wiki.go
+++ b/services/wiki/wiki.go
@@ -12,6 +12,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -369,7 +370,7 @@ func DeleteWikiPage(doer *models.User, repo *models.Repository, wikiName string)
// DeleteWiki removes the actual and local copy of repository wiki.
func DeleteWiki(repo *models.Repository) error {
- if err := models.UpdateRepositoryUnits(repo, nil, []models.UnitType{models.UnitTypeWiki}); err != nil {
+ if err := models.UpdateRepositoryUnits(repo, nil, []unit.Type{unit.TypeWiki}); err != nil {
return err
}