summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
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
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')
-rw-r--r--routers/api/v1/admin/adopt.go9
-rw-r--r--routers/api/v1/admin/org.go18
-rw-r--r--routers/api/v1/admin/user.go29
-rw-r--r--routers/api/v1/api.go10
-rw-r--r--routers/api/v1/org/org.go25
-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
-rw-r--r--routers/api/v1/user/follower.go13
-rw-r--r--routers/api/v1/user/helper.go9
-rw-r--r--routers/api/v1/user/key.go7
-rw-r--r--routers/api/v1/user/repo.go3
-rw-r--r--routers/api/v1/user/settings.go4
-rw-r--r--routers/api/v1/user/star.go3
-rw-r--r--routers/api/v1/user/user.go7
-rw-r--r--routers/api/v1/user/watch.go3
25 files changed, 173 insertions, 151 deletions
diff --git a/routers/api/v1/admin/adopt.go b/routers/api/v1/admin/adopt.go
index 184a2941a8..85262bc836 100644
--- a/routers/api/v1/admin/adopt.go
+++ b/routers/api/v1/admin/adopt.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/util"
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -79,9 +80,9 @@ func AdoptRepository(ctx *context.APIContext) {
ownerName := ctx.Params(":username")
repoName := ctx.Params(":reponame")
- ctxUser, err := models.GetUserByName(ownerName)
+ ctxUser, err := user_model.GetUserByName(ownerName)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound()
return
}
@@ -141,9 +142,9 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
ownerName := ctx.Params(":username")
repoName := ctx.Params(":reponame")
- ctxUser, err := models.GetUserByName(ownerName)
+ ctxUser, err := user_model.GetUserByName(ownerName)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound()
return
}
diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go
index 2633865d2c..bdfe87fd4e 100644
--- a/routers/api/v1/admin/org.go
+++ b/routers/api/v1/admin/org.go
@@ -9,6 +9,8 @@ import (
"net/http"
"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"
api "code.gitea.io/gitea/modules/structs"
@@ -61,15 +63,15 @@ func CreateOrg(ctx *context.APIContext) {
Website: form.Website,
Location: form.Location,
IsActive: true,
- Type: models.UserTypeOrganization,
+ Type: user_model.UserTypeOrganization,
Visibility: visibility,
}
if err := models.CreateOrganization(org, u); err != nil {
- if models.IsErrUserAlreadyExist(err) ||
- models.IsErrNameReserved(err) ||
- models.IsErrNameCharsNotAllowed(err) ||
- models.IsErrNamePatternNotAllowed(err) {
+ if user_model.IsErrUserAlreadyExist(err) ||
+ db.IsErrNameReserved(err) ||
+ db.IsErrNameCharsNotAllowed(err) ||
+ db.IsErrNamePatternNotAllowed(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "CreateOrganization", err)
@@ -104,10 +106,10 @@ func GetAllOrgs(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- users, maxResults, err := models.SearchUsers(&models.SearchUserOptions{
+ users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
Actor: ctx.User,
- Type: models.UserTypeOrganization,
- OrderBy: models.SearchOrderByAlphabetically,
+ Type: user_model.UserTypeOrganization,
+ OrderBy: db.SearchOrderByAlphabetically,
ListOptions: listOptions,
Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate},
})
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index 95060e7a1c..e50abb5937 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -11,6 +11,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/login"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
@@ -25,7 +26,7 @@ import (
user_service "code.gitea.io/gitea/services/user"
)
-func parseLoginSource(ctx *context.APIContext, u *models.User, sourceID int64, loginName string) {
+func parseLoginSource(ctx *context.APIContext, u *user_model.User, sourceID int64, loginName string) {
if sourceID == 0 {
return
}
@@ -70,7 +71,7 @@ func CreateUser(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateUserOption)
- u := &models.User{
+ u := &user_model.User{
Name: form.Username,
FullName: form.FullName,
Email: form.Email,
@@ -102,20 +103,20 @@ func CreateUser(ctx *context.APIContext) {
return
}
- var overwriteDefault *models.CreateUserOverwriteOptions
+ var overwriteDefault *user_model.CreateUserOverwriteOptions
if form.Visibility != "" {
- overwriteDefault = &models.CreateUserOverwriteOptions{
+ overwriteDefault = &user_model.CreateUserOverwriteOptions{
Visibility: api.VisibilityModes[form.Visibility],
}
}
- if err := models.CreateUser(u, overwriteDefault); err != nil {
- if models.IsErrUserAlreadyExist(err) ||
+ if err := user_model.CreateUser(u, overwriteDefault); err != nil {
+ if user_model.IsErrUserAlreadyExist(err) ||
user_model.IsErrEmailAlreadyUsed(err) ||
- models.IsErrNameReserved(err) ||
- models.IsErrNameCharsNotAllowed(err) ||
+ db.IsErrNameReserved(err) ||
+ db.IsErrNameCharsNotAllowed(err) ||
user_model.IsErrEmailInvalid(err) ||
- models.IsErrNamePatternNotAllowed(err) {
+ db.IsErrNamePatternNotAllowed(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "CreateUser", err)
@@ -183,7 +184,7 @@ func EditUser(ctx *context.APIContext) {
ctx.Error(http.StatusBadRequest, "PasswordPwned", errors.New("PasswordPwned"))
return
}
- if u.Salt, err = models.GetUserSalt(); err != nil {
+ if u.Salt, err = user_model.GetUserSalt(); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateUser", err)
return
}
@@ -246,7 +247,7 @@ func EditUser(ctx *context.APIContext) {
u.IsRestricted = *form.Restricted
}
- if err := models.UpdateUser(u); err != nil {
+ if err := user_model.UpdateUser(u); err != nil {
if user_model.IsErrEmailAlreadyUsed(err) || user_model.IsErrEmailInvalid(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
@@ -409,10 +410,10 @@ func GetAllUsers(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- users, maxResults, err := models.SearchUsers(&models.SearchUserOptions{
+ users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
Actor: ctx.User,
- Type: models.UserTypeIndividual,
- OrderBy: models.SearchOrderByAlphabetically,
+ Type: user_model.UserTypeIndividual,
+ OrderBy: db.SearchOrderByAlphabetically,
ListOptions: listOptions,
})
if err != nil {
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index ea653b9677..867803f8dd 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -103,9 +103,9 @@ func sudo() func(ctx *context.APIContext) {
if len(sudo) > 0 {
if ctx.IsSigned && ctx.User.IsAdmin {
- user, err := models.GetUserByName(sudo)
+ user, err := user_model.GetUserByName(sudo)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -130,7 +130,7 @@ func repoAssignment() func(ctx *context.APIContext) {
repoName := ctx.Params("reponame")
var (
- owner *models.User
+ owner *user_model.User
err error
)
@@ -138,9 +138,9 @@ func repoAssignment() func(ctx *context.APIContext) {
if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
owner = ctx.User
} else {
- owner, err = models.GetUserByName(userName)
+ owner, err = user_model.GetUserByName(userName)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
context.RedirectToUser(ctx.Context, userName, redirectUserID)
} else if user_model.IsErrUserRedirectNotExist(err) {
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go
index 952e29fba9..84065363f0 100644
--- a/routers/api/v1/org/org.go
+++ b/routers/api/v1/org/org.go
@@ -10,6 +10,7 @@ import (
"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"
api "code.gitea.io/gitea/modules/structs"
@@ -19,7 +20,7 @@ import (
"code.gitea.io/gitea/services/org"
)
-func listUserOrgs(ctx *context.APIContext, u *models.User) {
+func listUserOrgs(ctx *context.APIContext, u *user_model.User) {
listOptions := utils.GetListOptions(ctx)
showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == u.ID)
@@ -130,12 +131,12 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- var u *models.User
+ var u *user_model.User
if u = user.GetUserByParams(ctx); u == nil {
return
}
- var o *models.User
+ var o *user_model.User
if o = user.GetUserByParamsName(ctx, ":org"); o == nil {
return
}
@@ -206,11 +207,11 @@ func GetAll(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- publicOrgs, maxResults, err := models.SearchUsers(&models.SearchUserOptions{
+ publicOrgs, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
Actor: ctx.User,
ListOptions: listOptions,
- Type: models.UserTypeOrganization,
- OrderBy: models.SearchOrderByAlphabetically,
+ Type: user_model.UserTypeOrganization,
+ OrderBy: db.SearchOrderByAlphabetically,
Visible: vMode,
})
if err != nil {
@@ -266,15 +267,15 @@ func Create(ctx *context.APIContext) {
Website: form.Website,
Location: form.Location,
IsActive: true,
- Type: models.UserTypeOrganization,
+ Type: user_model.UserTypeOrganization,
Visibility: visibility,
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
}
if err := models.CreateOrganization(org, ctx.User); err != nil {
- if models.IsErrUserAlreadyExist(err) ||
- models.IsErrNameReserved(err) ||
- models.IsErrNameCharsNotAllowed(err) ||
- models.IsErrNamePatternNotAllowed(err) {
+ if user_model.IsErrUserAlreadyExist(err) ||
+ db.IsErrNameReserved(err) ||
+ db.IsErrNameCharsNotAllowed(err) ||
+ db.IsErrNamePatternNotAllowed(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "CreateOrganization", err)
@@ -344,7 +345,7 @@ func Edit(ctx *context.APIContext) {
if form.RepoAdminChangeTeamAccess != nil {
org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
}
- if err := models.UpdateUserCols(db.DefaultContext, org.AsUser(),
+ if err := user_model.UpdateUserCols(db.DefaultContext, org.AsUser(),
"full_name", "description", "website", "location",
"visibility", "repo_admin_change_team_access",
); err != nil {
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")
diff --git a/routers/api/v1/user/follower.go b/routers/api/v1/user/follower.go
index edf3cea3ea..1eacb89db2 100644
--- a/routers/api/v1/user/follower.go
+++ b/routers/api/v1/user/follower.go
@@ -8,7 +8,6 @@ package user
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"
@@ -16,7 +15,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/utils"
)
-func responseAPIUsers(ctx *context.APIContext, users []*models.User) {
+func responseAPIUsers(ctx *context.APIContext, users []*user_model.User) {
apiUsers := make([]*api.User, len(users))
for i := range users {
apiUsers[i] = convert.ToUser(users[i], ctx.User)
@@ -24,8 +23,8 @@ func responseAPIUsers(ctx *context.APIContext, users []*models.User) {
ctx.JSON(http.StatusOK, &apiUsers)
}
-func listUserFollowers(ctx *context.APIContext, u *models.User) {
- users, err := models.GetUserFollowers(u, utils.GetListOptions(ctx))
+func listUserFollowers(ctx *context.APIContext, u *user_model.User) {
+ users, err := user_model.GetUserFollowers(u, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserFollowers", err)
return
@@ -90,8 +89,8 @@ func ListFollowers(ctx *context.APIContext) {
listUserFollowers(ctx, u)
}
-func listUserFollowing(ctx *context.APIContext, u *models.User) {
- users, err := models.GetUserFollowing(u, utils.GetListOptions(ctx))
+func listUserFollowing(ctx *context.APIContext, u *user_model.User) {
+ users, err := user_model.GetUserFollowing(u, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserFollowing", err)
return
@@ -156,7 +155,7 @@ func ListFollowing(ctx *context.APIContext) {
listUserFollowing(ctx, u)
}
-func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64) {
+func checkUserFollowing(ctx *context.APIContext, u *user_model.User, followID int64) {
if user_model.IsFollowing(u.ID, followID) {
ctx.Status(http.StatusNoContent)
} else {
diff --git a/routers/api/v1/user/helper.go b/routers/api/v1/user/helper.go
index a7c2e61405..fab3ce2ae5 100644
--- a/routers/api/v1/user/helper.go
+++ b/routers/api/v1/user/helper.go
@@ -7,17 +7,16 @@ package user
import (
"net/http"
- "code.gitea.io/gitea/models"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
)
// GetUserByParamsName get user by name
-func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
+func GetUserByParamsName(ctx *context.APIContext, name string) *user_model.User {
username := ctx.Params(name)
- user, err := models.GetUserByName(username)
+ user, err := user_model.GetUserByName(username)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
if redirectUserID, err2 := user_model.LookupUserRedirect(username); err2 == nil {
context.RedirectToUser(ctx.Context, username, redirectUserID)
} else {
@@ -32,6 +31,6 @@ func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
}
// GetUserByParams returns user whose name is presented in URL (":username").
-func GetUserByParams(ctx *context.APIContext) *models.User {
+func GetUserByParams(ctx *context.APIContext) *user_model.User {
return GetUserByParamsName(ctx, ":username")
}
diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go
index 36b1c17b89..719e1c0bdc 100644
--- a/routers/api/v1/user/key.go
+++ b/routers/api/v1/user/key.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"
"code.gitea.io/gitea/modules/setting"
@@ -18,7 +19,7 @@ import (
)
// appendPrivateInformation appends the owner and key type information to api.PublicKey
-func appendPrivateInformation(apiKey *api.PublicKey, key *models.PublicKey, defaultUser *models.User) (*api.PublicKey, error) {
+func appendPrivateInformation(apiKey *api.PublicKey, key *models.PublicKey, defaultUser *user_model.User) (*api.PublicKey, error) {
if key.Type == models.KeyTypeDeploy {
apiKey.KeyType = "deploy"
} else if key.Type == models.KeyTypeUser {
@@ -27,7 +28,7 @@ func appendPrivateInformation(apiKey *api.PublicKey, key *models.PublicKey, defa
if defaultUser.ID == key.OwnerID {
apiKey.Owner = convert.ToUser(defaultUser, defaultUser)
} else {
- user, err := models.GetUserByID(key.OwnerID)
+ user, err := user_model.GetUserByID(key.OwnerID)
if err != nil {
return apiKey, err
}
@@ -44,7 +45,7 @@ func composePublicKeysAPILink() string {
return setting.AppURL + "api/v1/user/keys/"
}
-func listPublicKeys(ctx *context.APIContext, user *models.User) {
+func listPublicKeys(ctx *context.APIContext, user *user_model.User) {
var keys []*models.PublicKey
var err error
var count int
diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go
index 3c9a17a0be..0b0b522c15 100644
--- a/routers/api/v1/user/repo.go
+++ b/routers/api/v1/user/repo.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"
@@ -15,7 +16,7 @@ import (
)
// listUserRepos - List the repositories owned by the given user.
-func listUserRepos(ctx *context.APIContext, u *models.User, private bool) {
+func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
opts := utils.GetListOptions(ctx)
repos, count, err := models.GetUserRepositories(&models.SearchRepoOptions{
diff --git a/routers/api/v1/user/settings.go b/routers/api/v1/user/settings.go
index b4548e7443..40bee56681 100644
--- a/routers/api/v1/user/settings.go
+++ b/routers/api/v1/user/settings.go
@@ -7,7 +7,7 @@ package user
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"
@@ -74,7 +74,7 @@ func UpdateUserSettings(ctx *context.APIContext) {
ctx.User.KeepActivityPrivate = *form.HideActivity
}
- if err := models.UpdateUser(ctx.User); err != nil {
+ if err := user_model.UpdateUser(ctx.User); err != nil {
ctx.InternalServerError(err)
return
}
diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go
index f067722bfa..946ae738e9 100644
--- a/routers/api/v1/user/star.go
+++ b/routers/api/v1/user/star.go
@@ -10,6 +10,7 @@ import (
"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"
api "code.gitea.io/gitea/modules/structs"
@@ -18,7 +19,7 @@ import (
// getStarredRepos returns the repos that the user with the specified userID has
// starred
-func getStarredRepos(user *models.User, private bool, listOptions db.ListOptions) ([]*api.Repository, error) {
+func getStarredRepos(user *user_model.User, private bool, listOptions db.ListOptions) ([]*api.Repository, error) {
starredRepos, err := models.GetStarredRepos(user.ID, private, listOptions)
if err != nil {
return nil, err
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go
index 8c57b1f099..bba7b7a5d1 100644
--- a/routers/api/v1/user/user.go
+++ b/routers/api/v1/user/user.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/routers/api/v1/utils"
@@ -54,11 +55,11 @@ func Search(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- users, maxResults, err := models.SearchUsers(&models.SearchUserOptions{
+ users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
Actor: ctx.User,
Keyword: ctx.FormTrim("q"),
UID: ctx.FormInt64("uid"),
- Type: models.UserTypeIndividual,
+ Type: user_model.UserTypeIndividual,
ListOptions: listOptions,
})
if err != nil {
@@ -105,7 +106,7 @@ func GetInfo(ctx *context.APIContext) {
if !models.IsUserVisibleToViewer(u, ctx.User) {
// fake ErrUserNotExist error message to not leak information about existence
- ctx.NotFound("GetUserByName", models.ErrUserNotExist{Name: ctx.Params(":username")})
+ ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.Params(":username")})
return
}
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.User))
diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go
index 3c6f8b3070..54d5e74bc0 100644
--- a/routers/api/v1/user/watch.go
+++ b/routers/api/v1/user/watch.go
@@ -9,6 +9,7 @@ import (
"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"
api "code.gitea.io/gitea/modules/structs"
@@ -16,7 +17,7 @@ import (
)
// getWatchedRepos returns the repos that the user with the specified userID is watching
-func getWatchedRepos(user *models.User, private bool, listOptions db.ListOptions) ([]*api.Repository, int64, error) {
+func getWatchedRepos(user *user_model.User, private bool, listOptions db.ListOptions) ([]*api.Repository, int64, error) {
watchedRepos, total, err := models.GetWatchedRepos(user.ID, private, listOptions)
if err != nil {
return nil, 0, err