mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
Move EmailAddress & UserRedirect into models/user/ (#17607)
* Move EmailAddress into models/user/ * Fix test * rename user_mail to user_email * Fix test * Move UserRedirect into models/user/ * Fix lint & test * Fix lint * Fix lint * remove nolint comment * Fix lint
This commit is contained in:
parent
492e1c2fbd
commit
90eb9fb889
32 changed files with 722 additions and 647 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/login"
|
||||
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"
|
||||
|
@ -109,10 +110,10 @@ func CreateUser(ctx *context.APIContext) {
|
|||
|
||||
if err := models.CreateUser(u, overwriteDefault); err != nil {
|
||||
if models.IsErrUserAlreadyExist(err) ||
|
||||
models.IsErrEmailAlreadyUsed(err) ||
|
||||
user_model.IsErrEmailAlreadyUsed(err) ||
|
||||
models.IsErrNameReserved(err) ||
|
||||
models.IsErrNameCharsNotAllowed(err) ||
|
||||
models.IsErrEmailInvalid(err) ||
|
||||
user_model.IsErrEmailInvalid(err) ||
|
||||
models.IsErrNamePatternNotAllowed(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
|
@ -245,7 +246,7 @@ func EditUser(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if err := models.UpdateUser(u); err != nil {
|
||||
if models.IsErrEmailAlreadyUsed(err) || models.IsErrEmailInvalid(err) {
|
||||
if user_model.IsErrEmailAlreadyUsed(err) || user_model.IsErrEmailInvalid(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "UpdateUser", err)
|
||||
|
|
|
@ -71,6 +71,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/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -138,9 +139,9 @@ func repoAssignment() func(ctx *context.APIContext) {
|
|||
owner, err = models.GetUserByName(userName)
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
if redirectUserID, err := models.LookupUserRedirect(userName); err == nil {
|
||||
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
|
||||
context.RedirectToUser(ctx.Context, userName, redirectUserID)
|
||||
} else if models.IsErrUserRedirectNotExist(err) {
|
||||
} else if user_model.IsErrUserRedirectNotExist(err) {
|
||||
ctx.NotFound("GetUserByName", err)
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "LookupUserRedirect", err)
|
||||
|
@ -421,10 +422,10 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
|
|||
ctx.Org.Organization, err = models.GetOrgByName(ctx.Params(":org"))
|
||||
if err != nil {
|
||||
if models.IsErrOrgNotExist(err) {
|
||||
redirectUserID, err := models.LookupUserRedirect(ctx.Params(":org"))
|
||||
redirectUserID, err := user_model.LookupUserRedirect(ctx.Params(":org"))
|
||||
if err == nil {
|
||||
context.RedirectToUser(ctx.Context, ctx.Params(":org"), redirectUserID)
|
||||
} else if models.IsErrUserRedirectNotExist(err) {
|
||||
} else if user_model.IsErrUserRedirectNotExist(err) {
|
||||
ctx.NotFound("GetOrgByName", err)
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "LookupUserRedirect", err)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"fmt"
|
||||
"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"
|
||||
|
@ -28,7 +28,7 @@ func ListEmails(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/EmailList"
|
||||
|
||||
emails, err := models.GetEmailAddresses(ctx.User.ID)
|
||||
emails, err := user_model.GetEmailAddresses(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetEmailAddresses", err)
|
||||
return
|
||||
|
@ -68,20 +68,20 @@ func AddEmail(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
emails := make([]*models.EmailAddress, len(form.Emails))
|
||||
emails := make([]*user_model.EmailAddress, len(form.Emails))
|
||||
for i := range form.Emails {
|
||||
emails[i] = &models.EmailAddress{
|
||||
emails[i] = &user_model.EmailAddress{
|
||||
UID: ctx.User.ID,
|
||||
Email: form.Emails[i],
|
||||
IsActivated: !setting.Service.RegisterEmailConfirm,
|
||||
}
|
||||
}
|
||||
|
||||
if err := models.AddEmailAddresses(emails); err != nil {
|
||||
if models.IsErrEmailAlreadyUsed(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", "Email address has been used: "+err.(models.ErrEmailAlreadyUsed).Email)
|
||||
} else if models.IsErrEmailInvalid(err) {
|
||||
errMsg := fmt.Sprintf("Email address %s invalid", err.(models.ErrEmailInvalid).Email)
|
||||
if err := user_model.AddEmailAddresses(emails); err != nil {
|
||||
if user_model.IsErrEmailAlreadyUsed(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", "Email address has been used: "+err.(user_model.ErrEmailAlreadyUsed).Email)
|
||||
} else if user_model.IsErrEmailInvalid(err) {
|
||||
errMsg := fmt.Sprintf("Email address %s invalid", err.(user_model.ErrEmailInvalid).Email)
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", errMsg)
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "AddEmailAddresses", err)
|
||||
|
@ -119,16 +119,16 @@ func DeleteEmail(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
emails := make([]*models.EmailAddress, len(form.Emails))
|
||||
emails := make([]*user_model.EmailAddress, len(form.Emails))
|
||||
for i := range form.Emails {
|
||||
emails[i] = &models.EmailAddress{
|
||||
emails[i] = &user_model.EmailAddress{
|
||||
Email: form.Emails[i],
|
||||
UID: ctx.User.ID,
|
||||
}
|
||||
}
|
||||
|
||||
if err := models.DeleteEmailAddresses(emails); err != nil {
|
||||
if models.IsErrEmailAddressNotExist(err) {
|
||||
if err := user_model.DeleteEmailAddresses(emails); err != nil {
|
||||
if user_model.IsErrEmailAddressNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "DeleteEmailAddresses", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -17,7 +18,7 @@ func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
|
|||
user, err := models.GetUserByName(username)
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
if redirectUserID, err2 := models.LookupUserRedirect(username); err2 == nil {
|
||||
if redirectUserID, err2 := user_model.LookupUserRedirect(username); err2 == nil {
|
||||
context.RedirectToUser(ctx.Context, username, redirectUserID)
|
||||
} else {
|
||||
ctx.NotFound("GetUserByName", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue