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:
@@ -20,8 +20,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
mc "code.gitea.io/gitea/modules/cache"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
@@ -62,7 +62,7 @@ type Context struct {
|
||||
|
||||
Link string // current request URL
|
||||
EscapedLink string
|
||||
User *models.User
|
||||
User *user_model.User
|
||||
IsSigned bool
|
||||
IsBasicAuth bool
|
||||
|
||||
@@ -123,7 +123,7 @@ func (ctx *Context) IsUserRepoReaderAny() bool {
|
||||
|
||||
// RedirectToUser redirect to a differently-named user
|
||||
func RedirectToUser(ctx *Context, userName string, redirectUserID int64) {
|
||||
user, err := models.GetUserByID(redirectUserID)
|
||||
user, err := user_model.GetUserByID(redirectUserID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserByID", err)
|
||||
return
|
||||
@@ -560,7 +560,7 @@ func GetContext(req *http.Request) *Context {
|
||||
}
|
||||
|
||||
// GetContextUser returns context user
|
||||
func GetContextUser(req *http.Request) *models.User {
|
||||
func GetContextUser(req *http.Request) *user_model.User {
|
||||
if apiContext, ok := req.Context().Value(apiContextKey).(*APIContext); ok {
|
||||
return apiContext.User
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||
var err error
|
||||
ctx.Org.Organization, err = models.GetOrgByName(orgName)
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
redirectUserID, err := user_model.LookupUserRedirect(orgName)
|
||||
if err == nil {
|
||||
RedirectToUser(ctx, orgName, redirectUserID)
|
||||
@@ -108,7 +108,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||
}
|
||||
} else {
|
||||
// Fake data.
|
||||
ctx.Data["SignedUser"] = &models.User{}
|
||||
ctx.Data["SignedUser"] = &user_model.User{}
|
||||
}
|
||||
if (requireMember && !ctx.Org.IsMember) ||
|
||||
(requireOwner && !ctx.Org.IsOwner) {
|
||||
|
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
unit_model "code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/cache"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
@@ -55,7 +56,7 @@ type Repository struct {
|
||||
IsViewTag bool
|
||||
IsViewCommit bool
|
||||
Repository *models.Repository
|
||||
Owner *models.User
|
||||
Owner *user_model.User
|
||||
Commit *git.Commit
|
||||
Tag *git.Tag
|
||||
GitRepo *git.Repository
|
||||
@@ -104,7 +105,7 @@ type CanCommitToBranchResults struct {
|
||||
|
||||
// CanCommitToBranch returns true if repository is editable and user has proper access level
|
||||
// and branch is not protected for push
|
||||
func (r *Repository) CanCommitToBranch(doer *models.User) (CanCommitToBranchResults, error) {
|
||||
func (r *Repository) CanCommitToBranch(doer *user_model.User) (CanCommitToBranchResults, error) {
|
||||
protectedBranch, err := models.GetProtectedBranchBy(r.Repository.ID, r.BranchName)
|
||||
|
||||
if err != nil {
|
||||
@@ -145,7 +146,7 @@ func (r *Repository) CanCommitToBranch(doer *models.User) (CanCommitToBranchResu
|
||||
}
|
||||
|
||||
// CanUseTimetracker returns whether or not a user can use the timetracker.
|
||||
func (r *Repository) CanUseTimetracker(issue *models.Issue, user *models.User) bool {
|
||||
func (r *Repository) CanUseTimetracker(issue *models.Issue, user *user_model.User) bool {
|
||||
// Checking for following:
|
||||
// 1. Is timetracker enabled
|
||||
// 2. Is the user a contributor, admin, poster or assignee and do the repository policies require this?
|
||||
@@ -155,7 +156,7 @@ func (r *Repository) CanUseTimetracker(issue *models.Issue, user *models.User) b
|
||||
}
|
||||
|
||||
// CanCreateIssueDependencies returns whether or not a user can create dependencies.
|
||||
func (r *Repository) CanCreateIssueDependencies(user *models.User, isPull bool) bool {
|
||||
func (r *Repository) CanCreateIssueDependencies(user *user_model.User, isPull bool) bool {
|
||||
return r.Repository.IsDependenciesEnabled() && r.Permission.CanWriteIssuesOrPulls(isPull)
|
||||
}
|
||||
|
||||
@@ -402,7 +403,7 @@ func RepoIDAssignment() func(ctx *Context) {
|
||||
// RepoAssignment returns a middleware to handle repository assignment
|
||||
func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||
var (
|
||||
owner *models.User
|
||||
owner *user_model.User
|
||||
err error
|
||||
)
|
||||
|
||||
@@ -414,9 +415,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||
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 ctx.FormString("go-get") == "1" {
|
||||
EarlyResponseForGoGetMeta(ctx)
|
||||
return
|
||||
|
Reference in New Issue
Block a user