aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-24 17:49:20 +0800
committerGitHub <noreply@github.com>2021-11-24 17:49:20 +0800
commita666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch)
tree9ab1434b759a8a2cb275a83149903a823851e309 /routers/api/v1/repo
parent4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff)
downloadgitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz
gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip
Move user related model into models/user (#17781)
* Move user related model into models/user * Fix lint for windows * Fix windows lint * Fix windows lint * Move some tests in models * Merge
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r--routers/api/v1/repo/branch.go25
-rw-r--r--routers/api/v1/repo/collaborators.go13
-rw-r--r--routers/api/v1/repo/commits.go3
-rw-r--r--routers/api/v1/repo/fork.go3
-rw-r--r--routers/api/v1/repo/issue.go15
-rw-r--r--routers/api/v1/repo/issue_subscription.go5
-rw-r--r--routers/api/v1/repo/issue_tracked_time.go15
-rw-r--r--routers/api/v1/repo/migrate.go24
-rw-r--r--routers/api/v1/repo/pull.go17
-rw-r--r--routers/api/v1/repo/pull_review.go13
-rw-r--r--routers/api/v1/repo/repo.go44
-rw-r--r--routers/api/v1/repo/transfer.go7
12 files changed, 99 insertions, 85 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index 04da901239..70e5b3e2b8 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -11,6 +11,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
@@ -423,27 +424,27 @@ func CreateBranchProtection(ctx *context.APIContext) {
requiredApprovals = form.RequiredApprovals
}
- whitelistUsers, err := models.GetUserIDsByNames(form.PushWhitelistUsernames, false)
+ whitelistUsers, err := user_model.GetUserIDsByNames(form.PushWhitelistUsernames, false)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
return
}
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
return
}
- mergeWhitelistUsers, err := models.GetUserIDsByNames(form.MergeWhitelistUsernames, false)
+ mergeWhitelistUsers, err := user_model.GetUserIDsByNames(form.MergeWhitelistUsernames, false)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
return
}
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
return
}
- approvalsWhitelistUsers, err := models.GetUserIDsByNames(form.ApprovalsWhitelistUsernames, false)
+ approvalsWhitelistUsers, err := user_model.GetUserIDsByNames(form.ApprovalsWhitelistUsernames, false)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
return
}
@@ -653,9 +654,9 @@ func EditBranchProtection(ctx *context.APIContext) {
var whitelistUsers []int64
if form.PushWhitelistUsernames != nil {
- whitelistUsers, err = models.GetUserIDsByNames(form.PushWhitelistUsernames, false)
+ whitelistUsers, err = user_model.GetUserIDsByNames(form.PushWhitelistUsernames, false)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
return
}
@@ -667,9 +668,9 @@ func EditBranchProtection(ctx *context.APIContext) {
}
var mergeWhitelistUsers []int64
if form.MergeWhitelistUsernames != nil {
- mergeWhitelistUsers, err = models.GetUserIDsByNames(form.MergeWhitelistUsernames, false)
+ mergeWhitelistUsers, err = user_model.GetUserIDsByNames(form.MergeWhitelistUsernames, false)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
return
}
@@ -681,9 +682,9 @@ func EditBranchProtection(ctx *context.APIContext) {
}
var approvalsWhitelistUsers []int64
if form.ApprovalsWhitelistUsernames != nil {
- approvalsWhitelistUsers, err = models.GetUserIDsByNames(form.ApprovalsWhitelistUsernames, false)
+ approvalsWhitelistUsers, err = user_model.GetUserIDsByNames(form.ApprovalsWhitelistUsernames, false)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
return
}
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go
index d636220f62..fcc8f9a90f 100644
--- a/routers/api/v1/repo/collaborators.go
+++ b/routers/api/v1/repo/collaborators.go
@@ -10,6 +10,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -99,9 +100,9 @@ func IsCollaborator(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
- user, err := models.GetUserByName(ctx.Params(":collaborator"))
+ user, err := user_model.GetUserByName(ctx.Params(":collaborator"))
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -155,9 +156,9 @@ func AddCollaborator(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.AddCollaboratorOption)
- collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
+ collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator"))
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -214,9 +215,9 @@ func DeleteCollaborator(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
- collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
+ collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator"))
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go
index 639100757b..9907054b83 100644
--- a/routers/api/v1/repo/commits.go
+++ b/routers/api/v1/repo/commits.go
@@ -12,6 +12,7 @@ import (
"strconv"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
@@ -188,7 +189,7 @@ func GetAllCommits(ctx *context.APIContext) {
return
}
- userCache := make(map[string]*models.User)
+ userCache := make(map[string]*user_model.User)
apiCommits := make([]*api.Commit, len(commits))
for i, commit := range commits {
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index 45d3c815a7..528b8fdecc 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -10,6 +10,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -99,7 +100,7 @@ func CreateFork(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.CreateForkOption)
repo := ctx.Repo.Repository
- var forker *models.User // user/org that will own the fork
+ var forker *user_model.User // user/org that will own the fork
if form.Organization == nil {
forker = ctx.User
} else {
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index a2454b8618..5137c7246e 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
@@ -133,7 +134,7 @@ func SearchIssues(ctx *context.APIContext) {
Collaborate: util.OptionalBoolNone,
// This needs to be a column that is not nil in fixtures or
// MySQL will return different results when sorting by null in some cases
- OrderBy: models.SearchOrderByAlphabetically,
+ OrderBy: db.SearchOrderByAlphabetically,
Actor: ctx.User,
}
if ctx.IsSigned {
@@ -141,9 +142,9 @@ func SearchIssues(ctx *context.APIContext) {
opts.AllLimited = true
}
if ctx.FormString("owner") != "" {
- owner, err := models.GetUserByName(ctx.FormString("owner"))
+ owner, err := user_model.GetUserByName(ctx.FormString("owner"))
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusBadRequest, "Owner not found", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -492,8 +493,8 @@ func getUserIDForFilter(ctx *context.APIContext, queryName string) int64 {
return 0
}
- user, err := models.GetUserByName(userName)
- if models.IsErrUserNotExist(err) {
+ user, err := user_model.GetUserByName(userName)
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound(err)
return 0
}
@@ -604,7 +605,7 @@ func CreateIssue(ctx *context.APIContext) {
issue.MilestoneID = form.Milestone
assigneeIDs, err = models.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
} else {
ctx.Error(http.StatusInternalServerError, "AddAssigneeByName", err)
@@ -614,7 +615,7 @@ func CreateIssue(ctx *context.APIContext) {
// Check if the passed assignees is assignable
for _, aID := range assigneeIDs {
- assignee, err := models.GetUserByID(aID)
+ assignee, err := user_model.GetUserByID(aID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
return
diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go
index 8acd378cc5..09be3cc193 100644
--- a/routers/api/v1/repo/issue_subscription.go
+++ b/routers/api/v1/repo/issue_subscription.go
@@ -8,6 +8,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -114,9 +115,9 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
return
}
- user, err := models.GetUserByName(ctx.Params(":user"))
+ user, err := user_model.GetUserByName(ctx.Params(":user"))
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go
index f73e63547b..00f8e77feb 100644
--- a/routers/api/v1/repo/issue_tracked_time.go
+++ b/routers/api/v1/repo/issue_tracked_time.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -92,8 +93,8 @@ func ListTrackedTimes(ctx *context.APIContext) {
qUser := ctx.FormTrim("user")
if qUser != "" {
- user, err := models.GetUserByName(qUser)
- if models.IsErrUserNotExist(err) {
+ user, err := user_model.GetUserByName(qUser)
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusNotFound, "User does not exist", err)
} else if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -201,7 +202,7 @@ func AddTime(ctx *context.APIContext) {
if form.User != "" {
if (ctx.IsUserRepoAdmin() && ctx.User.Name != form.User) || ctx.User.IsAdmin {
//allow only RepoAdmin, Admin and User to add time
- user, err = models.GetUserByName(form.User)
+ user, err = user_model.GetUserByName(form.User)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
}
@@ -413,9 +414,9 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
return
}
- user, err := models.GetUserByName(ctx.Params(":timetrackingusername"))
+ user, err := user_model.GetUserByName(ctx.Params(":timetrackingusername"))
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -510,8 +511,8 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
// Filters
qUser := ctx.FormTrim("user")
if qUser != "" {
- user, err := models.GetUserByName(qUser)
- if models.IsErrUserNotExist(err) {
+ user, err := user_model.GetUserByName(qUser)
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusNotFound, "User does not exist", err)
} else if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go
index 767972ee98..bc594419f7 100644
--- a/routers/api/v1/repo/migrate.go
+++ b/routers/api/v1/repo/migrate.go
@@ -12,6 +12,8 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/graceful"
@@ -54,18 +56,18 @@ func Migrate(ctx *context.APIContext) {
//get repoOwner
var (
- repoOwner *models.User
+ repoOwner *user_model.User
err error
)
if len(form.RepoOwner) != 0 {
- repoOwner, err = models.GetUserByName(form.RepoOwner)
+ repoOwner, err = user_model.GetUserByName(form.RepoOwner)
} else if form.RepoOwnerID != 0 {
- repoOwner, err = models.GetUserByID(form.RepoOwnerID)
+ repoOwner, err = user_model.GetUserByID(form.RepoOwnerID)
} else {
repoOwner = ctx.User
}
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetUser", err)
@@ -208,7 +210,7 @@ func Migrate(ctx *context.APIContext) {
ctx.JSON(http.StatusCreated, convert.ToRepo(repo, models.AccessModeAdmin))
}
-func handleMigrateError(ctx *context.APIContext, repoOwner *models.User, remoteAddr string, err error) {
+func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, remoteAddr string, err error) {
switch {
case models.IsErrRepoAlreadyExist(err):
ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
@@ -220,12 +222,12 @@ func handleMigrateError(ctx *context.APIContext, repoOwner *models.User, remoteA
ctx.Error(http.StatusUnprocessableEntity, "", "Remote visit required two factors authentication.")
case models.IsErrReachLimitOfRepo(err):
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("You have already reached your limit of %d repositories.", repoOwner.MaxCreationLimit()))
- case models.IsErrNameReserved(err):
- ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' is reserved.", err.(models.ErrNameReserved).Name))
- case models.IsErrNameCharsNotAllowed(err):
- ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' contains invalid characters.", err.(models.ErrNameCharsNotAllowed).Name))
- case models.IsErrNamePatternNotAllowed(err):
- ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The pattern '%s' is not allowed in a username.", err.(models.ErrNamePatternNotAllowed).Pattern))
+ case db.IsErrNameReserved(err):
+ ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' is reserved.", err.(db.ErrNameReserved).Name))
+ case db.IsErrNameCharsNotAllowed(err):
+ ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' contains invalid characters.", err.(db.ErrNameCharsNotAllowed).Name))
+ case db.IsErrNamePatternNotAllowed(err):
+ ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The pattern '%s' is not allowed in a username.", err.(db.ErrNamePatternNotAllowed).Pattern))
case models.IsErrInvalidCloneAddr(err):
ctx.Error(http.StatusUnprocessableEntity, "", err)
case base.IsErrNotSupported(err):
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index efe72e1502..dd415a34af 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
@@ -382,7 +383,7 @@ func CreatePullRequest(ctx *context.APIContext) {
// Get all assignee IDs
assigneeIDs, err := models.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
} else {
ctx.Error(http.StatusInternalServerError, "AddAssigneeByName", err)
@@ -391,7 +392,7 @@ func CreatePullRequest(ctx *context.APIContext) {
}
// Check if the passed assignees is assignable
for _, aID := range assigneeIDs {
- assignee, err := models.GetUserByID(aID)
+ assignee, err := user_model.GetUserByID(aID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
return
@@ -522,7 +523,7 @@ func EditPullRequest(ctx *context.APIContext) {
if ctx.Repo.CanWrite(unit.TypePullRequests) && (form.Assignees != nil || len(form.Assignee) > 0) {
err = issue_service.UpdateAssignees(issue, form.Assignee, form.Assignees, ctx.User)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
} else {
ctx.Error(http.StatusInternalServerError, "UpdateAssignees", err)
@@ -900,7 +901,7 @@ func MergePullRequest(ctx *context.APIContext) {
ctx.Status(http.StatusOK)
}
-func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*models.User, *models.Repository, *git.Repository, *git.CompareInfo, string, string) {
+func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*user_model.User, *models.Repository, *git.Repository, *git.CompareInfo, string, string) {
baseRepo := ctx.Repo.Repository
// Get compared branches information
@@ -913,7 +914,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
baseBranch := form.Base
var (
- headUser *models.User
+ headUser *user_model.User
headBranch string
isSameRepo bool
err error
@@ -927,9 +928,9 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
headBranch = headInfos[0]
} else if len(headInfos) == 2 {
- headUser, err = models.GetUserByName(headInfos[0])
+ headUser, err = user_model.GetUserByName(headInfos[0])
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound("GetUserByName")
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -1209,7 +1210,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
totalNumberOfCommits := len(commits)
totalNumberOfPages := int(math.Ceil(float64(totalNumberOfCommits) / float64(listOptions.PageSize)))
- userCache := make(map[string]*models.User)
+ userCache := make(map[string]*user_model.User)
start, end := listOptions.GetStartEnd()
diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go
index 55b5178305..ec5f045647 100644
--- a/routers/api/v1/repo/pull_review.go
+++ b/routers/api/v1/repo/pull_review.go
@@ -10,6 +10,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
@@ -554,7 +555,7 @@ func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullR
return nil, nil, true
}
- if err := review.LoadAttributes(); err != nil && !models.IsErrUserNotExist(err) {
+ if err := review.LoadAttributes(); err != nil && !user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusInternalServerError, "ReviewLoadAttributes", err)
return nil, nil, true
}
@@ -659,7 +660,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
return
}
- reviewers := make([]*models.User, 0, len(opts.Reviewers))
+ reviewers := make([]*user_model.User, 0, len(opts.Reviewers))
permDoer, err := models.GetUserRepoPermission(pr.Issue.Repo, ctx.User)
if err != nil {
@@ -668,15 +669,15 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
}
for _, r := range opts.Reviewers {
- var reviewer *models.User
+ var reviewer *user_model.User
if strings.Contains(r, "@") {
- reviewer, err = models.GetUserByEmail(r)
+ reviewer, err = user_model.GetUserByEmail(r)
} else {
- reviewer, err = models.GetUserByName(r)
+ reviewer, err = user_model.GetUserByName(r)
}
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound("UserNotExist", fmt.Sprintf("User '%s' not exist", r))
return
}
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 872ce22871..a74e13d3ab 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -12,7 +12,9 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
unit_model "code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
@@ -26,20 +28,20 @@ import (
repo_service "code.gitea.io/gitea/services/repository"
)
-var searchOrderByMap = map[string]map[string]models.SearchOrderBy{
+var searchOrderByMap = map[string]map[string]db.SearchOrderBy{
"asc": {
- "alpha": models.SearchOrderByAlphabetically,
- "created": models.SearchOrderByOldest,
- "updated": models.SearchOrderByLeastUpdated,
- "size": models.SearchOrderBySize,
- "id": models.SearchOrderByID,
+ "alpha": db.SearchOrderByAlphabetically,
+ "created": db.SearchOrderByOldest,
+ "updated": db.SearchOrderByLeastUpdated,
+ "size": db.SearchOrderBySize,
+ "id": db.SearchOrderByID,
},
"desc": {
- "alpha": models.SearchOrderByAlphabeticallyReverse,
- "created": models.SearchOrderByNewest,
- "updated": models.SearchOrderByRecentUpdated,
- "size": models.SearchOrderBySizeReverse,
- "id": models.SearchOrderByIDReverse,
+ "alpha": db.SearchOrderByAlphabeticallyReverse,
+ "created": db.SearchOrderByNewest,
+ "updated": db.SearchOrderByRecentUpdated,
+ "size": db.SearchOrderBySizeReverse,
+ "id": db.SearchOrderByIDReverse,
},
}
@@ -239,7 +241,7 @@ func Search(ctx *context.APIContext) {
}
// CreateUserRepo create a repository for a user
-func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateRepoOption) {
+func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.CreateRepoOption) {
if opt.AutoInit && opt.Readme == "" {
opt.Readme = "Default"
}
@@ -259,8 +261,8 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
if err != nil {
if models.IsErrRepoAlreadyExist(err) {
ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
- } else if models.IsErrNameReserved(err) ||
- models.IsErrNamePatternNotAllowed(err) {
+ } else if db.IsErrNameReserved(err) ||
+ db.IsErrNamePatternNotAllowed(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "CreateRepository", err)
@@ -374,9 +376,9 @@ func Generate(ctx *context.APIContext) {
ctxUser := ctx.User
var err error
if form.Owner != ctxUser.Name {
- ctxUser, err = models.GetUserByName(form.Owner)
+ ctxUser, err = user_model.GetUserByName(form.Owner)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.JSON(http.StatusNotFound, map[string]interface{}{
"error": "request owner `" + form.Owner + "` does not exist",
})
@@ -408,8 +410,8 @@ func Generate(ctx *context.APIContext) {
if err != nil {
if models.IsErrRepoAlreadyExist(err) {
ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
- } else if models.IsErrNameReserved(err) ||
- models.IsErrNamePatternNotAllowed(err) {
+ } else if db.IsErrNameReserved(err) ||
+ db.IsErrNamePatternNotAllowed(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "CreateRepository", err)
@@ -648,10 +650,10 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
switch {
case models.IsErrRepoAlreadyExist(err):
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is already taken [name: %s]", newRepoName), err)
- case models.IsErrNameReserved(err):
+ case db.IsErrNameReserved(err):
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is reserved [name: %s]", newRepoName), err)
- case models.IsErrNamePatternNotAllowed(err):
- ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name's pattern is not allowed [name: %s, pattern: %s]", newRepoName, err.(models.ErrNamePatternNotAllowed).Pattern), err)
+ case db.IsErrNamePatternNotAllowed(err):
+ ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name's pattern is not allowed [name: %s, pattern: %s]", newRepoName, err.(db.ErrNamePatternNotAllowed).Pattern), err)
default:
ctx.Error(http.StatusUnprocessableEntity, "ChangeRepositoryName", err)
}
diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go
index f16e2bb081..b3913bcd34 100644
--- a/routers/api/v1/repo/transfer.go
+++ b/routers/api/v1/repo/transfer.go
@@ -9,6 +9,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/log"
@@ -53,9 +54,9 @@ func Transfer(ctx *context.APIContext) {
opts := web.GetForm(ctx).(*api.TransferRepoOption)
- newOwner, err := models.GetUserByName(opts.NewOwner)
+ newOwner, err := user_model.GetUserByName(opts.NewOwner)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
return
}
@@ -63,7 +64,7 @@ func Transfer(ctx *context.APIContext) {
return
}
- if newOwner.Type == models.UserTypeOrganization {
+ if newOwner.Type == user_model.UserTypeOrganization {
if !ctx.User.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) {
// The user shouldn't know about this organization
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")