Move user follow and openid into models/user/ (#17613)
* Move UserRedirect into models/user/ * Fix lint & test * Fix lint * Fix lint * remove nolint comment * Fix lint * Move user follow and openid into models/user * Ignore the lint * Ignore the lint * Fix test * ignore stutters lint on UserOpenID
This commit is contained in:
parent
adda27668b
commit
95d3266bee
17 changed files with 155 additions and 143 deletions
|
@ -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"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
@ -239,7 +240,7 @@ func Follow(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if err := models.FollowUser(ctx.User.ID, target.ID); err != nil {
|
||||
if err := user_model.FollowUser(ctx.User.ID, target.ID); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "FollowUser", err)
|
||||
return
|
||||
}
|
||||
|
@ -265,7 +266,7 @@ func Unfollow(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if err := models.UnfollowUser(ctx.User.ID, target.ID); err != nil {
|
||||
if err := user_model.UnfollowUser(ctx.User.ID, target.ID); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UnfollowUser", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"net/url"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/auth/openid"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -302,9 +303,9 @@ func ConnectOpenIDPost(ctx *context.Context) {
|
|||
}
|
||||
|
||||
// add OpenID for the user
|
||||
userOID := &models.UserOpenID{UID: u.ID, URI: oid}
|
||||
if err = models.AddUserOpenID(userOID); err != nil {
|
||||
if models.IsErrOpenIDAlreadyUsed(err) {
|
||||
userOID := &user_model.UserOpenID{UID: u.ID, URI: oid}
|
||||
if err = user_model.AddUserOpenID(userOID); err != nil {
|
||||
if user_model.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplConnectOID, &form)
|
||||
return
|
||||
}
|
||||
|
@ -430,9 +431,9 @@ func RegisterOpenIDPost(ctx *context.Context) {
|
|||
}
|
||||
|
||||
// add OpenID for the user
|
||||
userOID := &models.UserOpenID{UID: u.ID, URI: oid}
|
||||
if err = models.AddUserOpenID(userOID); err != nil {
|
||||
if models.IsErrOpenIDAlreadyUsed(err) {
|
||||
userOID := &user_model.UserOpenID{UID: u.ID, URI: oid}
|
||||
if err = user_model.AddUserOpenID(userOID); err != nil {
|
||||
if user_model.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplSignUpOID, &form)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ func Profile(ctx *context.Context) {
|
|||
}
|
||||
|
||||
// Show OpenID URIs
|
||||
openIDs, err := models.GetUserOpenIDs(ctxUser.ID)
|
||||
openIDs, err := user_model.GetUserOpenIDs(ctxUser.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserOpenIDs", err)
|
||||
return
|
||||
|
@ -355,9 +355,9 @@ func Action(ctx *context.Context) {
|
|||
var err error
|
||||
switch ctx.Params(":action") {
|
||||
case "follow":
|
||||
err = models.FollowUser(ctx.User.ID, u.ID)
|
||||
err = user_model.FollowUser(ctx.User.ID, u.ID)
|
||||
case "unfollow":
|
||||
err = models.UnfollowUser(ctx.User.ID, u.ID)
|
||||
err = user_model.UnfollowUser(ctx.User.ID, u.ID)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -10,6 +10,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/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -107,7 +108,7 @@ func loadSecurityData(ctx *context.Context) {
|
|||
}
|
||||
ctx.Data["AccountLinks"] = sources
|
||||
|
||||
openid, err := models.GetUserOpenIDs(ctx.User.ID)
|
||||
openid, err := user_model.GetUserOpenIDs(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserOpenIDs", err)
|
||||
return
|
||||
|
|
|
@ -7,7 +7,7 @@ package setting
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/auth/openid"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
@ -45,7 +45,7 @@ func OpenIDPost(ctx *context.Context) {
|
|||
form.Openid = id
|
||||
log.Trace("Normalized id: " + id)
|
||||
|
||||
oids, err := models.GetUserOpenIDs(ctx.User.ID)
|
||||
oids, err := user_model.GetUserOpenIDs(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserOpenIDs", err)
|
||||
return
|
||||
|
@ -89,9 +89,9 @@ func settingsOpenIDVerify(ctx *context.Context) {
|
|||
|
||||
log.Trace("Verified ID: " + id)
|
||||
|
||||
oid := &models.UserOpenID{UID: ctx.User.ID, URI: id}
|
||||
if err = models.AddUserOpenID(oid); err != nil {
|
||||
if models.IsErrOpenIDAlreadyUsed(err) {
|
||||
oid := &user_model.UserOpenID{UID: ctx.User.ID, URI: id}
|
||||
if err = user_model.AddUserOpenID(oid); err != nil {
|
||||
if user_model.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsSecurity, &forms.AddOpenIDForm{Openid: id})
|
||||
return
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func settingsOpenIDVerify(ctx *context.Context) {
|
|||
|
||||
// DeleteOpenID response for delete user's openid
|
||||
func DeleteOpenID(ctx *context.Context) {
|
||||
if err := models.DeleteUserOpenID(&models.UserOpenID{ID: ctx.FormInt64("id"), UID: ctx.User.ID}); err != nil {
|
||||
if err := user_model.DeleteUserOpenID(&user_model.UserOpenID{ID: ctx.FormInt64("id"), UID: ctx.User.ID}); err != nil {
|
||||
ctx.ServerError("DeleteUserOpenID", err)
|
||||
return
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ func DeleteOpenID(ctx *context.Context) {
|
|||
|
||||
// ToggleOpenIDVisibility response for toggle visibility of user's openid
|
||||
func ToggleOpenIDVisibility(ctx *context.Context) {
|
||||
if err := models.ToggleUserOpenIDVisibility(ctx.FormInt64("id")); err != nil {
|
||||
if err := user_model.ToggleUserOpenIDVisibility(ctx.FormInt64("id")); err != nil {
|
||||
ctx.ServerError("ToggleUserOpenIDVisibility", err)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue