mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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")
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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{
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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))
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user