diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-28 22:11:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-28 22:11:58 +0800 |
commit | 9defddb2862aa0a54da21328ca091284291363f7 (patch) | |
tree | 1126670579198f00d89c8a4f0240aa7d99995eb8 /routers | |
parent | b1df89095163d8ce3eecfeb855e7f03f17b473c4 (diff) | |
download | gitea-9defddb2862aa0a54da21328ca091284291363f7.tar.gz gitea-9defddb2862aa0a54da21328ca091284291363f7.zip |
Move more model into models/user (#17826)
* Move more model into models/user
* Remove unnecessary comment
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue_subscription.go | 2 | ||||
-rw-r--r-- | routers/web/admin/emails.go | 23 | ||||
-rw-r--r-- | routers/web/explore/user.go | 3 | ||||
-rw-r--r-- | routers/web/org/members.go | 2 | ||||
-rw-r--r-- | routers/web/user/auth.go | 15 | ||||
-rw-r--r-- | routers/web/user/setting/account.go | 2 | ||||
-rw-r--r-- | routers/web/user/setting/security.go | 4 |
7 files changed, 24 insertions, 27 deletions
diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go index 09be3cc193..ae7661cfab 100644 --- a/routers/api/v1/repo/issue_subscription.go +++ b/routers/api/v1/repo/issue_subscription.go @@ -273,7 +273,7 @@ func GetIssueSubscribers(ctx *context.APIContext) { userIDs = append(userIDs, iw.UserID) } - users, err := models.GetUsersByIDs(userIDs) + users, err := user_model.GetUsersByIDs(userIDs) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUsersByIDs", err) return diff --git a/routers/web/admin/emails.go b/routers/web/admin/emails.go index 4872ecb920..cbf0ec5e98 100644 --- a/routers/web/admin/emails.go +++ b/routers/web/admin/emails.go @@ -9,7 +9,6 @@ import ( "net/http" "net/url" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" @@ -29,7 +28,7 @@ func Emails(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminEmails"] = true - opts := &models.SearchEmailOptions{ + opts := &user_model.SearchEmailOptions{ ListOptions: db.ListOptions{ PageSize: setting.UI.Admin.UserPagingNum, Page: ctx.FormInt("page"), @@ -41,31 +40,31 @@ func Emails(ctx *context.Context) { } type ActiveEmail struct { - models.SearchEmailResult + user_model.SearchEmailResult CanChange bool } var ( - baseEmails []*models.SearchEmailResult + baseEmails []*user_model.SearchEmailResult emails []ActiveEmail count int64 err error - orderBy models.SearchEmailOrderBy + orderBy user_model.SearchEmailOrderBy ) ctx.Data["SortType"] = ctx.FormString("sort") switch ctx.FormString("sort") { case "email": - orderBy = models.SearchEmailOrderByEmail + orderBy = user_model.SearchEmailOrderByEmail case "reverseemail": - orderBy = models.SearchEmailOrderByEmailReverse + orderBy = user_model.SearchEmailOrderByEmailReverse case "username": - orderBy = models.SearchEmailOrderByName + orderBy = user_model.SearchEmailOrderByName case "reverseusername": - orderBy = models.SearchEmailOrderByNameReverse + orderBy = user_model.SearchEmailOrderByNameReverse default: ctx.Data["SortType"] = "email" - orderBy = models.SearchEmailOrderByEmail + orderBy = user_model.SearchEmailOrderByEmail } opts.Keyword = ctx.FormTrim("q") @@ -78,7 +77,7 @@ func Emails(ctx *context.Context) { } if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) { - baseEmails, count, err = models.SearchEmails(opts) + baseEmails, count, err = user_model.SearchEmails(opts) if err != nil { ctx.ServerError("SearchEmails", err) return @@ -127,7 +126,7 @@ func ActivateEmail(ctx *context.Context) { log.Info("Changing activation for User ID: %d, email: %s, primary: %v to %v", uid, email, primary, activate) - if err := models.ActivateUserEmail(uid, email, activate); err != nil { + if err := user_model.ActivateUserEmail(uid, email, activate); err != nil { log.Error("ActivateUserEmail(%v,%v,%v): %v", uid, email, activate, err) if user_model.IsErrEmailAlreadyUsed(err) { ctx.Flash.Error(ctx.Tr("admin.emails.duplicate_active")) diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index 8560378447..27634c3d4e 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -8,7 +8,6 @@ import ( "bytes" "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/base" @@ -79,7 +78,7 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, ctx.Data["Keyword"] = opts.Keyword ctx.Data["Total"] = count ctx.Data["Users"] = users - ctx.Data["UsersTwoFaStatus"] = models.UserList(users).GetTwoFaStatus() + ctx.Data["UsersTwoFaStatus"] = user_model.UserList(users).GetTwoFaStatus() ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled diff --git a/routers/web/org/members.go b/routers/web/org/members.go index ef5a69e157..e9b7317c98 100644 --- a/routers/web/org/members.go +++ b/routers/web/org/members.go @@ -62,7 +62,7 @@ func Members(ctx *context.Context) { ctx.Data["Page"] = pager ctx.Data["Members"] = members ctx.Data["MembersIsPublicMember"] = membersIsPublic - ctx.Data["MembersIsUserOrgOwner"] = members.IsUserOrgOwner(org.ID) + ctx.Data["MembersIsUserOrgOwner"] = models.IsUserOrgOwner(members, org.ID) ctx.Data["MembersTwoFaStatus"] = members.GetTwoFaStatus() ctx.HTML(http.StatusOK, tplMembers) diff --git a/routers/web/user/auth.go b/routers/web/user/auth.go index a71a278958..42cd977b54 100644 --- a/routers/web/user/auth.go +++ b/routers/web/user/auth.go @@ -12,7 +12,6 @@ import ( "net/http" "strings" - "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" @@ -781,7 +780,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *user_mode } // update external user information - if err := models.UpdateExternalUser(u, gothUser); err != nil { + if err := user_model.UpdateExternalUser(u, gothUser); err != nil { log.Error("UpdateExternalUser failed: %v", err) } @@ -844,11 +843,11 @@ func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, r } // search in external linked users - externalLoginUser := &models.ExternalLoginUser{ + externalLoginUser := &user_model.ExternalLoginUser{ ExternalID: gothUser.UserID, LoginSourceID: loginSource.ID, } - hasUser, err = models.GetExternalLogin(externalLoginUser) + hasUser, err = user_model.GetExternalLogin(externalLoginUser) if err != nil { return nil, goth.User{}, err } @@ -1355,7 +1354,7 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth. // update external user information if gothUser != nil { - if err := models.UpdateExternalUser(u, *gothUser); err != nil { + if err := user_model.UpdateExternalUser(u, *gothUser); err != nil { log.Error("UpdateExternalUser failed: %v", err) } } @@ -1477,7 +1476,7 @@ func handleAccountActivation(ctx *context.Context, user *user_model.User) { return } - if err := models.ActivateUserEmail(user.ID, user.Email, true); err != nil { + if err := user_model.ActivateUserEmail(user.ID, user.Email, true); err != nil { log.Error("Unable to activate email for user: %-v with email: %s: %v", user, user.Email, err) ctx.ServerError("ActivateUserEmail", err) return @@ -1505,8 +1504,8 @@ func ActivateEmail(ctx *context.Context) { emailStr := ctx.FormString("email") // Verify code. - if email := models.VerifyActiveEmailCode(code, emailStr); email != nil { - if err := models.ActivateEmail(email); err != nil { + if email := user_model.VerifyActiveEmailCode(code, emailStr); email != nil { + if err := user_model.ActivateEmail(email); err != nil { ctx.ServerError("ActivateEmail", err) } diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go index 3b51fdb777..b73122fa12 100644 --- a/routers/web/user/setting/account.go +++ b/routers/web/user/setting/account.go @@ -94,7 +94,7 @@ func EmailPost(ctx *context.Context) { // Make emailaddress primary. if ctx.FormString("_method") == "PRIMARY" { - if err := models.MakeEmailPrimary(&user_model.EmailAddress{ID: ctx.FormInt64("id")}); err != nil { + if err := user_model.MakeEmailPrimary(&user_model.EmailAddress{ID: ctx.FormInt64("id")}); err != nil { ctx.ServerError("MakeEmailPrimary", err) return } diff --git a/routers/web/user/setting/security.go b/routers/web/user/setting/security.go index f0b1d8232a..d34de519b7 100644 --- a/routers/web/user/setting/security.go +++ b/routers/web/user/setting/security.go @@ -43,7 +43,7 @@ func DeleteAccountLink(ctx *context.Context) { if id <= 0 { ctx.Flash.Error("Account link id is not given") } else { - if _, err := models.RemoveAccountLink(ctx.User, id); err != nil { + if _, err := user_model.RemoveAccountLink(ctx.User, id); err != nil { ctx.Flash.Error("RemoveAccountLink: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.remove_account_link_success")) @@ -76,7 +76,7 @@ func loadSecurityData(ctx *context.Context) { } ctx.Data["Tokens"] = tokens - accountLinks, err := models.ListAccountLinks(ctx.User) + accountLinks, err := user_model.ListAccountLinks(ctx.User) if err != nil { ctx.ServerError("ListAccountLinks", err) return |