]> source.dussan.org Git - gitea.git/commitdiff
Move user related model into models/user (#17781)
authorLunny Xiao <xiaolunwen@gmail.com>
Wed, 24 Nov 2021 09:49:20 +0000 (17:49 +0800)
committerGitHub <noreply@github.com>
Wed, 24 Nov 2021 09:49:20 +0000 (17:49 +0800)
* Move user related model into models/user

* Fix lint for windows

* Fix windows lint

* Fix windows lint

* Move some tests in models

* Merge

346 files changed:
cmd/admin.go
cmd/migrate_storage.go
integrations/admin_user_test.go
integrations/api_admin_org_test.go
integrations/api_admin_test.go
integrations/api_comment_test.go
integrations/api_issue_label_test.go
integrations/api_issue_milestone_test.go
integrations/api_issue_reaction_test.go
integrations/api_issue_stopwatch_test.go
integrations/api_issue_subscription_test.go
integrations/api_issue_test.go
integrations/api_issue_tracked_time_test.go
integrations/api_keys_test.go
integrations/api_notification_test.go
integrations/api_oauth2_apps_test.go
integrations/api_org_test.go
integrations/api_pull_test.go
integrations/api_releases_test.go
integrations/api_repo_archive_test.go
integrations/api_repo_edit_test.go
integrations/api_repo_file_create_test.go
integrations/api_repo_file_delete_test.go
integrations/api_repo_file_helpers.go
integrations/api_repo_file_update_test.go
integrations/api_repo_get_contents_list_test.go
integrations/api_repo_get_contents_test.go
integrations/api_repo_git_blobs_test.go
integrations/api_repo_git_commits_test.go
integrations/api_repo_git_hook_test.go
integrations/api_repo_git_notes_test.go
integrations/api_repo_git_ref_test.go
integrations/api_repo_git_tags_test.go
integrations/api_repo_git_trees_test.go
integrations/api_repo_lfs_locks_test.go
integrations/api_repo_lfs_migrate_test.go
integrations/api_repo_lfs_test.go
integrations/api_repo_raw_test.go
integrations/api_repo_tags_test.go
integrations/api_repo_teams_test.go
integrations/api_repo_test.go
integrations/api_repo_topic_test.go
integrations/api_team_test.go
integrations/api_team_user_test.go
integrations/api_token_test.go
integrations/api_user_orgs_test.go
integrations/api_user_search_test.go
integrations/change_default_branch_test.go
integrations/delete_user_test.go
integrations/empty_repo_test.go
integrations/eventsource_test.go
integrations/git_test.go
integrations/gpg_git_test.go
integrations/issue_test.go
integrations/migrate_test.go
integrations/mirror_pull_test.go
integrations/mirror_push_test.go
integrations/org_count_test.go
integrations/privateactivity_test.go
integrations/pull_merge_test.go
integrations/pull_update_test.go
integrations/repo_fork_test.go
integrations/repo_generate_test.go
integrations/repo_tag_test.go
integrations/signin_test.go
integrations/signup_test.go
integrations/user_avatar_test.go
integrations/user_test.go
integrations/xss_test.go
models/access.go
models/access_test.go
models/action.go
models/action_list.go
models/action_test.go
models/branches.go
models/commit.go
models/commit_status.go
models/consistency.go
models/db/error.go
models/db/name.go [new file with mode: 0644]
models/db/search.go [new file with mode: 0644]
models/error.go
models/external_login_user.go
models/gpg_key.go
models/gpg_key_commit_verification.go
models/gpg_key_test.go
models/gpg_key_verify.go
models/helper.go
models/helper_environment.go
models/issue.go
models/issue_assignees.go
models/issue_assignees_test.go
models/issue_comment.go
models/issue_comment_list.go
models/issue_comment_test.go
models/issue_dependency.go
models/issue_dependency_test.go
models/issue_label.go
models/issue_label_test.go
models/issue_list.go
models/issue_lock.go
models/issue_milestone.go
models/issue_milestone_test.go
models/issue_reaction.go
models/issue_reaction_test.go
models/issue_stopwatch.go
models/issue_stopwatch_test.go
models/issue_test.go
models/issue_tracked_time.go
models/issue_tracked_time_test.go
models/issue_watch.go
models/issue_xref.go
models/issue_xref_test.go
models/lfs.go
models/lfs_lock.go
models/main_test.go
models/notification.go
models/notification_test.go
models/org.go
models/org_team.go
models/org_team_test.go
models/org_test.go
models/project_issue.go
models/pull.go
models/pull_list.go
models/pull_sign.go
models/pull_test.go
models/release.go
models/repo.go
models/repo_activity.go
models/repo_collaboration.go
models/repo_collaboration_test.go
models/repo_list.go
models/repo_permission.go
models/repo_permission_test.go
models/repo_sign.go
models/repo_test.go
models/repo_transfer.go
models/repo_transfer_test.go
models/repo_watch.go
models/review.go
models/review_test.go
models/ssh_key.go
models/ssh_key_deploy.go
models/ssh_key_principals.go
models/star.go
models/statistic.go
models/task.go
models/user.go
models/user/avatar.go [new file with mode: 0644]
models/user/error.go [new file with mode: 0644]
models/user/main_test.go
models/user/search.go [new file with mode: 0644]
models/user/user.go [new file with mode: 0644]
models/user/user_test.go [new file with mode: 0644]
models/user_avatar.go [deleted file]
models/user_email.go
models/user_email_test.go
models/user_heatmap.go
models/user_heatmap_test.go
models/user_test.go
models/userlist.go
models/wiki.go
modules/context/context.go
modules/context/org.go
modules/context/repo.go
modules/convert/convert.go
modules/convert/git_commit.go
modules/convert/issue.go
modules/convert/pull.go
modules/convert/pull_review.go
modules/convert/status.go
modules/convert/user.go
modules/convert/user_test.go
modules/doctor/misc.go
modules/gitgraph/graph_models.go
modules/indexer/issues/indexer.go
modules/notification/action/action.go
modules/notification/action/action_test.go
modules/notification/base/notifier.go
modules/notification/base/null.go
modules/notification/indexer/indexer.go
modules/notification/mail/mail.go
modules/notification/notification.go
modules/notification/ui/ui.go
modules/notification/webhook/webhook.go
modules/private/serv.go
modules/repofiles/commit_status.go [new file with mode: 0644]
modules/repository/commits.go
modules/repository/create.go
modules/repository/create_test.go
modules/repository/generate.go
modules/repository/init.go
modules/repository/repo.go
modules/templates/helper.go
modules/test/context_tests.go
routers/api/v1/admin/adopt.go
routers/api/v1/admin/org.go
routers/api/v1/admin/user.go
routers/api/v1/api.go
routers/api/v1/org/org.go
routers/api/v1/repo/branch.go
routers/api/v1/repo/collaborators.go
routers/api/v1/repo/commits.go
routers/api/v1/repo/fork.go
routers/api/v1/repo/issue.go
routers/api/v1/repo/issue_subscription.go
routers/api/v1/repo/issue_tracked_time.go
routers/api/v1/repo/migrate.go
routers/api/v1/repo/pull.go
routers/api/v1/repo/pull_review.go
routers/api/v1/repo/repo.go
routers/api/v1/repo/transfer.go
routers/api/v1/user/follower.go
routers/api/v1/user/helper.go
routers/api/v1/user/key.go
routers/api/v1/user/repo.go
routers/api/v1/user/settings.go
routers/api/v1/user/star.go
routers/api/v1/user/user.go
routers/api/v1/user/watch.go
routers/install/install.go
routers/private/hook_pre_receive.go
routers/private/mail.go
routers/private/serv.go
routers/web/admin/orgs.go
routers/web/admin/repos.go
routers/web/admin/users.go
routers/web/admin/users_test.go
routers/web/dev/template.go
routers/web/explore/org.go
routers/web/explore/repo.go
routers/web/explore/user.go
routers/web/feed/profile.go
routers/web/org/home.go
routers/web/org/org.go
routers/web/org/setting.go
routers/web/org/teams.go
routers/web/repo/blame.go
routers/web/repo/commit.go
routers/web/repo/compare.go
routers/web/repo/http.go
routers/web/repo/issue.go
routers/web/repo/lfs.go
routers/web/repo/middlewares.go
routers/web/repo/migrate.go
routers/web/repo/pull.go
routers/web/repo/release.go
routers/web/repo/repo.go
routers/web/repo/setting.go
routers/web/repo/settings_test.go
routers/web/repo/view.go
routers/web/repo/webhook.go
routers/web/user/auth.go
routers/web/user/auth_openid.go
routers/web/user/avatar.go
routers/web/user/home.go
routers/web/user/oauth.go
routers/web/user/oauth_test.go
routers/web/user/profile.go
routers/web/user/setting/account.go
routers/web/user/setting/adopt.go
routers/web/user/setting/profile.go
services/agit/agit.go
services/attachment/attachment_test.go
services/auth/auth.go
services/auth/basic.go
services/auth/group.go
services/auth/interface.go
services/auth/login_source.go
services/auth/oauth2.go
services/auth/reverseproxy.go
services/auth/session.go
services/auth/signin.go
services/auth/source/db/authenticate.go
services/auth/source/db/source.go
services/auth/source/ldap/source_authenticate.go
services/auth/source/ldap/source_sync.go
services/auth/source/oauth2/providers.go
services/auth/source/oauth2/source_authenticate.go
services/auth/source/pam/source_authenticate.go
services/auth/source/smtp/auth.go
services/auth/source/smtp/source_authenticate.go
services/auth/sspi_windows.go
services/comments/comments.go
services/cron/setting.go
services/cron/tasks.go
services/cron/tasks_basic.go
services/cron/tasks_extended.go
services/externalaccount/user.go
services/gitdiff/gitdiff.go
services/gitdiff/gitdiff_test.go
services/issue/assignee.go
services/issue/assignee_test.go
services/issue/commit.go
services/issue/commit_test.go
services/issue/content.go
services/issue/issue.go
services/issue/label.go
services/issue/label_test.go
services/issue/milestone.go
services/issue/status.go
services/lfs/locks.go
services/lfs/server.go
services/mailer/mail.go
services/mailer/mail_comment.go
services/mailer/mail_issue.go
services/mailer/mail_release.go
services/mailer/mail_repo.go
services/mailer/mail_test.go
services/migrations/dump.go
services/migrations/gitea_uploader.go
services/migrations/gitea_uploader_test.go
services/migrations/migrate.go
services/migrations/migrate_test.go
services/org/org.go
services/org/org_test.go
services/pull/check.go
services/pull/merge.go
services/pull/pull.go
services/pull/review.go
services/pull/update.go
services/release/release.go
services/release/release_test.go
services/repository/adopt.go
services/repository/branch.go
services/repository/check.go
services/repository/files/commit.go
services/repository/files/delete.go
services/repository/files/file.go
services/repository/files/temp_repo.go
services/repository/files/update.go
services/repository/files/upload.go
services/repository/fork.go
services/repository/fork_test.go
services/repository/generate.go
services/repository/push.go
services/repository/repository.go
services/repository/transfer.go
services/repository/transfer_test.go
services/task/migrate.go
services/task/task.go
services/user/user.go
services/user/user_test.go
services/wiki/wiki.go
services/wiki/wiki_test.go

index b4fc7f570671b600ab0185c6038186a74c606838..d11b824fa12ea46810e43ec3d8c539a76bd1f1b8 100644 (file)
@@ -16,6 +16,7 @@ import (
        "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"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/graceful"
        "code.gitea.io/gitea/modules/log"
@@ -358,7 +359,7 @@ func runChangePassword(c *cli.Context) error {
                return errors.New("The password you chose is on a list of stolen passwords previously exposed in public data breaches. Please try again with a different password.\nFor more details, see https://haveibeenpwned.com/Passwords")
        }
        uname := c.String("username")
-       user, err := models.GetUserByName(uname)
+       user, err := user_model.GetUserByName(uname)
        if err != nil {
                return err
        }
@@ -366,7 +367,7 @@ func runChangePassword(c *cli.Context) error {
                return err
        }
 
-       if err = models.UpdateUserCols(db.DefaultContext, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
+       if err = user_model.UpdateUserCols(db.DefaultContext, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
                return err
        }
 
@@ -424,7 +425,7 @@ func runCreateUser(c *cli.Context) error {
 
        // If this is the first user being created.
        // Take it as the admin and don't force a password update.
-       if n := models.CountUsers(); n == 0 {
+       if n := user_model.CountUsers(); n == 0 {
                changePassword = false
        }
 
@@ -432,7 +433,7 @@ func runCreateUser(c *cli.Context) error {
                changePassword = c.Bool("must-change-password")
        }
 
-       u := &models.User{
+       u := &user_model.User{
                Name:               username,
                Email:              c.String("email"),
                Passwd:             password,
@@ -442,7 +443,7 @@ func runCreateUser(c *cli.Context) error {
                Theme:              setting.UI.DefaultTheme,
        }
 
-       if err := models.CreateUser(u); err != nil {
+       if err := user_model.CreateUser(u); err != nil {
                return fmt.Errorf("CreateUser: %v", err)
        }
 
@@ -471,7 +472,7 @@ func runListUsers(c *cli.Context) error {
                return err
        }
 
-       users, err := models.GetAllUsers()
+       users, err := user_model.GetAllUsers()
 
        if err != nil {
                return err
@@ -516,13 +517,13 @@ func runDeleteUser(c *cli.Context) error {
        }
 
        var err error
-       var user *models.User
+       var user *user_model.User
        if c.IsSet("email") {
-               user, err = models.GetUserByEmail(c.String("email"))
+               user, err = user_model.GetUserByEmail(c.String("email"))
        } else if c.IsSet("username") {
-               user, err = models.GetUserByName(c.String("username"))
+               user, err = user_model.GetUserByName(c.String("username"))
        } else {
-               user, err = models.GetUserByID(c.Int64("id"))
+               user, err = user_model.GetUserByID(c.Int64("id"))
        }
        if err != nil {
                return err
index 9f1d9057f9ccd72c0bc8b57b179a4ccea20403f4..afb0fc02a3a13b8cc09f61d02d6eb8f9f66c36b6 100644 (file)
@@ -13,6 +13,7 @@ import (
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/migrations"
        repo_model "code.gitea.io/gitea/models/repo"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/storage"
@@ -94,7 +95,7 @@ func migrateLFS(dstStorage storage.ObjectStorage) error {
 }
 
 func migrateAvatars(dstStorage storage.ObjectStorage) error {
-       return models.IterateUser(func(user *models.User) error {
+       return user_model.IterateUser(func(user *user_model.User) error {
                _, err := storage.Copy(dstStorage, user.CustomAvatarRelativePath(), storage.Avatars, user.CustomAvatarRelativePath())
                return err
        })
index f9e9afac34c066a2f523e88d16ae634369645362..d657f65fa55e40bb9a07ac1ad9933eca79cfb88f 100644 (file)
@@ -9,8 +9,8 @@ import (
        "strconv"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -42,14 +42,14 @@ func TestAdminViewUser(t *testing.T) {
 func TestAdminEditUser(t *testing.T) {
        defer prepareTestEnv(t)()
 
-       testSuccessfullEdit(t, models.User{ID: 2, Name: "newusername", LoginName: "otherlogin", Email: "new@e-mail.gitea"})
+       testSuccessfullEdit(t, user_model.User{ID: 2, Name: "newusername", LoginName: "otherlogin", Email: "new@e-mail.gitea"})
 }
 
-func testSuccessfullEdit(t *testing.T, formData models.User) {
+func testSuccessfullEdit(t *testing.T, formData user_model.User) {
        makeRequest(t, formData, http.StatusFound)
 }
 
-func makeRequest(t *testing.T, formData models.User, headerCode int) {
+func makeRequest(t *testing.T, formData user_model.User, headerCode int) {
        session := loginUser(t, "user1")
        csrf := GetCSRF(t, session, "/admin/users/"+strconv.Itoa(int(formData.ID)))
        req := NewRequestWithValues(t, "POST", "/admin/users/"+strconv.Itoa(int(formData.ID)), map[string]string{
@@ -61,7 +61,7 @@ func makeRequest(t *testing.T, formData models.User, headerCode int) {
        })
 
        session.MakeRequest(t, req, headerCode)
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: formData.ID}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: formData.ID}).(*user_model.User)
        assert.Equal(t, formData.Name, user.Name)
        assert.Equal(t, formData.LoginName, user.LoginName)
        assert.Equal(t, formData.Email, user.Email)
@@ -79,5 +79,5 @@ func TestAdminDeleteUser(t *testing.T) {
        session.MakeRequest(t, req, http.StatusOK)
 
        assertUserDeleted(t, 8)
-       unittest.CheckConsistencyFor(t, &models.User{})
+       unittest.CheckConsistencyFor(t, &user_model.User{})
 }
index a4ef0ed5ef3670b65ee67e5d258660c8fe8d1b6e..4b5e2481e65d48b7c4b97e694346ef6290540f5f 100644 (file)
@@ -10,8 +10,8 @@ import (
        "strings"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -43,7 +43,7 @@ func TestAPIAdminOrgCreate(t *testing.T) {
                assert.Equal(t, org.Location, apiOrg.Location)
                assert.Equal(t, org.Visibility, apiOrg.Visibility)
 
-               unittest.AssertExistsAndLoadBean(t, &models.User{
+               unittest.AssertExistsAndLoadBean(t, &user_model.User{
                        Name:      org.UserName,
                        LowerName: strings.ToLower(org.UserName),
                        FullName:  org.FullName,
index 86a3784b175adb43a5058b62548fc5b1d17731c3..98270ed587599e4b03ede692c03706ccefc13b46 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/json"
        api "code.gitea.io/gitea/modules/structs"
 
@@ -21,7 +22,7 @@ func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) {
        defer prepareTestEnv(t)()
        // user1 is an admin user
        session := loginUser(t, "user1")
-       keyOwner := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
+       keyOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user2"}).(*user_model.User)
 
        token := getTokenForLoggedInUser(t, session)
        urlStr := fmt.Sprintf("/api/v1/admin/users/%s/keys?token=%s", keyOwner.Name, token)
@@ -128,7 +129,7 @@ func TestAPIListUsers(t *testing.T) {
                }
        }
        assert.True(t, found)
-       numberOfUsers := unittest.GetCount(t, &models.User{}, "type = 0")
+       numberOfUsers := unittest.GetCount(t, &user_model.User{}, "type = 0")
        assert.Equal(t, numberOfUsers, len(users))
 }
 
@@ -194,7 +195,7 @@ func TestAPIEditUser(t *testing.T) {
        json.Unmarshal(resp.Body.Bytes(), &errMap)
        assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string))
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"}).(*user_model.User)
        assert.False(t, user2.IsRestricted)
        bTrue := true
        req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
@@ -205,6 +206,6 @@ func TestAPIEditUser(t *testing.T) {
                Restricted: &bTrue,
        })
        session.MakeRequest(t, req, http.StatusOK)
-       user2 = unittest.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User)
+       user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"}).(*user_model.User)
        assert.True(t, user2.IsRestricted)
 }
index cf26fa0e16a5c2fa97619661cce619bcaf8aa9f6..9ab97c0f40d00dc1507d0eb703f95413ce5eb56a 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
 
@@ -25,7 +26,7 @@ func TestAPIListRepoComments(t *testing.T) {
                unittest.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
-       repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, repoOwner.Name)
        link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments", repoOwner.Name, repo.Name))
@@ -71,7 +72,7 @@ func TestAPIListIssueComments(t *testing.T) {
                unittest.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
-       repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, repoOwner.Name)
        req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments",
@@ -91,7 +92,7 @@ func TestAPICreateComment(t *testing.T) {
 
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{}).(*models.Issue)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
-       repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, repoOwner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -114,7 +115,7 @@ func TestAPIGetComment(t *testing.T) {
        comment := unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 2}).(*models.Comment)
        assert.NoError(t, comment.LoadIssue())
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: comment.Issue.RepoID}).(*models.Repository)
-       repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, repoOwner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -143,7 +144,7 @@ func TestAPIEditComment(t *testing.T) {
                unittest.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
-       repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, repoOwner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -168,7 +169,7 @@ func TestAPIDeleteComment(t *testing.T) {
                unittest.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
-       repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, repoOwner.Name)
        token := getTokenForLoggedInUser(t, session)
index 9e569c85a2bf1e3350bdf9090a49872331dcd0fe..9ee8b75b50816fa470fdf7e6588292de85427b50 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -21,7 +22,7 @@ func TestAPIModifyLabels(t *testing.T) {
        assert.NoError(t, unittest.LoadFixtures())
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
        urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/labels?token=%s", owner.Name, repo.Name, token)
@@ -93,7 +94,7 @@ func TestAPIAddIssueLabels(t *testing.T) {
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
        _ = unittest.AssertExistsAndLoadBean(t, &models.Label{RepoID: repo.ID, ID: 2}).(*models.Label)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -116,7 +117,7 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
        label := unittest.AssertExistsAndLoadBean(t, &models.Label{RepoID: repo.ID}).(*models.Label)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -140,7 +141,7 @@ func TestAPIModifyOrgLabels(t *testing.T) {
        assert.NoError(t, unittest.LoadFixtures())
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        user := "user1"
        session := loginUser(t, user)
        token := getTokenForLoggedInUser(t, session)
index 1ac3fb2ed834a1d8da9907c6cadd9b9ede5bc016..6a94321d3b1e4f2b291765b9518c3056c9a6326e 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -21,7 +22,7 @@ func TestAPIIssuesMilestone(t *testing.T) {
 
        milestone := unittest.AssertExistsAndLoadBean(t, &models.Milestone{ID: 1}).(*models.Milestone)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: milestone.RepoID}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        assert.Equal(t, int64(1), int64(milestone.NumIssues))
        assert.Equal(t, structs.StateOpen, milestone.State())
 
index 7b3632ca672374671f8c2eabcc2197e4ac728035..fa0f016ef2cd4735689687b83612dfaee7679fbb 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
 
@@ -23,12 +24,12 @@ func TestAPIIssuesReactions(t *testing.T) {
 
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
        _ = issue.LoadRepo()
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/reactions?token=%s",
                owner.Name, issue.Repo.Name, issue.Index, token)
 
@@ -82,13 +83,13 @@ func TestAPICommentReactions(t *testing.T) {
        _ = comment.LoadIssue()
        issue := comment.Issue
        _ = issue.LoadRepo()
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
 
-       user1 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/reactions?token=%s",
                owner.Name, issue.Repo.Name, comment.ID, token)
 
index 92822ed8117b2ca6818b43a2a8dcc39e6f97a999..8b9af3f0c0b3dddbf5bdbe5a3487a6f619f027d6 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -19,7 +20,7 @@ func TestAPIListStopWatches(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -44,8 +45,8 @@ func TestAPIStopStopWatches(t *testing.T) {
 
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
        _ = issue.LoadRepo()
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -60,8 +61,8 @@ func TestAPICancelStopWatches(t *testing.T) {
 
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
        _ = issue.LoadRepo()
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -76,8 +77,8 @@ func TestAPIStartStopWatches(t *testing.T) {
 
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
        _ = issue.LoadRepo()
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
index dd8e4311496ce6e1113f270a7b836c67e2f169ec..18ff4159b6812d4c858598dce17b35c6bd05dc3f 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -25,7 +26,7 @@ func TestAPIIssueSubscriptions(t *testing.T) {
        issue4 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 4}).(*models.Issue)
        issue5 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 8}).(*models.Issue)
 
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: issue1.PosterID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue1.PosterID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
index a46cba599097b2bec429225b5eb30c2a11d39b81..87bec7a8f3e7e25214a356b30103eccd08d2c115 100644 (file)
@@ -13,6 +13,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -22,7 +23,7 @@ func TestAPIListIssues(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -73,7 +74,7 @@ func TestAPICreateIssue(t *testing.T) {
        const body, title = "apiTestBody", "apiTestTitle"
 
        repoBefore := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repoBefore.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -106,7 +107,7 @@ func TestAPIEditIssue(t *testing.T) {
 
        issueBefore := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
        repoBefore := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: issueBefore.RepoID}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repoBefore.OwnerID}).(*user_model.User)
        assert.NoError(t, issueBefore.LoadAttributes())
        assert.Equal(t, int64(1019307200), int64(issueBefore.DeadlineUnix))
        assert.Equal(t, api.StateOpen, issueBefore.State())
index bcaa0213c8ee0a04618e7c691ddb156f03cc924a..94e569113c160130193b9d2cb4124abfce4dac7e 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -20,7 +21,7 @@ import (
 func TestAPIGetTrackedTimes(t *testing.T) {
        defer prepareTestEnv(t)()
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        issue2 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
        assert.NoError(t, issue2.LoadRepo())
 
@@ -41,7 +42,7 @@ func TestAPIGetTrackedTimes(t *testing.T) {
                assert.EqualValues(t, issue2.ID, apiTimes[i].IssueID)
                assert.Equal(t, time.Created.Unix(), apiTimes[i].Created.Unix())
                assert.Equal(t, time.Time, apiTimes[i].Time)
-               user, err := models.GetUserByID(time.UserID)
+               user, err := user_model.GetUserByID(time.UserID)
                assert.NoError(t, err)
                assert.Equal(t, user.Name, apiTimes[i].UserName)
        }
@@ -65,7 +66,7 @@ func TestAPIDeleteTrackedTime(t *testing.T) {
        time6 := unittest.AssertExistsAndLoadBean(t, &models.TrackedTime{ID: 6}).(*models.TrackedTime)
        issue2 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
        assert.NoError(t, issue2.LoadRepo())
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        session := loginUser(t, user2.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -99,8 +100,8 @@ func TestAPIAddTrackedTimes(t *testing.T) {
 
        issue2 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
        assert.NoError(t, issue2.LoadRepo())
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
-       admin := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        session := loginUser(t, admin.Name)
        token := getTokenForLoggedInUser(t, session)
index 244ece56cc5d7d187cd9961bac68402e64e9099f..7c82bfbb69c1b2f6b4113d31e3100120fef6d243 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -47,7 +48,7 @@ func TestDeleteDeployKeyNoLogin(t *testing.T) {
 func TestCreateReadOnlyDeployKey(t *testing.T) {
        defer prepareTestEnv(t)()
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{Name: "repo1"}).(*models.Repository)
-       repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, repoOwner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -73,7 +74,7 @@ func TestCreateReadOnlyDeployKey(t *testing.T) {
 func TestCreateReadWriteDeployKey(t *testing.T) {
        defer prepareTestEnv(t)()
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{Name: "repo1"}).(*models.Repository)
-       repoOwner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, repoOwner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -97,7 +98,7 @@ func TestCreateReadWriteDeployKey(t *testing.T) {
 
 func TestCreateUserKey(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user1"}).(*user_model.User)
 
        session := loginUser(t, "user1")
        token := url.QueryEscape(getTokenForLoggedInUser(t, session))
index 24d17173ac3dc3574762acc060b824a0decf6116..182e9829cb81f1131e17272e8e2dbdd65ee51b78 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -19,7 +20,7 @@ import (
 func TestAPINotification(t *testing.T) {
        defer prepareTestEnv(t)()
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
        assert.NoError(t, thread5.LoadAttributes())
index d84477ace5c226cd62fdf1728aff48cb3cacfe65..52922b98485cd2f061e05f05597712ae3ad4a9dc 100644 (file)
@@ -9,9 +9,9 @@ import (
        "net/http"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/login"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -27,7 +27,7 @@ func TestOAuth2Application(t *testing.T) {
 }
 
 func testAPICreateOAuth2Application(t *testing.T) {
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        appBody := api.CreateOAuth2ApplicationOptions{
                Name: "test-app-1",
                RedirectURIs: []string{
@@ -51,7 +51,7 @@ func testAPICreateOAuth2Application(t *testing.T) {
 }
 
 func testAPIListOAuth2Applications(t *testing.T) {
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
 
@@ -80,7 +80,7 @@ func testAPIListOAuth2Applications(t *testing.T) {
 }
 
 func testAPIDeleteOAuth2Application(t *testing.T) {
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
 
@@ -101,7 +101,7 @@ func testAPIDeleteOAuth2Application(t *testing.T) {
 }
 
 func testAPIGetOAuth2Application(t *testing.T) {
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
 
@@ -131,7 +131,7 @@ func testAPIGetOAuth2Application(t *testing.T) {
 }
 
 func testAPIUpdateOAuth2Application(t *testing.T) {
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        existApp := unittest.AssertExistsAndLoadBean(t, &login.OAuth2Application{
                UID:  user.ID,
index ced78d7ee95b366ea066dae9ed581348865590d7..76979c674dc20f1eb5ea9b8f399b4952f6e2386b 100644 (file)
@@ -10,8 +10,8 @@ import (
        "strings"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
 
@@ -44,7 +44,7 @@ func TestAPIOrgCreate(t *testing.T) {
                assert.Equal(t, org.Location, apiOrg.Location)
                assert.Equal(t, org.Visibility, apiOrg.Visibility)
 
-               unittest.AssertExistsAndLoadBean(t, &models.User{
+               unittest.AssertExistsAndLoadBean(t, &user_model.User{
                        Name:      org.UserName,
                        LowerName: strings.ToLower(org.UserName),
                        FullName:  org.FullName,
index 060eb16d89c80edc2b6207ac2774693b46a7f4d7..db53d415993e2df53d25579ec193fdfb4c6ff1d0 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/services/forms"
@@ -22,7 +23,7 @@ import (
 func TestAPIViewPulls(t *testing.T) {
        defer prepareTestEnv(t)()
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, "user2")
        token := getTokenForLoggedInUser(t, session)
@@ -39,7 +40,7 @@ func TestAPIViewPulls(t *testing.T) {
 func TestAPIMergePullWIP(t *testing.T) {
        defer prepareTestEnv(t)()
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{Status: models.PullRequestStatusMergeable}, unittest.Cond("has_merged = ?", false)).(*models.PullRequest)
        pr.LoadIssue()
        issue_service.ChangeTitle(pr.Issue, owner, setting.Repository.PullRequest.WorkInProgressPrefixes[0]+" "+pr.Issue.Title)
@@ -65,8 +66,8 @@ func TestAPICreatePullSuccess(t *testing.T) {
        // repo10 have code, pulls units.
        repo11 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
        // repo11 only have code unit but should still create pulls
-       owner10 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
-       owner11 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
+       owner10 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo10.OwnerID}).(*user_model.User)
+       owner11 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo11.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner11.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -83,10 +84,10 @@ func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
        defer prepareTestEnv(t)()
        // repo10 have code, pulls units.
        repo10 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
-       owner10 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
+       owner10 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo10.OwnerID}).(*user_model.User)
        // repo11 only have code unit but should still create pulls
        repo11 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
-       owner11 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
+       owner11 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo11.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner11.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -120,10 +121,10 @@ func TestAPICreatePullWithFieldsFailure(t *testing.T) {
        defer prepareTestEnv(t)()
        // repo10 have code, pulls units.
        repo10 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
-       owner10 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
+       owner10 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo10.OwnerID}).(*user_model.User)
        // repo11 only have code unit but should still create pulls
        repo11 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
-       owner11 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
+       owner11 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo11.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner11.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -153,7 +154,7 @@ func TestAPICreatePullWithFieldsFailure(t *testing.T) {
 func TestAPIEditPull(t *testing.T) {
        defer prepareTestEnv(t)()
        repo10 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
-       owner10 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
+       owner10 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo10.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner10.Name)
        token := getTokenForLoggedInUser(t, session)
index ac2beb7bdf3beba5bf1d434574f7d3145fcc633b..5a16e60d735edd57f594872e4dd77e84f6640183 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        api "code.gitea.io/gitea/modules/structs"
 
@@ -22,7 +23,7 @@ func TestAPIListReleases(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        session := loginUser(t, user2.LowerName)
        token := getTokenForLoggedInUser(t, session)
 
@@ -70,7 +71,7 @@ func TestAPIListReleases(t *testing.T) {
        testFilterByLen(true, url.Values{"draft": {"true"}, "pre-release": {"true"}}, 0, "there is no pre-release draft")
 }
 
-func createNewReleaseUsingAPI(t *testing.T, session *TestSession, token string, owner *models.User, repo *models.Repository, name, target, title, desc string) *api.Release {
+func createNewReleaseUsingAPI(t *testing.T, session *TestSession, token string, owner *user_model.User, repo *models.Repository, name, target, title, desc string) *api.Release {
        urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/releases?token=%s",
                owner.Name, repo.Name, token)
        req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateReleaseOption{
@@ -99,7 +100,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        session := loginUser(t, owner.LowerName)
        token := getTokenForLoggedInUser(t, session)
 
@@ -150,7 +151,7 @@ func TestAPICreateReleaseToDefaultBranch(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        session := loginUser(t, owner.LowerName)
        token := getTokenForLoggedInUser(t, session)
 
@@ -161,7 +162,7 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        session := loginUser(t, owner.LowerName)
        token := getTokenForLoggedInUser(t, session)
 
@@ -179,7 +180,7 @@ func TestAPIGetReleaseByTag(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        session := loginUser(t, owner.LowerName)
 
        tag := "v1.1"
@@ -212,7 +213,7 @@ func TestAPIDeleteReleaseByTagName(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        session := loginUser(t, owner.LowerName)
        token := getTokenForLoggedInUser(t, session)
 
index 77940f4c360dd5d035b9e447095860c1550f5130..6de61eea9f9803d9d647639382c25a31b6d8f101 100644 (file)
@@ -13,6 +13,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -21,7 +22,7 @@ func TestAPIDownloadArchive(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        session := loginUser(t, user2.LowerName)
        token := getTokenForLoggedInUser(t, session)
 
index f862afa2c3f9cac6bd430749d12da10778ddcec0..defa86fca8c8e121e935e035acf0aea0dbf87222 100644 (file)
@@ -13,6 +13,7 @@ import (
        "code.gitea.io/gitea/models"
        unit_model "code.gitea.io/gitea/models/unit"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -134,9 +135,9 @@ func TestAPIRepoEdit(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, u *url.URL) {
                bFalse, bTrue := false, true
 
-               user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)               // owner of the repo1 & repo16
-               user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)               // owner of the repo3, is an org
-               user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)               // owner of neither repos
+               user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)       // owner of the repo1 & repo16
+               user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)       // owner of the repo3, is an org
+               user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)       // owner of neither repos
                repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)   // public repo
                repo3 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)   // public repo
                repo15 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 15}).(*models.Repository) // empty repo
index 07ddbbbfe6ef3012f464629e1bf3de9d955f8267..5092b8095b832516f81aa09b6d3b2b35abd1a4fd 100644 (file)
@@ -15,6 +15,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/setting"
@@ -109,7 +110,7 @@ func getExpectedFileResponseForCreate(commitID, treePath string) *api.FileRespon
 func BenchmarkAPICreateFileSmall(b *testing.B) {
        onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
                b := t.(*testing.B)
-               user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)             // owner of the repo1 & repo16
+               user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)     // owner of the repo1 & repo16
                repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
 
                for n := 0; n < b.N; n++ {
@@ -124,7 +125,7 @@ func BenchmarkAPICreateFileMedium(b *testing.B) {
 
        onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
                b := t.(*testing.B)
-               user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)             // owner of the repo1 & repo16
+               user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)     // owner of the repo1 & repo16
                repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
 
                b.ResetTimer()
@@ -138,9 +139,9 @@ func BenchmarkAPICreateFileMedium(b *testing.B) {
 
 func TestAPICreateFile(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, u *url.URL) {
-               user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)               // owner of the repo1 & repo16
-               user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)               // owner of the repo3, is an org
-               user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)               // owner of neither repos
+               user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)       // owner of the repo1 & repo16
+               user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)       // owner of the repo3, is an org
+               user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)       // owner of neither repos
                repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)   // public repo
                repo3 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)   // public repo
                repo16 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
index 93da12700d8d72ef6a21e5bca28ac78383cad41d..0a87c09242836a60b05b0e682061f448f6fe4c20 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -38,9 +39,9 @@ func getDeleteFileOptions() *api.DeleteFileOptions {
 
 func TestAPIDeleteFile(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, u *url.URL) {
-               user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)               // owner of the repo1 & repo16
-               user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)               // owner of the repo3, is an org
-               user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)               // owner of neither repos
+               user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)       // owner of the repo1 & repo16
+               user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)       // owner of the repo3, is an org
+               user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)       // owner of neither repos
                repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)   // public repo
                repo3 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)   // public repo
                repo16 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
index ef3b8c610bbb1d6c8d73ea98a3b245f556385486..8477d65a3ed4f9c5b6b73198c3f7d300693eb017 100644 (file)
@@ -6,11 +6,12 @@ package integrations
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
        files_service "code.gitea.io/gitea/services/repository/files"
 )
 
-func createFileInBranch(user *models.User, repo *models.Repository, treePath, branchName, content string) (*api.FileResponse, error) {
+func createFileInBranch(user *user_model.User, repo *models.Repository, treePath, branchName, content string) (*api.FileResponse, error) {
        opts := &files_service.UpdateRepoFileOptions{
                OldBranch: branchName,
                TreePath:  treePath,
@@ -22,6 +23,6 @@ func createFileInBranch(user *models.User, repo *models.Repository, treePath, br
        return files_service.CreateOrUpdateRepoFile(repo, user, opts)
 }
 
-func createFile(user *models.User, repo *models.Repository, treePath string) (*api.FileResponse, error) {
+func createFile(user *user_model.User, repo *models.Repository, treePath string) (*api.FileResponse, error) {
        return createFileInBranch(user, repo, treePath, repo.DefaultBranch, "This is a NEW file")
 }
index fb554efe7abf11824b6b1e48448ea6bfa7bc3be9..1fc84d5dea1e654d94ee3053c8c1d684ed492951 100644 (file)
@@ -14,6 +14,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/setting"
@@ -104,9 +105,9 @@ func getExpectedFileResponseForUpdate(commitID, treePath string) *api.FileRespon
 
 func TestAPIUpdateFile(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, u *url.URL) {
-               user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)               // owner of the repo1 & repo16
-               user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)               // owner of the repo3, is an org
-               user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)               // owner of neither repos
+               user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)       // owner of the repo1 & repo16
+               user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)       // owner of the repo3, is an org
+               user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)       // owner of neither repos
                repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)   // public repo
                repo3 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)   // public repo
                repo16 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
index abcfc1fd82907fd78be1764d5d6eee77eadd8158..63ac9cfb5306bb15b3e6b6b582218251d7345f88 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
@@ -53,9 +54,9 @@ func TestAPIGetContentsList(t *testing.T) {
 
 func testAPIGetContentsList(t *testing.T, u *url.URL) {
        /*** SETUP ***/
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)               // owner of the repo1 & repo16
-       user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)               // owner of the repo3, is an org
-       user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)               // owner of neither repos
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)       // owner of the repo1 & repo16
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)       // owner of the repo3, is an org
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)       // owner of neither repos
        repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)   // public repo
        repo3 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)   // public repo
        repo16 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
index 00fef78b8874cc168be78450dd033ed5f6dde255..9843239ec4a70875e0f39334a7faf24be064f7fe 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
@@ -54,9 +55,9 @@ func TestAPIGetContents(t *testing.T) {
 
 func testAPIGetContents(t *testing.T, u *url.URL) {
        /*** SETUP ***/
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)               // owner of the repo1 & repo16
-       user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)               // owner of the repo3, is an org
-       user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)               // owner of neither repos
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)       // owner of the repo1 & repo16
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)       // owner of the repo3, is an org
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)       // owner of neither repos
        repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)   // public repo
        repo3 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)   // public repo
        repo16 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
index 53c266e9f9703d2d8bc4e74c42d02b8be86a715f..0311b6120f280463c62a6bbab6bbebdccd48de62 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -17,9 +18,9 @@ import (
 
 func TestAPIReposGitBlobs(t *testing.T) {
        defer prepareTestEnv(t)()
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)               // owner of the repo1 & repo16
-       user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)               // owner of the repo3
-       user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)               // owner of neither repos
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)       // owner of the repo1 & repo16
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)       // owner of the repo3
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)       // owner of neither repos
        repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)   // public repo
        repo3 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)   // public repo
        repo16 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
index 627f563dafe621b18fff4d07eb944c254792020a..1e138eb9152fc04c89f94c530a863760e5f2f598 100644 (file)
@@ -8,8 +8,8 @@ import (
        "net/http"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -25,7 +25,7 @@ func compareCommitFiles(t *testing.T, expect []string, files []*api.CommitAffect
 
 func TestAPIReposGitCommits(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        // Login as User2.
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -53,7 +53,7 @@ func TestAPIReposGitCommits(t *testing.T) {
 
 func TestAPIReposGitCommitList(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        // Login as User2.
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -76,7 +76,7 @@ func TestAPIReposGitCommitList(t *testing.T) {
 
 func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        // Login as User2.
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -93,7 +93,7 @@ func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
 
 func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        // Login as User2.
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -112,7 +112,7 @@ func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
 
 func TestDownloadCommitDiffOrPatch(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        // Login as User2.
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
index f9cfdf44934c2f793415cb42c6e970ab48832ae1..ee59321761afb9f3170a39212f723d57da240b5e 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -25,7 +26,7 @@ func TestAPIListGitHooks(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        // user1 is an admin user
        session := loginUser(t, "user1")
@@ -51,7 +52,7 @@ func TestAPIListGitHooksNoHooks(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        // user1 is an admin user
        session := loginUser(t, "user1")
@@ -72,7 +73,7 @@ func TestAPIListGitHooksNoAccess(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -85,7 +86,7 @@ func TestAPIGetGitHook(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        // user1 is an admin user
        session := loginUser(t, "user1")
@@ -103,7 +104,7 @@ func TestAPIGetGitHookNoAccess(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -116,7 +117,7 @@ func TestAPIEditGitHook(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        // user1 is an admin user
        session := loginUser(t, "user1")
@@ -146,7 +147,7 @@ func TestAPIEditGitHookNoAccess(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -162,7 +163,7 @@ func TestAPIDeleteGitHook(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        // user1 is an admin user
        session := loginUser(t, "user1")
@@ -185,7 +186,7 @@ func TestAPIDeleteGitHookNoAccess(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        token := getTokenForLoggedInUser(t, session)
index 293bd769f43ec5ea2dd4c7bc8ecfe778d4f4374c..08b885bd2fc9e2f648042f0d6511033929934bf8 100644 (file)
@@ -9,8 +9,8 @@ import (
        "net/url"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -18,7 +18,7 @@ import (
 
 func TestAPIReposGitNotes(t *testing.T) {
        onGiteaRun(t, func(*testing.T, *url.URL) {
-               user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+               user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
                // Login as User2.
                session := loginUser(t, user.Name)
                token := getTokenForLoggedInUser(t, session)
index 9137f03adf285e0cba15dead3a6913db6a4ee11d..f0fc3c81fa2a9de2005d6700fe652ad2618ff497 100644 (file)
@@ -8,13 +8,13 @@ import (
        "net/http"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 )
 
 func TestAPIReposGitRefs(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        // Login as User2.
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
index f091286e2c29c5cc154e2452705d8775fdac72f2..73c04531f1991c15d0fe4cf37c9405b0aabb9d74 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/util"
@@ -20,7 +21,7 @@ import (
 
 func TestAPIGitTags(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        // Login as User2.
        session := loginUser(t, user.Name)
@@ -66,7 +67,7 @@ func TestAPIDeleteTagByName(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        session := loginUser(t, owner.LowerName)
        token := getTokenForLoggedInUser(t, session)
 
index 27088156bac6572359d5d50fc2fd3e8ed32a454c..c54d3e3245a23d290fc0c308399b7ab8842cc16a 100644 (file)
@@ -10,13 +10,14 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 )
 
 func TestAPIReposGitTrees(t *testing.T) {
        defer prepareTestEnv(t)()
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)               // owner of the repo1 & repo16
-       user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)               // owner of the repo3
-       user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)               // owner of neither repos
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)       // owner of the repo1 & repo16
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)       // owner of the repo3
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)       // owner of neither repos
        repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)   // public repo
        repo3 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)   // public repo
        repo16 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
index 6a69145589a4e0d40edd2f791e9432f5f185dbeb..f4d1ad124408e66b31f3d44541824f9bb3c734f5 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/lfs"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
@@ -22,7 +23,7 @@ import (
 func TestAPILFSLocksNotStarted(t *testing.T) {
        defer prepareTestEnv(t)()
        setting.LFS.StartServer = false
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
 
        req := NewRequestf(t, "GET", "/%s/%s.git/info/lfs/locks", user.Name, repo.Name)
@@ -38,7 +39,7 @@ func TestAPILFSLocksNotStarted(t *testing.T) {
 func TestAPILFSLocksNotLogin(t *testing.T) {
        defer prepareTestEnv(t)()
        setting.LFS.StartServer = true
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
 
        req := NewRequestf(t, "GET", "/%s/%s.git/info/lfs/locks", user.Name, repo.Name)
@@ -52,14 +53,14 @@ func TestAPILFSLocksNotLogin(t *testing.T) {
 func TestAPILFSLocksLogged(t *testing.T) {
        defer prepareTestEnv(t)()
        setting.LFS.StartServer = true
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) //in org 3
-       user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) //in org 3
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) //in org 3
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User) //in org 3
 
        repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        repo3 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // own by org 3
 
        tests := []struct {
-               user       *models.User
+               user       *user_model.User
                repo       *models.Repository
                path       string
                httpResult int
@@ -81,21 +82,21 @@ func TestAPILFSLocksLogged(t *testing.T) {
        }
 
        resultsTests := []struct {
-               user        *models.User
+               user        *user_model.User
                repo        *models.Repository
                totalCount  int
                oursCount   int
                theirsCount int
-               locksOwners []*models.User
+               locksOwners []*user_model.User
                locksTimes  []time.Time
        }{
-               {user: user2, repo: repo1, totalCount: 4, oursCount: 4, theirsCount: 0, locksOwners: []*models.User{user2, user2, user2, user2}, locksTimes: []time.Time{}},
-               {user: user2, repo: repo3, totalCount: 2, oursCount: 1, theirsCount: 1, locksOwners: []*models.User{user2, user4}, locksTimes: []time.Time{}},
-               {user: user4, repo: repo3, totalCount: 2, oursCount: 1, theirsCount: 1, locksOwners: []*models.User{user2, user4}, locksTimes: []time.Time{}},
+               {user: user2, repo: repo1, totalCount: 4, oursCount: 4, theirsCount: 0, locksOwners: []*user_model.User{user2, user2, user2, user2}, locksTimes: []time.Time{}},
+               {user: user2, repo: repo3, totalCount: 2, oursCount: 1, theirsCount: 1, locksOwners: []*user_model.User{user2, user4}, locksTimes: []time.Time{}},
+               {user: user4, repo: repo3, totalCount: 2, oursCount: 1, theirsCount: 1, locksOwners: []*user_model.User{user2, user4}, locksTimes: []time.Time{}},
        }
 
        deleteTests := []struct {
-               user   *models.User
+               user   *user_model.User
                repo   *models.Repository
                lockID string
        }{}
@@ -143,7 +144,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
                for _, lock := range lfsLocksVerify.Ours {
                        assert.EqualValues(t, test.user.DisplayName(), lock.Owner.Name)
                        deleteTests = append(deleteTests, struct {
-                               user   *models.User
+                               user   *user_model.User
                                repo   *models.Repository
                                lockID string
                        }{test.user, test.repo, lock.ID})
index 2873b425c5e17ea6ba9a69ba03605986ebc712ef..6d41a48529ce6d1efe6b061879e460eee4a69e0f 100644 (file)
@@ -9,8 +9,8 @@ import (
        "path"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/lfs"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
@@ -28,7 +28,7 @@ func TestAPIRepoLFSMigrateLocal(t *testing.T) {
        setting.Migrations.AllowLocalNetworks = true
        assert.NoError(t, migrations.Init())
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
 
index 4addb422c39c181c862896a04122606a06af3488..6f3becf17b1f09d51abf9b80205af36e298f5842 100644 (file)
@@ -14,6 +14,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/json"
        "code.gitea.io/gitea/modules/lfs"
        "code.gitea.io/gitea/modules/setting"
@@ -26,7 +27,7 @@ func TestAPILFSNotStarted(t *testing.T) {
 
        setting.LFS.StartServer = false
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
 
        req := NewRequestf(t, "POST", "/%s/%s.git/info/lfs/objects/batch", user.Name, repo.Name)
@@ -46,7 +47,7 @@ func TestAPILFSMediaType(t *testing.T) {
 
        setting.LFS.StartServer = true
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
 
        req := NewRequestf(t, "POST", "/%s/%s.git/info/lfs/objects/batch", user.Name, repo.Name)
index e7eb60ac56c1eb4e115d640af18efd1e432a7e29..2a77d1ba630dced4bbefe6a2628971e853def99b 100644 (file)
@@ -8,13 +8,13 @@ import (
        "net/http"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 )
 
 func TestAPIReposRaw(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        // Login as User2.
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
index 79a2880bcf5454074f3d6dd0f6cd8f755ad7b3b8..c076bb42edf1354edfd80b601587f3f001ad5911 100644 (file)
@@ -9,8 +9,8 @@ import (
        "net/http"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
 
@@ -19,7 +19,7 @@ import (
 
 func TestAPIRepoTags(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        // Login as User2.
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
index 59025e0e53e6effca7cd8539c1b5cff1b334d6d7..ca1e33eabf247721aa40fbc066a7ff4287f7f47a 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -22,7 +23,7 @@ func TestAPIRepoTeams(t *testing.T) {
        // publicOrgRepo = user3/repo21
        publicOrgRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 32}).(*models.Repository)
        // user4
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
 
@@ -62,7 +63,7 @@ func TestAPIRepoTeams(t *testing.T) {
        session.MakeRequest(t, req, http.StatusForbidden)
 
        // AddTeam with user2
-       user = unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        session = loginUser(t, user.Name)
        token = getTokenForLoggedInUser(t, session)
        url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "team1", token)
index 8de020d0748d9acfd4253b6f47324eb8e20f251b..b07416a5bffd5d82b3372921f2419b2710d56ba0 100644 (file)
@@ -13,6 +13,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/util"
@@ -22,7 +23,7 @@ import (
 
 func TestAPIUserReposNotLogin(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        req := NewRequestf(t, "GET", "/api/v1/users/%s/repos", user.Name)
        resp := MakeRequest(t, req, http.StatusOK)
@@ -53,11 +54,11 @@ func TestAPISearchRepo(t *testing.T) {
                assert.False(t, repo.Private)
        }
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 15}).(*models.User)
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 16}).(*models.User)
-       user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 18}).(*models.User)
-       user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 20}).(*models.User)
-       orgUser := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 17}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 15}).(*user_model.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 16}).(*user_model.User)
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 18}).(*user_model.User)
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 20}).(*user_model.User)
+       orgUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 17}).(*user_model.User)
 
        oldAPIDefaultNum := setting.API.DefaultPagingNum
        defer func() {
@@ -66,7 +67,7 @@ func TestAPISearchRepo(t *testing.T) {
        setting.API.DefaultPagingNum = 10
 
        // Map of expected results, where key is user for login
-       type expectedResults map[*models.User]struct {
+       type expectedResults map[*user_model.User]struct {
                count           int
                repoOwnerID     int64
                repoName        string
@@ -246,13 +247,13 @@ func TestAPIViewRepo(t *testing.T) {
 
 func TestAPIOrgRepos(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
-       user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
        // User3 is an Org. Check their repos.
-       sourceOrg := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
+       sourceOrg := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
 
-       expectedResults := map[*models.User]struct {
+       expectedResults := map[*user_model.User]struct {
                count           int
                includesPrivate bool
        }{
@@ -292,7 +293,7 @@ func TestAPIOrgRepos(t *testing.T) {
 
 func TestAPIGetRepoByIDUnauthorized(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
        req := NewRequestf(t, "GET", "/api/v1/repositories/2?token="+token)
@@ -316,7 +317,7 @@ func TestAPIRepoMigrate(t *testing.T) {
 
        defer prepareTestEnv(t)()
        for _, testCase := range testCases {
-               user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
+               user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: testCase.ctxUserID}).(*user_model.User)
                session := loginUser(t, user.Name)
                token := getTokenForLoggedInUser(t, session)
                req := NewRequestWithJSON(t, "POST", "/api/v1/repos/migrate?token="+token, &api.MigrateRepoOptions{
@@ -361,7 +362,7 @@ func testAPIRepoMigrateConflict(t *testing.T, u *url.URL) {
                defer util.RemoveAll(dstPath)
                t.Run("CreateRepo", doAPICreateRepository(httpContext, false))
 
-               user, err := models.GetUserByName(httpContext.Username)
+               user, err := user_model.GetUserByName(httpContext.Username)
                assert.NoError(t, err)
                userID := user.ID
 
@@ -395,7 +396,7 @@ func TestAPIOrgRepoCreate(t *testing.T) {
 
        defer prepareTestEnv(t)()
        for _, testCase := range testCases {
-               user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
+               user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: testCase.ctxUserID}).(*user_model.User)
                session := loginUser(t, user.Name)
                token := getTokenForLoggedInUser(t, session)
                req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/org/%s/repos?token="+token, testCase.orgName), &api.CreateRepoOption{
@@ -463,7 +464,7 @@ func TestAPIRepoTransfer(t *testing.T) {
        defer prepareTestEnv(t)()
 
        //create repo to move
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
        repoName := "moveME"
@@ -480,7 +481,7 @@ func TestAPIRepoTransfer(t *testing.T) {
 
        //start testing
        for _, testCase := range testCases {
-               user = unittest.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
+               user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: testCase.ctxUserID}).(*user_model.User)
                repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: apiRepo.ID}).(*models.Repository)
                session = loginUser(t, user.Name)
                token = getTokenForLoggedInUser(t, session)
@@ -499,7 +500,7 @@ func TestAPIRepoTransfer(t *testing.T) {
 func TestAPIGenerateRepo(t *testing.T) {
        defer prepareTestEnv(t)()
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
 
@@ -535,7 +536,7 @@ func TestAPIGenerateRepo(t *testing.T) {
 
 func TestAPIRepoGetReviewers(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
@@ -549,7 +550,7 @@ func TestAPIRepoGetReviewers(t *testing.T) {
 
 func TestAPIRepoGetAssignees(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
index 05f025d94610e806c9041cba84e5b705aaed8b7b..572099b7d72f8c49edf49aef895afcdc8053b35c 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -51,9 +52,9 @@ func TestAPITopicSearch(t *testing.T) {
 
 func TestAPIRepoTopic(t *testing.T) {
        defer prepareTestEnv(t)()
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of repo2
-       user3 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of repo3
-       user4 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // write access to repo 3
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) // owner of repo2
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User) // owner of repo3
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User) // write access to repo 3
        repo2 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
        repo3 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
 
index 26d6c884b49f7d47f4fcb5d1a81ee95d3eceaae8..da22d404797603f9163968b705e8b55f248214eb 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
 
@@ -23,7 +24,7 @@ func TestAPITeam(t *testing.T) {
 
        teamUser := unittest.AssertExistsAndLoadBean(t, &models.TeamUser{}).(*models.TeamUser)
        team := unittest.AssertExistsAndLoadBean(t, &models.Team{ID: teamUser.TeamID}).(*models.Team)
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: teamUser.UID}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: teamUser.UID}).(*user_model.User)
 
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -37,7 +38,7 @@ func TestAPITeam(t *testing.T) {
 
        // non team member user will not access the teams details
        teamUser2 := unittest.AssertExistsAndLoadBean(t, &models.TeamUser{ID: 3}).(*models.TeamUser)
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: teamUser2.UID}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: teamUser2.UID}).(*user_model.User)
 
        session = loginUser(t, user2.Name)
        token = getTokenForLoggedInUser(t, session)
@@ -48,11 +49,11 @@ func TestAPITeam(t *testing.T) {
        _ = session.MakeRequest(t, req, http.StatusUnauthorized)
 
        // Get an admin user able to create, update and delete teams.
-       user = unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        session = loginUser(t, user.Name)
        token = getTokenForLoggedInUser(t, session)
 
-       org := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 6}).(*models.User)
+       org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 6}).(*user_model.User)
 
        // Create team.
        teamToCreate := &api.CreateTeamOption{
@@ -139,8 +140,8 @@ type TeamSearchResults struct {
 func TestAPITeamSearch(t *testing.T) {
        defer prepareTestEnv(t)()
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
-       org := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
 
        var results TeamSearchResults
 
@@ -155,7 +156,7 @@ func TestAPITeamSearch(t *testing.T) {
        assert.Equal(t, "test_team", results.Data[0].Name)
 
        // no access if not organization member
-       user5 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+       user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
        session = loginUser(t, user5.Name)
        csrf = GetCSRF(t, session, "/"+org.Name)
        req = NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s", org.Name, "team")
index e7f4b0ee4c94b6e1fff38b4e94deffb3cc883087..7263408bee56f97bb798a1ea3d6b7acbf2708478 100644 (file)
@@ -9,8 +9,8 @@ import (
        "testing"
        "time"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
 
@@ -31,7 +31,7 @@ func TestAPITeamUser(t *testing.T) {
        var user2 *api.User
        DecodeJSON(t, resp, &user2)
        user2.Created = user2.Created.In(time.Local)
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user2"}).(*user_model.User)
 
        expectedUser := convert.ToUser(user, user)
 
index 8314d5b636ff663081f5436de41529862883f0a6..aca4768503c9c28f8f1c37401f6b9a161eb5b7c4 100644 (file)
@@ -10,13 +10,14 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 )
 
 // TestAPICreateAndDeleteToken tests that token that was just created can be deleted
 func TestAPICreateAndDeleteToken(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        req := NewRequestWithJSON(t, "POST", "/api/v1/users/user1/tokens", map[string]string{
                "name": "test-key-1",
@@ -56,7 +57,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
 // TestAPIDeleteMissingToken ensures that error is thrown when token not found
 func TestAPIDeleteMissingToken(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        req := NewRequestf(t, "DELETE", "/api/v1/users/user1/tokens/%d", unittest.NonexistentID)
        req = AddBasicAuthHeader(req, user.Name)
index 5bc5df118f8a413e53a85a10b1b347d8538f99fd..09272726f663e8178c81286f8e0f8c2ef68eaabe 100644 (file)
@@ -9,8 +9,8 @@ import (
        "net/http"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -25,7 +25,7 @@ func TestUserOrgs(t *testing.T) {
 
        orgs := getUserOrgs(t, adminUsername, normalUsername)
 
-       user3 := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"}).(*user_model.User)
 
        assert.Equal(t, []*api.Organization{
                {
@@ -81,7 +81,7 @@ func TestMyOrgs(t *testing.T) {
        resp := session.MakeRequest(t, req, http.StatusOK)
        var orgs []*api.Organization
        DecodeJSON(t, resp, &orgs)
-       user3 := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"}).(*user_model.User)
 
        assert.Equal(t, []*api.Organization{
                {
index 67dc2f1cac40deeea411bc0873d7f9adbd867680..41f14cf944f336df829bd49d6c7acfa4d1862747 100644 (file)
@@ -9,8 +9,8 @@ import (
        "net/http"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
 
@@ -49,10 +49,10 @@ func TestAPIUserSearchNotLoggedIn(t *testing.T) {
        var results SearchResults
        DecodeJSON(t, resp, &results)
        assert.NotEmpty(t, results.Data)
-       var modelUser *models.User
+       var modelUser *user_model.User
        for _, user := range results.Data {
                assert.Contains(t, user.UserName, query)
-               modelUser = unittest.AssertExistsAndLoadBean(t, &models.User{ID: user.ID}).(*models.User)
+               modelUser = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: user.ID}).(*user_model.User)
                if modelUser.KeepEmailPrivate {
                        assert.EqualValues(t, fmt.Sprintf("%s@%s", modelUser.LowerName, setting.Service.NoReplyAddress), user.Email)
                } else {
index d691e48e00a40d3378aabcf188ca7730fe48e895..3b79e5032d9c00734957d3000c1e16cd1d7ef50c 100644 (file)
@@ -11,12 +11,13 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 )
 
 func TestChangeDefaultBranch(t *testing.T) {
        defer prepareTestEnv(t)()
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        session := loginUser(t, owner.Name)
        branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)
index f8efab0a24fac32250adebd2702643b559895f41..385b1822bb0914e7a968c3437816a09d78ed87d1 100644 (file)
@@ -15,7 +15,7 @@ import (
 )
 
 func assertUserDeleted(t *testing.T, userID int64) {
-       unittest.AssertNotExistsBean(t, &models.User{ID: userID})
+       unittest.AssertNotExistsBean(t, &user_model.User{ID: userID})
        unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: userID})
        unittest.AssertNotExistsBean(t, &user_model.Follow{FollowID: userID})
        unittest.AssertNotExistsBean(t, &models.Repository{OwnerID: userID})
@@ -38,7 +38,7 @@ func TestUserDeleteAccount(t *testing.T) {
        session.MakeRequest(t, req, http.StatusFound)
 
        assertUserDeleted(t, 8)
-       unittest.CheckConsistencyFor(t, &models.User{})
+       unittest.CheckConsistencyFor(t, &user_model.User{})
 }
 
 func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
@@ -53,5 +53,5 @@ func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
        session.MakeRequest(t, req, http.StatusFound)
 
        // user should not have been deleted, because the user still owns repos
-       unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2})
+       unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
 }
index cbab67ba1e20a982b5182d1539664db08c3b9b39..70e7aff9aa211fd0e78ef5bb1dcef1f6adcf5054 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 )
 
 func TestEmptyRepo(t *testing.T) {
@@ -21,7 +22,7 @@ func TestEmptyRepo(t *testing.T) {
                "graph",
        }
        emptyRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{}, unittest.Cond("is_empty = ?", true)).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: emptyRepo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: emptyRepo.OwnerID}).(*user_model.User)
        for _, subpath := range subpaths {
                req := NewRequestf(t, "GET", "/%s/%s/%s", owner.Name, emptyRepo.Name, subpath)
                MakeRequest(t, req, http.StatusNotFound)
index 6c4c87b3d1fcca481697d90ba41e4ec391a5ba95..277f5695a816ea795b8892b170dd6e09cd9842be 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/eventsource"
        api "code.gitea.io/gitea/modules/structs"
 
@@ -51,7 +52,7 @@ func TestEventSourceManagerRun(t *testing.T) {
                }
        }
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
        assert.NoError(t, thread5.LoadAttributes())
index cf84800eed86f55826eb84671bf831f1eb54afef..71e3476abbf7de5d32d9c1f4d81629db39b43eef 100644 (file)
@@ -19,6 +19,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/lfs"
        "code.gitea.io/gitea/modules/setting"
@@ -429,7 +430,7 @@ func doProtectBranch(ctx APITestContext, branch string, userToWhitelist string,
                        })
                        ctx.Session.MakeRequest(t, req, http.StatusFound)
                } else {
-                       user, err := models.GetUserByName(userToWhitelist)
+                       user, err := user_model.GetUserByName(userToWhitelist)
                        assert.NoError(t, err)
                        // Change branch to protected
                        req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/settings/branches/%s", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), url.PathEscape(branch)), map[string]string{
index b136e822810a0d2fbc42b42f4c725b2c8f49fd0b..8478f53c0e94f85eaeb21ca0dbcf6db9a409dba4 100644 (file)
@@ -11,8 +11,8 @@ import (
        "os"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/process"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
@@ -61,7 +61,7 @@ func TestGPGGit(t *testing.T) {
        setting.Repository.Signing.SigningKey = rootKeyID
        setting.Repository.Signing.SigningName = "gitea"
        setting.Repository.Signing.SigningEmail = "gitea@fake.local"
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{Name: username}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: username}).(*user_model.User)
 
        setting.Repository.Signing.InitialCommit = []string{"never"}
        setting.Repository.Signing.CRUDActions = []string{"never"}
@@ -326,7 +326,7 @@ func TestGPGGit(t *testing.T) {
        }, false)
 }
 
-func crudActionCreateFile(t *testing.T, ctx APITestContext, user *models.User, from, to, path string, callback ...func(*testing.T, api.FileResponse)) func(*testing.T) {
+func crudActionCreateFile(t *testing.T, ctx APITestContext, user *user_model.User, from, to, path string, callback ...func(*testing.T, api.FileResponse)) func(*testing.T) {
        return doAPICreateFile(ctx, path, &api.CreateFileOptions{
                FileOptions: api.FileOptions{
                        BranchName:    from,
index ae274749a2709e2e14f7b77c2927dbb833171d54..69998b6f46e002328f4aeeddba45d15446bd8723 100644 (file)
@@ -15,6 +15,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/indexer/issues"
        "code.gitea.io/gitea/modules/references"
        "code.gitea.io/gitea/modules/setting"
@@ -61,7 +62,7 @@ func TestNoLoginViewIssues(t *testing.T) {
 func TestViewIssuesSortByType(t *testing.T) {
        defer prepareTestEnv(t)()
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
 
        session := loginUser(t, user.Name)
index e22da7db907e14d188c0b903c77e241bdd0fd4a0..9b59c85a4eb7e51896ec540e7f0949171c4b8196 100644 (file)
@@ -8,8 +8,8 @@ import (
        "os"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/services/migrations"
 
@@ -19,7 +19,7 @@ import (
 func TestMigrateLocalPath(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       adminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
+       adminUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user1"}).(*user_model.User)
 
        old := setting.ImportLocalPaths
        setting.ImportLocalPaths = true
index aa0f89dd914d6d363093f03246e10abeb7134d1f..fb70fd01706f05f425f6ef0f0701da91153f1c5c 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/migration"
        "code.gitea.io/gitea/modules/repository"
@@ -22,7 +23,7 @@ import (
 func TestMirrorPull(t *testing.T) {
        defer prepareTestEnv(t)()
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        repoPath := models.RepoPath(user.Name, repo.Name)
 
index 492e2c23eef6f10f2a2814590f4df80546eb97a4..d9fa543768daa1d57493d878f89234b37689449a 100644 (file)
@@ -13,6 +13,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/repository"
        "code.gitea.io/gitea/modules/setting"
@@ -32,7 +33,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
        setting.Migrations.AllowLocalNetworks = true
        assert.NoError(t, migrations.Init())
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        srcRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
 
        mirrorRepo, err := repository.CreateRepository(user, user, models.CreateRepoOptions{
index a45d1e81b59e25e57b8a1f7ca7c29bc7df084c5c..b7d0da2f4bd0b4082aa8504e7a8db96de3f84ff0 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -112,9 +113,9 @@ func doCheckOrgCounts(username string, orgCounts map[string]int, strict bool, ca
        }
 
        return func(t *testing.T) {
-               user := unittest.AssertExistsAndLoadBean(t, &models.User{
+               user := unittest.AssertExistsAndLoadBean(t, &user_model.User{
                        Name: username,
-               }).(*models.User)
+               }).(*user_model.User)
 
                orgs, err := models.FindOrgs(models.FindOrgOptions{
                        UserID:         user.ID,
index e45274ad43d522428ea1dc6ddde1cf53729b76fe..72890f611c61b00757f83a2956ad284c5b908600 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -26,7 +27,7 @@ const privateActivityTestOtherUser = "user4"
 
 func testPrivateActivityDoSomethingForActionEntries(t *testing.T) {
        repoBefore := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repoBefore.OwnerID}).(*user_model.User)
 
        session := loginUser(t, privateActivityTestUser)
        token := getTokenForLoggedInUser(t, session)
index 4d5699fa53cd298efcc0b89092f142127b7d9e80..2e219dcc918205810e67ebf467d95f5dda2db1ea 100644 (file)
@@ -18,6 +18,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/models/webhook"
        "code.gitea.io/gitea/modules/git"
        api "code.gitea.io/gitea/modules/structs"
@@ -221,9 +222,9 @@ func TestCantMergeConflict(t *testing.T) {
                session.MakeRequest(t, req, 201)
 
                // Now this PR will be marked conflict - or at least a race will do - so drop down to pure code at this point...
-               user1 := unittest.AssertExistsAndLoadBean(t, &models.User{
+               user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{
                        Name: "user1",
-               }).(*models.User)
+               }).(*user_model.User)
                repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{
                        OwnerID: user1.ID,
                        Name:    "repo1",
@@ -258,9 +259,9 @@ func TestCantMergeUnrelated(t *testing.T) {
 
                // Now we want to create a commit on a branch that is totally unrelated to our current head
                // Drop down to pure code at this point
-               user1 := unittest.AssertExistsAndLoadBean(t, &models.User{
+               user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{
                        Name: "user1",
-               }).(*models.User)
+               }).(*user_model.User)
                repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{
                        OwnerID: user1.ID,
                        Name:    "repo1",
index d7ea676b79ad99fd99ce25b695aa199234f4c0c9..e5e19475caa43dc531fc94cf049a67be5f4ae676 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        pull_service "code.gitea.io/gitea/services/pull"
        repo_service "code.gitea.io/gitea/services/repository"
        files_service "code.gitea.io/gitea/services/repository/files"
@@ -22,8 +23,8 @@ import (
 func TestAPIPullUpdate(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
                //Create PR to test
-               user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
-               org26 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 26}).(*models.User)
+               user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+               org26 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 26}).(*user_model.User)
                pr := createOutdatedPR(t, user, org26)
 
                //Test GetDiverging
@@ -50,8 +51,8 @@ func TestAPIPullUpdate(t *testing.T) {
 func TestAPIPullUpdateByRebase(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
                //Create PR to test
-               user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
-               org26 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 26}).(*models.User)
+               user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+               org26 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 26}).(*user_model.User)
                pr := createOutdatedPR(t, user, org26)
 
                //Test GetDiverging
@@ -75,7 +76,7 @@ func TestAPIPullUpdateByRebase(t *testing.T) {
        })
 }
 
-func createOutdatedPR(t *testing.T, actor, forkOrg *models.User) *models.PullRequest {
+func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *models.PullRequest {
        baseRepo, err := repo_service.CreateRepository(actor, actor, models.CreateRepoOptions{
                Name:        "repo-pr-update",
                Description: "repo-tmp-pr-update description",
index 0f23aa5e87252335de5f49e72cd02a72f9f2318f..27b62d264652d53372daab920e45d938a467dc4c 100644 (file)
@@ -10,14 +10,14 @@ import (
        "net/http/httptest"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
 
 func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkOwnerName, forkRepoName string) *httptest.ResponseRecorder {
-       forkOwner := unittest.AssertExistsAndLoadBean(t, &models.User{Name: forkOwnerName}).(*models.User)
+       forkOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: forkOwnerName}).(*user_model.User)
 
        // Step0: check the existence of the to-fork repo
        req := NewRequestf(t, "GET", "/%s/%s", forkOwnerName, forkRepoName)
index 66819656f94453b7b775e2680fe02fa76d82af11..b70a4a479739331a0467fae2d5bdaefae12fa0f5 100644 (file)
@@ -10,14 +10,14 @@ import (
        "net/http/httptest"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
 
 func testRepoGenerate(t *testing.T, session *TestSession, templateOwnerName, templateRepoName, generateOwnerName, generateRepoName string) *httptest.ResponseRecorder {
-       generateOwner := unittest.AssertExistsAndLoadBean(t, &models.User{Name: generateOwnerName}).(*models.User)
+       generateOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: generateOwnerName}).(*user_model.User)
 
        // Step0: check the existence of the generated repo
        req := NewRequestf(t, "GET", "/%s/%s", generateOwnerName, generateRepoName)
index 7bba055e2a57f5575f860b4ef0d43e3b97961956..823e7e6589e479bf64b04b70755c1fdd9e552da3 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/util"
        "code.gitea.io/gitea/services/release"
@@ -22,7 +23,7 @@ func TestCreateNewTagProtected(t *testing.T) {
        defer prepareTestEnv(t)()
 
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        t.Run("API", func(t *testing.T) {
                defer PrintCurrentTest(t)()
index a920ed45dd3d2b7d20bd4e58ad44223ee25aaf70..3ea8866150c3c7057609f9a9e626d981db125af6 100644 (file)
@@ -9,8 +9,8 @@ import (
        "strings"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
        "github.com/unknwon/i18n"
@@ -34,7 +34,7 @@ func testLoginFailed(t *testing.T, username, password, message string) {
 func TestSignin(t *testing.T) {
        defer prepareTestEnv(t)()
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        // add new user with user2's email
        user.Name = "testuser"
index 38aa069f318acadfe29ff02d7cce46d22cd4c9cc..93e384076ffd3edcd4c39f6c274c45f85281ff09 100644 (file)
@@ -10,8 +10,8 @@ import (
        "strings"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
 
        "github.com/stretchr/testify/assert"
@@ -54,7 +54,7 @@ func TestSignupAsRestricted(t *testing.T) {
        req = NewRequest(t, "GET", "/restrictedUser")
        MakeRequest(t, req, http.StatusOK)
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "restrictedUser"}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "restrictedUser"}).(*user_model.User)
        assert.True(t, user2.IsRestricted)
 }
 
index edc3a47314ac955364b404b08da0af18364f32a4..d1005bce078b58951ec7808cf29b75f0cad33551 100644 (file)
@@ -13,8 +13,8 @@ import (
        "net/url"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/avatar"
 
        "github.com/stretchr/testify/assert"
@@ -22,7 +22,7 @@ import (
 
 func TestUserAvatar(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, u *url.URL) {
-               user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo3, is an org
+               user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) // owner of the repo3, is an org
 
                seed := user2.Email
                if len(seed) == 0 {
@@ -72,7 +72,7 @@ func TestUserAvatar(t *testing.T) {
 
                session.MakeRequest(t, req, http.StatusFound)
 
-               user2 = unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo3, is an org
+               user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) // owner of the repo3, is an org
 
                req = NewRequest(t, "GET", user2.AvatarLinkWithSize(0))
                _ = session.MakeRequest(t, req, http.StatusOK)
index b70bf212b09fc21abcf7b12b5df9f798dc283149..8552993217a7a875a56ab157a4322598750d8b3c 100644 (file)
@@ -8,8 +8,8 @@ import (
        "net/http"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/test"
 
        "github.com/stretchr/testify/assert"
@@ -35,8 +35,8 @@ func TestRenameUsername(t *testing.T) {
        })
        session.MakeRequest(t, req, http.StatusFound)
 
-       unittest.AssertExistsAndLoadBean(t, &models.User{Name: "newUsername"})
-       unittest.AssertNotExistsBean(t, &models.User{Name: "user2"})
+       unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "newUsername"})
+       unittest.AssertNotExistsBean(t, &user_model.User{Name: "user2"})
 }
 
 func TestRenameInvalidUsername(t *testing.T) {
@@ -67,7 +67,7 @@ func TestRenameInvalidUsername(t *testing.T) {
                        i18n.Tr("en", "form.alpha_dash_dot_error"),
                )
 
-               unittest.AssertNotExistsBean(t, &models.User{Name: invalidUsername})
+               unittest.AssertNotExistsBean(t, &user_model.User{Name: invalidUsername})
        }
 }
 
@@ -113,7 +113,7 @@ func TestRenameReservedUsername(t *testing.T) {
                        i18n.Tr("en", "user.form.name_reserved", reservedUsername),
                )
 
-               unittest.AssertNotExistsBean(t, &models.User{Name: reservedUsername})
+               unittest.AssertNotExistsBean(t, &user_model.User{Name: reservedUsername})
        }
 }
 
index 8128a54aa374c056c606059471905148ea01d353..4c2e60e799b71808b2be1d2162fbd23a814253c4 100644 (file)
@@ -8,15 +8,15 @@ import (
        "net/http"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
 
 func TestXSSUserFullName(t *testing.T) {
        defer prepareTestEnv(t)()
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        const fullName = `name & <script class="evil">alert('Oh no!');</script>`
 
        session := loginUser(t, user.Name)
index 7af88e1b4a1e79c1f0dcdc26d62ef9ade8a24536..01b37dd7aec873d10663505bebbba6ecd0ffe7b0 100644 (file)
@@ -9,6 +9,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
 )
 
@@ -76,7 +77,7 @@ func init() {
        db.RegisterModel(new(Access))
 }
 
-func accessLevel(e db.Engine, user *User, repo *Repository) (AccessMode, error) {
+func accessLevel(e db.Engine, user *user_model.User, repo *Repository) (AccessMode, error) {
        mode := AccessModeNone
        var userID int64
        restricted := false
@@ -116,12 +117,12 @@ func maxAccessMode(modes ...AccessMode) AccessMode {
 }
 
 type userAccess struct {
-       User *User
+       User *user_model.User
        Mode AccessMode
 }
 
 // updateUserAccess updates an access map so that user has at least mode
-func updateUserAccess(accessMap map[int64]*userAccess, user *User, mode AccessMode) {
+func updateUserAccess(accessMap map[int64]*userAccess, user *user_model.User, mode AccessMode) {
        if ua, ok := accessMap[user.ID]; ok {
                ua.Mode = maxAccessMode(ua.Mode, mode)
        } else {
index 81e36ed2e0242350a96abab094d62193325ebbb3..a2fd05a033e6a460fa45df4b64c1334067c2239b 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -16,9 +17,9 @@ import (
 func TestAccessLevel(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       user5 := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
-       user29 := unittest.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
+       user29 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 29}).(*user_model.User)
        // A public repository owned by User 2
        repo1 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
        assert.False(t, repo1.IsPrivate)
@@ -67,8 +68,8 @@ func TestAccessLevel(t *testing.T) {
 func TestHasAccess(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
+       user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
        // A public repository owned by User 2
        repo1 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
        assert.False(t, repo1.IsPrivate)
@@ -125,7 +126,7 @@ func TestRepository_RecalculateAccesses2(t *testing.T) {
 func TestRepository_RecalculateAccesses3(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
        team5 := unittest.AssertExistsAndLoadBean(t, &Team{ID: 5}).(*Team)
-       user29 := unittest.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User)
+       user29 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 29}).(*user_model.User)
 
        has, err := db.GetEngine(db.DefaultContext).Get(&Access{UserID: 29, RepoID: 23})
        assert.NoError(t, err)
index d790cd6678f5c47d172c1556a7974f474c63a4d6..66fa78f26834071c5694923110950bb161e28a80 100644 (file)
@@ -14,6 +14,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
@@ -63,13 +64,13 @@ type Action struct {
        ID          int64 `xorm:"pk autoincr"`
        UserID      int64 `xorm:"INDEX"` // Receiver user id.
        OpType      ActionType
-       ActUserID   int64       `xorm:"INDEX"` // Action user id.
-       ActUser     *User       `xorm:"-"`
-       RepoID      int64       `xorm:"INDEX"`
-       Repo        *Repository `xorm:"-"`
-       CommentID   int64       `xorm:"INDEX"`
-       Comment     *Comment    `xorm:"-"`
-       IsDeleted   bool        `xorm:"INDEX NOT NULL DEFAULT false"`
+       ActUserID   int64            `xorm:"INDEX"` // Action user id.
+       ActUser     *user_model.User `xorm:"-"`
+       RepoID      int64            `xorm:"INDEX"`
+       Repo        *Repository      `xorm:"-"`
+       CommentID   int64            `xorm:"INDEX"`
+       Comment     *Comment         `xorm:"-"`
+       IsDeleted   bool             `xorm:"INDEX NOT NULL DEFAULT false"`
        RefName     string
        IsPrivate   bool               `xorm:"INDEX NOT NULL DEFAULT false"`
        Content     string             `xorm:"TEXT"`
@@ -91,11 +92,11 @@ func (a *Action) LoadActUser() {
                return
        }
        var err error
-       a.ActUser, err = GetUserByID(a.ActUserID)
+       a.ActUser, err = user_model.GetUserByID(a.ActUserID)
        if err == nil {
                return
-       } else if IsErrUserNotExist(err) {
-               a.ActUser = NewGhostUser()
+       } else if user_model.IsErrUserNotExist(err) {
+               a.ActUser = user_model.NewGhostUser()
        } else {
                log.Error("GetUserByID(%d): %v", a.ActUserID, err)
        }
@@ -294,13 +295,13 @@ func (a *Action) GetIssueContent() string {
 
 // GetFeedsOptions options for retrieving feeds
 type GetFeedsOptions struct {
-       RequestedUser   *User  // the user we want activity for
-       RequestedTeam   *Team  // the team we want activity for
-       Actor           *User  // the user viewing the activity
-       IncludePrivate  bool   // include private actions
-       OnlyPerformedBy bool   // only actions performed by requested user
-       IncludeDeleted  bool   // include deleted actions
-       Date            string // the day we want activity for: YYYY-MM-DD
+       RequestedUser   *user_model.User // the user we want activity for
+       RequestedTeam   *Team            // the team we want activity for
+       Actor           *user_model.User // the user viewing the activity
+       IncludePrivate  bool             // include private actions
+       OnlyPerformedBy bool             // only actions performed by requested user
+       IncludeDeleted  bool             // include deleted actions
+       Date            string           // the day we want activity for: YYYY-MM-DD
 }
 
 // GetFeeds returns actions according to the provided options
@@ -327,7 +328,7 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
        return actions, nil
 }
 
-func activityReadable(user, doer *User) bool {
+func activityReadable(user, doer *user_model.User) bool {
        var doerID int64
        if doer != nil {
                doerID = doer.ID
index 69e6aa73121fa39d327d9a2622e8b798b7bece46..4f2024cfcf67ec968f4e7a0a23ba4ce7cf6bb55f 100644 (file)
@@ -8,6 +8,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
 )
 
 // ActionList defines a list of actions
@@ -23,13 +24,13 @@ func (actions ActionList) getUserIDs() []int64 {
        return keysInt64(userIDs)
 }
 
-func (actions ActionList) loadUsers(e db.Engine) ([]*User, error) {
+func (actions ActionList) loadUsers(e db.Engine) ([]*user_model.User, error) {
        if len(actions) == 0 {
                return nil, nil
        }
 
        userIDs := actions.getUserIDs()
-       userMaps := make(map[int64]*User, len(userIDs))
+       userMaps := make(map[int64]*user_model.User, len(userIDs))
        err := e.
                In("id", userIDs).
                Find(&userMaps)
@@ -44,7 +45,7 @@ func (actions ActionList) loadUsers(e db.Engine) ([]*User, error) {
 }
 
 // LoadUsers loads actions' all users
-func (actions ActionList) LoadUsers() ([]*User, error) {
+func (actions ActionList) LoadUsers() ([]*user_model.User, error) {
        return actions.loadUsers(db.GetEngine(db.DefaultContext))
 }
 
index 87bbcf3fb77502cc9e1ace920b4887076cf193fa..8ab88bb97e06c77dea98347f7e04efc4f3a369b1 100644 (file)
@@ -9,6 +9,7 @@ import (
        "testing"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
 
        "github.com/stretchr/testify/assert"
@@ -17,7 +18,7 @@ import (
 func TestAction_GetRepoPath(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
        repo := unittest.AssertExistsAndLoadBean(t, &Repository{}).(*Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        action := &Action{RepoID: repo.ID}
        assert.Equal(t, path.Join(owner.Name, repo.Name), action.GetRepoPath())
 }
@@ -25,7 +26,7 @@ func TestAction_GetRepoPath(t *testing.T) {
 func TestAction_GetRepoLink(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
        repo := unittest.AssertExistsAndLoadBean(t, &Repository{}).(*Repository)
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        action := &Action{RepoID: repo.ID}
        setting.AppSubURL = "/suburl"
        expected := path.Join(setting.AppSubURL, owner.Name, repo.Name)
@@ -35,7 +36,7 @@ func TestAction_GetRepoLink(t *testing.T) {
 func TestGetFeeds(t *testing.T) {
        // test with an individual user
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        actions, err := GetFeeds(GetFeedsOptions{
                RequestedUser:   user,
@@ -63,8 +64,8 @@ func TestGetFeeds(t *testing.T) {
 func TestGetFeeds2(t *testing.T) {
        // test with an organization user
        assert.NoError(t, unittest.PrepareTestDatabase())
-       org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        actions, err := GetFeeds(GetFeedsOptions{
                RequestedUser:   org,
index fc0da58e381061c2fdef4730e9bf3ce78887f6e1..f5ed570ea24634200ed93672761a21a228cc1de7 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/timeutil"
@@ -69,7 +70,7 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
        }
 
        if !protectBranch.EnableWhitelist {
-               if user, err := GetUserByID(userID); err != nil {
+               if user, err := user_model.GetUserByID(userID); err != nil {
                        log.Error("GetUserByID: %v", err)
                        return false
                } else if repo, err := GetRepositoryByID(protectBranch.RepoID); err != nil {
@@ -123,11 +124,11 @@ func (protectBranch *ProtectedBranch) IsUserMergeWhitelisted(userID int64, permi
 }
 
 // IsUserOfficialReviewer check if user is official reviewer for the branch (counts towards required approvals)
-func (protectBranch *ProtectedBranch) IsUserOfficialReviewer(user *User) (bool, error) {
+func (protectBranch *ProtectedBranch) IsUserOfficialReviewer(user *user_model.User) (bool, error) {
        return protectBranch.isUserOfficialReviewer(db.GetEngine(db.DefaultContext), user)
 }
 
-func (protectBranch *ProtectedBranch) isUserOfficialReviewer(e db.Engine, user *User) (bool, error) {
+func (protectBranch *ProtectedBranch) isUserOfficialReviewer(e db.Engine, user *user_model.User) (bool, error) {
        repo, err := getRepositoryByID(e, protectBranch.RepoID)
        if err != nil {
                return false, err
@@ -446,7 +447,7 @@ func updateUserWhitelist(repo *Repository, currentWhitelist, newWhitelist []int6
 
        whitelist = make([]int64, 0, len(newWhitelist))
        for _, userID := range newWhitelist {
-               user, err := GetUserByID(userID)
+               user, err := user_model.GetUserByID(userID)
                if err != nil {
                        return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
                }
@@ -511,7 +512,7 @@ type DeletedBranch struct {
        Name        string             `xorm:"UNIQUE(s) NOT NULL"`
        Commit      string             `xorm:"UNIQUE(s) NOT NULL"`
        DeletedByID int64              `xorm:"INDEX"`
-       DeletedBy   *User              `xorm:"-"`
+       DeletedBy   *user_model.User   `xorm:"-"`
        DeletedUnix timeutil.TimeStamp `xorm:"INDEX created"`
 }
 
@@ -564,11 +565,11 @@ func (repo *Repository) RemoveDeletedBranch(id int64) (err error) {
 }
 
 // LoadUser loads the user that deleted the branch
-// When there's no user found it returns a NewGhostUser
+// When there's no user found it returns a user_model.NewGhostUser
 func (deletedBranch *DeletedBranch) LoadUser() {
-       user, err := GetUserByID(deletedBranch.DeletedByID)
+       user, err := user_model.GetUserByID(deletedBranch.DeletedByID)
        if err != nil {
-               user = NewGhostUser()
+               user = user_model.NewGhostUser()
        }
        deletedBranch.DeletedBy = user
 }
index 474825820afab068597181ea7fe70b50d17e2ccc..12aecdae84d9284be39b722f5ae0384c59c32e3e 100644 (file)
@@ -5,6 +5,7 @@
 package models
 
 import (
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
 )
 
@@ -12,7 +13,7 @@ import (
 func ConvertFromGitCommit(commits []*git.Commit, repo *Repository) []*SignCommitWithStatuses {
        return ParseCommitsWithStatus(
                ParseCommitsWithSignature(
-                       ValidateCommitsWithEmails(commits),
+                       user_model.ValidateCommitsWithEmails(commits),
                        repo,
                ),
                repo,
index df34b93ec53cd810acf8ae217290e3e6beccc6cb..bba39fde876a1093239651360440482328decfb0 100644 (file)
@@ -12,6 +12,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
@@ -32,7 +33,7 @@ type CommitStatus struct {
        Description string                `xorm:"TEXT"`
        ContextHash string                `xorm:"char(40) index"`
        Context     string                `xorm:"TEXT"`
-       Creator     *User                 `xorm:"-"`
+       Creator     *user_model.User      `xorm:"-"`
        CreatorID   int64
 
        CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
@@ -127,7 +128,7 @@ func (status *CommitStatus) loadAttributes(e db.Engine) (err error) {
                }
        }
        if status.Creator == nil && status.CreatorID > 0 {
-               status.Creator, err = getUserByID(e, status.CreatorID)
+               status.Creator, err = user_model.GetUserByIDEngine(e, status.CreatorID)
                if err != nil {
                        return fmt.Errorf("getUserByID [%d]: %v", status.CreatorID, err)
                }
@@ -274,7 +275,7 @@ func FindRepoRecentCommitStatusContexts(repoID int64, before time.Duration) ([]s
 // NewCommitStatusOptions holds options for creating a CommitStatus
 type NewCommitStatusOptions struct {
        Repo         *Repository
-       Creator      *User
+       Creator      *user_model.User
        SHA          string
        CommitStatus *CommitStatus
 }
index ba669628b906fa03ce6db7f8baf7f0a03800ceed..d16e7f5e99a93fbb422e5493f078ffec29d5b1b4 100644 (file)
@@ -7,6 +7,7 @@ package models
 import (
        admin_model "code.gitea.io/gitea/models/admin"
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
 
        "xorm.io/builder"
 )
@@ -169,12 +170,12 @@ func FixNullArchivedRepository() (int64, error) {
 
 // CountWrongUserType count OrgUser who have wrong type
 func CountWrongUserType() (int64, error) {
-       return db.GetEngine(db.DefaultContext).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Count(new(User))
+       return db.GetEngine(db.DefaultContext).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Count(new(user_model.User))
 }
 
 // FixWrongUserType fix OrgUser who have wrong type
 func FixWrongUserType() (int64, error) {
-       return db.GetEngine(db.DefaultContext).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Cols("type").NoAutoTime().Update(&User{Type: 1})
+       return db.GetEngine(db.DefaultContext).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Cols("type").NoAutoTime().Update(&user_model.User{Type: 1})
 }
 
 // CountCommentTypeLabelWithEmptyLabel count label comments with empty label
index 675247ed874f513c1def71af3ea839773b92bce5..adaeedcc0949e36faec180216faf3210d60acf94 100644 (file)
@@ -4,7 +4,9 @@
 
 package db
 
-import "fmt"
+import (
+       "fmt"
+)
 
 // ErrCancelled represents an error due to context cancellation
 type ErrCancelled struct {
diff --git a/models/db/name.go b/models/db/name.go
new file mode 100644 (file)
index 0000000..9c9d18f
--- /dev/null
@@ -0,0 +1,91 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package db
+
+import (
+       "errors"
+       "fmt"
+       "regexp"
+       "strings"
+       "unicode/utf8"
+)
+
+var (
+       // ErrNameEmpty name is empty error
+       ErrNameEmpty = errors.New("Name is empty")
+
+       // AlphaDashDotPattern characters prohibited in a user name (anything except A-Za-z0-9_.-)
+       AlphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`)
+)
+
+// ErrNameReserved represents a "reserved name" error.
+type ErrNameReserved struct {
+       Name string
+}
+
+// IsErrNameReserved checks if an error is a ErrNameReserved.
+func IsErrNameReserved(err error) bool {
+       _, ok := err.(ErrNameReserved)
+       return ok
+}
+
+func (err ErrNameReserved) Error() string {
+       return fmt.Sprintf("name is reserved [name: %s]", err.Name)
+}
+
+// ErrNamePatternNotAllowed represents a "pattern not allowed" error.
+type ErrNamePatternNotAllowed struct {
+       Pattern string
+}
+
+// IsErrNamePatternNotAllowed checks if an error is an ErrNamePatternNotAllowed.
+func IsErrNamePatternNotAllowed(err error) bool {
+       _, ok := err.(ErrNamePatternNotAllowed)
+       return ok
+}
+
+func (err ErrNamePatternNotAllowed) Error() string {
+       return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
+}
+
+// ErrNameCharsNotAllowed represents a "character not allowed in name" error.
+type ErrNameCharsNotAllowed struct {
+       Name string
+}
+
+// IsErrNameCharsNotAllowed checks if an error is an ErrNameCharsNotAllowed.
+func IsErrNameCharsNotAllowed(err error) bool {
+       _, ok := err.(ErrNameCharsNotAllowed)
+       return ok
+}
+
+func (err ErrNameCharsNotAllowed) Error() string {
+       return fmt.Sprintf("User name is invalid [%s]: must be valid alpha or numeric or dash(-_) or dot characters", err.Name)
+}
+
+// IsUsableName checks if name is reserved or pattern of name is not allowed
+// based on given reserved names and patterns.
+// Names are exact match, patterns can be prefix or suffix match with placeholder '*'.
+func IsUsableName(names, patterns []string, name string) error {
+       name = strings.TrimSpace(strings.ToLower(name))
+       if utf8.RuneCountInString(name) == 0 {
+               return ErrNameEmpty
+       }
+
+       for i := range names {
+               if name == names[i] {
+                       return ErrNameReserved{name}
+               }
+       }
+
+       for _, pat := range patterns {
+               if pat[0] == '*' && strings.HasSuffix(name, pat[1:]) ||
+                       (pat[len(pat)-1] == '*' && strings.HasPrefix(name, pat[:len(pat)-1])) {
+                       return ErrNamePatternNotAllowed{pat}
+               }
+       }
+
+       return nil
+}
diff --git a/models/db/search.go b/models/db/search.go
new file mode 100644 (file)
index 0000000..704a48e
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package db
+
+// SearchOrderBy is used to sort the result
+type SearchOrderBy string
+
+func (s SearchOrderBy) String() string {
+       return string(s)
+}
+
+// Strings for sorting result
+const (
+       SearchOrderByAlphabetically        SearchOrderBy = "name ASC"
+       SearchOrderByAlphabeticallyReverse SearchOrderBy = "name DESC"
+       SearchOrderByLeastUpdated          SearchOrderBy = "updated_unix ASC"
+       SearchOrderByRecentUpdated         SearchOrderBy = "updated_unix DESC"
+       SearchOrderByOldest                SearchOrderBy = "created_unix ASC"
+       SearchOrderByNewest                SearchOrderBy = "created_unix DESC"
+       SearchOrderBySize                  SearchOrderBy = "size ASC"
+       SearchOrderBySizeReverse           SearchOrderBy = "size DESC"
+       SearchOrderByID                    SearchOrderBy = "id ASC"
+       SearchOrderByIDReverse             SearchOrderBy = "id DESC"
+       SearchOrderByStars                 SearchOrderBy = "num_stars ASC"
+       SearchOrderByStarsReverse          SearchOrderBy = "num_stars DESC"
+       SearchOrderByForks                 SearchOrderBy = "num_forks ASC"
+       SearchOrderByForksReverse          SearchOrderBy = "num_forks DESC"
+)
index d0691c1c697d55611e707ca0dc07862c4e39187a..5ef96683e702d6906bdea4191dfe76f9cb9d926a 100644 (file)
@@ -26,51 +26,6 @@ func (err ErrNotExist) Error() string {
        return fmt.Sprintf("record does not exist [id: %d]", err.ID)
 }
 
-// ErrNameReserved represents a "reserved name" error.
-type ErrNameReserved struct {
-       Name string
-}
-
-// IsErrNameReserved checks if an error is a ErrNameReserved.
-func IsErrNameReserved(err error) bool {
-       _, ok := err.(ErrNameReserved)
-       return ok
-}
-
-func (err ErrNameReserved) Error() string {
-       return fmt.Sprintf("name is reserved [name: %s]", err.Name)
-}
-
-// ErrNamePatternNotAllowed represents a "pattern not allowed" error.
-type ErrNamePatternNotAllowed struct {
-       Pattern string
-}
-
-// IsErrNamePatternNotAllowed checks if an error is an ErrNamePatternNotAllowed.
-func IsErrNamePatternNotAllowed(err error) bool {
-       _, ok := err.(ErrNamePatternNotAllowed)
-       return ok
-}
-
-func (err ErrNamePatternNotAllowed) Error() string {
-       return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
-}
-
-// ErrNameCharsNotAllowed represents a "character not allowed in name" error.
-type ErrNameCharsNotAllowed struct {
-       Name string
-}
-
-// IsErrNameCharsNotAllowed checks if an error is an ErrNameCharsNotAllowed.
-func IsErrNameCharsNotAllowed(err error) bool {
-       _, ok := err.(ErrNameCharsNotAllowed)
-       return ok
-}
-
-func (err ErrNameCharsNotAllowed) Error() string {
-       return fmt.Sprintf("User name is invalid [%s]: must be valid alpha or numeric or dash(-_) or dot characters", err.Name)
-}
-
 // ErrSSHDisabled represents an "SSH disabled" error.
 type ErrSSHDisabled struct{}
 
@@ -84,77 +39,6 @@ func (err ErrSSHDisabled) Error() string {
        return "SSH is disabled"
 }
 
-//  ____ ___
-// |    |   \______ ___________
-// |    |   /  ___// __ \_  __ \
-// |    |  /\___ \\  ___/|  | \/
-// |______//____  >\___  >__|
-//              \/     \/
-
-// ErrUserAlreadyExist represents a "user already exists" error.
-type ErrUserAlreadyExist struct {
-       Name string
-}
-
-// IsErrUserAlreadyExist checks if an error is a ErrUserAlreadyExists.
-func IsErrUserAlreadyExist(err error) bool {
-       _, ok := err.(ErrUserAlreadyExist)
-       return ok
-}
-
-func (err ErrUserAlreadyExist) Error() string {
-       return fmt.Sprintf("user already exists [name: %s]", err.Name)
-}
-
-// ErrUserNotExist represents a "UserNotExist" kind of error.
-type ErrUserNotExist struct {
-       UID   int64
-       Name  string
-       KeyID int64
-}
-
-// IsErrUserNotExist checks if an error is a ErrUserNotExist.
-func IsErrUserNotExist(err error) bool {
-       _, ok := err.(ErrUserNotExist)
-       return ok
-}
-
-func (err ErrUserNotExist) Error() string {
-       return fmt.Sprintf("user does not exist [uid: %d, name: %s, keyid: %d]", err.UID, err.Name, err.KeyID)
-}
-
-// ErrUserProhibitLogin represents a "ErrUserProhibitLogin" kind of error.
-type ErrUserProhibitLogin struct {
-       UID  int64
-       Name string
-}
-
-// IsErrUserProhibitLogin checks if an error is a ErrUserProhibitLogin
-func IsErrUserProhibitLogin(err error) bool {
-       _, ok := err.(ErrUserProhibitLogin)
-       return ok
-}
-
-func (err ErrUserProhibitLogin) Error() string {
-       return fmt.Sprintf("user is not allowed login [uid: %d, name: %s]", err.UID, err.Name)
-}
-
-// ErrUserInactive represents a "ErrUserInactive" kind of error.
-type ErrUserInactive struct {
-       UID  int64
-       Name string
-}
-
-// IsErrUserInactive checks if an error is a ErrUserInactive
-func IsErrUserInactive(err error) bool {
-       _, ok := err.(ErrUserInactive)
-       return ok
-}
-
-func (err ErrUserInactive) Error() string {
-       return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
-}
-
 // ErrUserOwnRepos represents a "UserOwnRepos" kind of error.
 type ErrUserOwnRepos struct {
        UID int64
index 6b023a4cb2a984192b32bd3a77023032cf459499..4be13072257b5a02e85c1ce59dbfd9ca73d993e7 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/login"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/structs"
 
        "github.com/markbates/goth"
@@ -46,7 +47,7 @@ func GetExternalLogin(externalLoginUser *ExternalLoginUser) (bool, error) {
 }
 
 // ListAccountLinks returns a map with the ExternalLoginUser and its LoginSource
-func ListAccountLinks(user *User) ([]*ExternalLoginUser, error) {
+func ListAccountLinks(user *user_model.User) ([]*ExternalLoginUser, error) {
        externalAccounts := make([]*ExternalLoginUser, 0, 5)
        err := db.GetEngine(db.DefaultContext).Where("user_id=?", user.ID).
                Desc("login_source_id").
@@ -59,7 +60,7 @@ func ListAccountLinks(user *User) ([]*ExternalLoginUser, error) {
 }
 
 // LinkExternalToUser link the external user to the user
-func LinkExternalToUser(user *User, externalLoginUser *ExternalLoginUser) error {
+func LinkExternalToUser(user *user_model.User, externalLoginUser *ExternalLoginUser) error {
        has, err := db.GetEngine(db.DefaultContext).Where("external_id=? AND login_source_id=?", externalLoginUser.ExternalID, externalLoginUser.LoginSourceID).
                NoAutoCondition().
                Exist(externalLoginUser)
@@ -74,7 +75,7 @@ func LinkExternalToUser(user *User, externalLoginUser *ExternalLoginUser) error
 }
 
 // RemoveAccountLink will remove all external login sources for the given user
-func RemoveAccountLink(user *User, loginSourceID int64) (int64, error) {
+func RemoveAccountLink(user *user_model.User, loginSourceID int64) (int64, error) {
        deleted, err := db.GetEngine(db.DefaultContext).Delete(&ExternalLoginUser{UserID: user.ID, LoginSourceID: loginSourceID})
        if err != nil {
                return deleted, err
@@ -86,7 +87,7 @@ func RemoveAccountLink(user *User, loginSourceID int64) (int64, error) {
 }
 
 // removeAllAccountLinks will remove all external login sources for the given user
-func removeAllAccountLinks(e db.Engine, user *User) error {
+func removeAllAccountLinks(e db.Engine, user *user_model.User) error {
        _, err := e.Delete(&ExternalLoginUser{UserID: user.ID})
        return err
 }
@@ -106,7 +107,7 @@ func GetUserIDByExternalUserID(provider, userID string) (int64, error) {
 }
 
 // UpdateExternalUser updates external user's information
-func UpdateExternalUser(user *User, gothUser goth.User) error {
+func UpdateExternalUser(user *user_model.User, gothUser goth.User) error {
        loginSource, err := login.GetActiveOAuth2LoginSourceByName(gothUser.Provider)
        if err != nil {
                return err
index 357dc2b964cbfb1ea9bfc66e7d403b76008fe534..ce27a9237ed8533fd662913accae0e4cd110b8c8 100644 (file)
@@ -214,7 +214,7 @@ func deleteGPGKey(e db.Engine, keyID string) (int64, error) {
 }
 
 // DeleteGPGKey deletes GPG key information in database.
-func DeleteGPGKey(doer *User, id int64) (err error) {
+func DeleteGPGKey(doer *user_model.User, id int64) (err error) {
        key, err := GetGPGKeyByID(id)
        if err != nil {
                if IsErrGPGKeyNotExist(err) {
@@ -244,7 +244,7 @@ func DeleteGPGKey(doer *User, id int64) (err error) {
 func checkKeyEmails(email string, keys ...*GPGKey) (bool, string) {
        uid := int64(0)
        var userEmails []*user_model.EmailAddress
-       var user *User
+       var user *user_model.User
        for _, key := range keys {
                for _, e := range key.Emails {
                        if e.IsActivated && (email == "" || strings.EqualFold(e.Email, email)) {
@@ -255,8 +255,8 @@ func checkKeyEmails(email string, keys ...*GPGKey) (bool, string) {
                        if uid != key.OwnerID {
                                userEmails, _ = user_model.GetEmailAddresses(key.OwnerID)
                                uid = key.OwnerID
-                               user = &User{ID: uid}
-                               _, _ = GetUser(user)
+                               user = &user_model.User{ID: uid}
+                               _, _ = user_model.GetUser(user)
                        }
                        for _, e := range userEmails {
                                if e.IsActivated && (email == "" || strings.EqualFold(e.Email, email)) {
index 6da65d3697941b879bc8f1b0a3bd6adf8b13a4cc..5eeeb69ef50832146e00a162a4b33d97891d0b45 100644 (file)
@@ -44,8 +44,8 @@ type CommitVerification struct {
        Verified       bool
        Warning        bool
        Reason         string
-       SigningUser    *User
-       CommittingUser *User
+       SigningUser    *user_model.User
+       CommittingUser *user_model.User
        SigningEmail   string
        SigningKey     *GPGKey
        TrustStatus    string
@@ -54,7 +54,7 @@ type CommitVerification struct {
 // SignCommit represents a commit with validation of signature.
 type SignCommit struct {
        Verification *CommitVerification
-       *UserCommit
+       *user_model.UserCommit
 }
 
 const (
@@ -69,7 +69,7 @@ const (
 )
 
 // ParseCommitsWithSignature checks if signaute of commits are corresponding to users gpg keys.
-func ParseCommitsWithSignature(oldCommits []*UserCommit, repository *Repository) []*SignCommit {
+func ParseCommitsWithSignature(oldCommits []*user_model.UserCommit, repository *Repository) []*SignCommit {
        newCommits := make([]*SignCommit, 0, len(oldCommits))
        keyMap := map[string]bool{}
 
@@ -88,19 +88,19 @@ func ParseCommitsWithSignature(oldCommits []*UserCommit, repository *Repository)
 
 // ParseCommitWithSignature check if signature is good against keystore.
 func ParseCommitWithSignature(c *git.Commit) *CommitVerification {
-       var committer *User
+       var committer *user_model.User
        if c.Committer != nil {
                var err error
                // Find Committer account
-               committer, err = GetUserByEmail(c.Committer.Email) // This finds the user by primary email or activated email so commit will not be valid if email is not
-               if err != nil {                                    // Skipping not user for committer
-                       committer = &User{
+               committer, err = user_model.GetUserByEmail(c.Committer.Email) // This finds the user by primary email or activated email so commit will not be valid if email is not
+               if err != nil {                                               // Skipping not user for committer
+                       committer = &user_model.User{
                                Name:  c.Committer.Name,
                                Email: c.Committer.Email,
                        }
                        // We can expect this to often be an ErrUserNotExist. in the case
                        // it is not, however, it is important to log it.
-                       if !IsErrUserNotExist(err) {
+                       if !user_model.IsErrUserNotExist(err) {
                                log.Error("GetUserByEmail: %v", err)
                                return &CommitVerification{
                                        CommittingUser: committer,
@@ -250,7 +250,7 @@ func ParseCommitWithSignature(c *git.Commit) *CommitVerification {
        }
 }
 
-func verifyWithGPGSettings(gpgSettings *git.GPGSettings, sig *packet.Signature, payload string, committer *User, keyID string) *CommitVerification {
+func verifyWithGPGSettings(gpgSettings *git.GPGSettings, sig *packet.Signature, payload string, committer *user_model.User, keyID string) *CommitVerification {
        // First try to find the key in the db
        if commitVerification := hashAndVerifyForKeyID(sig, payload, committer, gpgSettings.KeyID, gpgSettings.Name, gpgSettings.Email); commitVerification != nil {
                return commitVerification
@@ -296,7 +296,7 @@ func verifyWithGPGSettings(gpgSettings *git.GPGSettings, sig *packet.Signature,
                                KeyID:   subKey.PublicKey.KeyIdString(),
                        })
                }
-               if commitVerification := hashAndVerifyWithSubKeysCommitVerification(sig, payload, k, committer, &User{
+               if commitVerification := hashAndVerifyWithSubKeysCommitVerification(sig, payload, k, committer, &user_model.User{
                        Name:  gpgSettings.Name,
                        Email: gpgSettings.Email,
                }, gpgSettings.Email); commitVerification != nil {
@@ -357,7 +357,7 @@ func hashAndVerifyWithSubKeys(sig *packet.Signature, payload string, k *GPGKey)
        return nil, nil
 }
 
-func hashAndVerifyWithSubKeysCommitVerification(sig *packet.Signature, payload string, k *GPGKey, committer, signer *User, email string) *CommitVerification {
+func hashAndVerifyWithSubKeysCommitVerification(sig *packet.Signature, payload string, k *GPGKey, committer, signer *user_model.User, email string) *CommitVerification {
        key, err := hashAndVerifyWithSubKeys(sig, payload, k)
        if err != nil { // Skipping failed to generate hash
                return &CommitVerification{
@@ -380,7 +380,7 @@ func hashAndVerifyWithSubKeysCommitVerification(sig *packet.Signature, payload s
        return nil
 }
 
-func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *User, keyID, name, email string) *CommitVerification {
+func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *user_model.User, keyID, name, email string) *CommitVerification {
        if keyID == "" {
                return nil
        }
@@ -415,16 +415,16 @@ func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *Use
                        continue
                }
 
-               signer := &User{
+               signer := &user_model.User{
                        Name:  name,
                        Email: email,
                }
                if key.OwnerID != 0 {
-                       owner, err := GetUserByID(key.OwnerID)
+                       owner, err := user_model.GetUserByID(key.OwnerID)
                        if err == nil {
                                signer = owner
-                       } else if !IsErrUserNotExist(err) {
-                               log.Error("Failed to GetUserByID: %d for key ID: %d (%s) %v", key.OwnerID, key.ID, key.KeyID, err)
+                       } else if !user_model.IsErrUserNotExist(err) {
+                               log.Error("Failed to user_model.GetUserByID: %d for key ID: %d (%s) %v", key.OwnerID, key.ID, key.KeyID, err)
                                return &CommitVerification{
                                        CommittingUser: committer,
                                        Verified:       false,
index e5f4960b7666df02e44cabb9bb8e35daeb297533..8f51c146aa0ee88448d0cd6fa0626df0ef308d87 100644 (file)
@@ -9,6 +9,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/timeutil"
 
        "github.com/stretchr/testify/assert"
@@ -195,7 +196,7 @@ Unknown GPG key with good email
 func TestCheckGPGUserEmail(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       _ = unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       _ = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        testEmailWithUpperCaseLetters := `-----BEGIN PGP PUBLIC KEY BLOCK-----
 Version: GnuPG v1
index 1c6b79ec5f6afc89852497efa9327cf41ca8ce96..18240860211c5be65efaa873e98c67e44e6fbb78 100644 (file)
@@ -9,6 +9,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/log"
 )
@@ -104,7 +105,7 @@ func VerifyGPGKey(ownerID int64, keyID, token, signature string) (string, error)
 }
 
 // VerificationToken returns token for the user that will be valid in minutes (time)
-func VerificationToken(user *User, minutes int) string {
+func VerificationToken(user *user_model.User, minutes int) string {
        return base.EncodeSha256(
                time.Now().Truncate(1*time.Minute).Add(time.Duration(minutes)*time.Minute).Format(time.RFC1123Z) + ":" +
                        user.CreatedUnix.FormatLong() + ":" +
index 710c15a97837188a86fedc6b1290d32475d18144..41dd1ccd535e1b73049b9abd2ec77d17a5c00e2d 100644 (file)
@@ -7,6 +7,7 @@ package models
 import (
        "encoding/binary"
 
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/json"
 )
 
@@ -26,8 +27,8 @@ func valuesRepository(m map[int64]*Repository) []*Repository {
        return values
 }
 
-func valuesUser(m map[int64]*User) []*User {
-       values := make([]*User, 0, len(m))
+func valuesUser(m map[int64]*user_model.User) []*user_model.User {
+       values := make([]*user_model.User, 0, len(m))
        for _, v := range m {
                values = append(values, v)
        }
index 922a5790be2dac19a826e80f959ae00e42fe083a..3e98f60ffdf6a56ac0e04ae24547469cc49d3e6b 100644 (file)
@@ -9,6 +9,7 @@ import (
        "os"
        "strings"
 
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
 )
 
@@ -32,19 +33,19 @@ const (
 // It is recommended to avoid using this unless you are pushing within a transaction
 // or if you absolutely are sure that post-receive and pre-receive will do nothing
 // We provide the full pushing-environment for other hook providers
-func InternalPushingEnvironment(doer *User, repo *Repository) []string {
+func InternalPushingEnvironment(doer *user_model.User, repo *Repository) []string {
        return append(PushingEnvironment(doer, repo),
                EnvIsInternal+"=true",
        )
 }
 
 // PushingEnvironment returns an os environment to allow hooks to work on push
-func PushingEnvironment(doer *User, repo *Repository) []string {
+func PushingEnvironment(doer *user_model.User, repo *Repository) []string {
        return FullPushingEnvironment(doer, doer, repo, repo.Name, 0)
 }
 
 // FullPushingEnvironment returns an os environment to allow hooks to work on push
-func FullPushingEnvironment(author, committer *User, repo *Repository, repoName string, prID int64) []string {
+func FullPushingEnvironment(author, committer *user_model.User, repo *Repository, repoName string, prID int64) []string {
        isWiki := "false"
        if strings.HasSuffix(repoName, ".wiki") {
                isWiki = "true"
index 7aab8b93995b16a715f07374b86240b58ac7c563..557d19e739d9dbd0c05b04aa62fba485ee05f56f 100644 (file)
@@ -17,6 +17,7 @@ import (
        "code.gitea.io/gitea/models/issues"
        repo_model "code.gitea.io/gitea/models/repo"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/references"
@@ -30,12 +31,12 @@ import (
 
 // Issue represents an issue or pull request of repository.
 type Issue struct {
-       ID               int64       `xorm:"pk autoincr"`
-       RepoID           int64       `xorm:"INDEX UNIQUE(repo_index)"`
-       Repo             *Repository `xorm:"-"`
-       Index            int64       `xorm:"UNIQUE(repo_index)"` // Index in one repository.
-       PosterID         int64       `xorm:"INDEX"`
-       Poster           *User       `xorm:"-"`
+       ID               int64            `xorm:"pk autoincr"`
+       RepoID           int64            `xorm:"INDEX UNIQUE(repo_index)"`
+       Repo             *Repository      `xorm:"-"`
+       Index            int64            `xorm:"UNIQUE(repo_index)"` // Index in one repository.
+       PosterID         int64            `xorm:"INDEX"`
+       Poster           *user_model.User `xorm:"-"`
        OriginalAuthor   string
        OriginalAuthorID int64      `xorm:"index"`
        Title            string     `xorm:"name"`
@@ -46,12 +47,12 @@ type Issue struct {
        Milestone        *Milestone `xorm:"-"`
        Project          *Project   `xorm:"-"`
        Priority         int
-       AssigneeID       int64        `xorm:"-"`
-       Assignee         *User        `xorm:"-"`
-       IsClosed         bool         `xorm:"INDEX"`
-       IsRead           bool         `xorm:"-"`
-       IsPull           bool         `xorm:"INDEX"` // Indicates whether is a pull request or not.
-       PullRequest      *PullRequest `xorm:"-"`
+       AssigneeID       int64            `xorm:"-"`
+       Assignee         *user_model.User `xorm:"-"`
+       IsClosed         bool             `xorm:"INDEX"`
+       IsRead           bool             `xorm:"-"`
+       IsPull           bool             `xorm:"INDEX"` // Indicates whether is a pull request or not.
+       PullRequest      *PullRequest     `xorm:"-"`
        NumComments      int
        Ref              string
 
@@ -65,7 +66,7 @@ type Issue struct {
        Comments         []*Comment               `xorm:"-"`
        Reactions        ReactionList             `xorm:"-"`
        TotalTrackedTime int64                    `xorm:"-"`
-       Assignees        []*User                  `xorm:"-"`
+       Assignees        []*user_model.User       `xorm:"-"`
 
        // IsLocked limits commenting abilities to users on an issue
        // with write access
@@ -177,11 +178,11 @@ func (issue *Issue) LoadPoster() error {
 
 func (issue *Issue) loadPoster(e db.Engine) (err error) {
        if issue.Poster == nil {
-               issue.Poster, err = getUserByID(e, issue.PosterID)
+               issue.Poster, err = user_model.GetUserByIDEngine(e, issue.PosterID)
                if err != nil {
                        issue.PosterID = -1
-                       issue.Poster = NewGhostUser()
-                       if !IsErrUserNotExist(err) {
+                       issue.Poster = user_model.NewGhostUser()
+                       if !user_model.IsErrUserNotExist(err) {
                                return fmt.Errorf("getUserByID.(poster) [%d]: %v", issue.PosterID, err)
                        }
                        err = nil
@@ -428,11 +429,11 @@ func (issue *Issue) HasLabel(labelID int64) bool {
        return issue.hasLabel(db.GetEngine(db.DefaultContext), labelID)
 }
 
-func (issue *Issue) addLabel(ctx context.Context, label *Label, doer *User) error {
+func (issue *Issue) addLabel(ctx context.Context, label *Label, doer *user_model.User) error {
        return newIssueLabel(ctx, issue, label, doer)
 }
 
-func (issue *Issue) addLabels(ctx context.Context, labels []*Label, doer *User) error {
+func (issue *Issue) addLabels(ctx context.Context, labels []*Label, doer *user_model.User) error {
        return newIssueLabels(ctx, issue, labels, doer)
 }
 
@@ -448,11 +449,11 @@ func (issue *Issue) getLabels(e db.Engine) (err error) {
        return nil
 }
 
-func (issue *Issue) removeLabel(ctx context.Context, doer *User, label *Label) error {
+func (issue *Issue) removeLabel(ctx context.Context, doer *user_model.User, label *Label) error {
        return deleteIssueLabel(ctx, issue, label, doer)
 }
 
-func (issue *Issue) clearLabels(ctx context.Context, doer *User) (err error) {
+func (issue *Issue) clearLabels(ctx context.Context, doer *user_model.User) (err error) {
        if err = issue.getLabels(db.GetEngine(ctx)); err != nil {
                return fmt.Errorf("getLabels: %v", err)
        }
@@ -468,7 +469,7 @@ func (issue *Issue) clearLabels(ctx context.Context, doer *User) (err error) {
 
 // ClearLabels removes all issue labels as the given user.
 // Triggers appropriate WebHooks, if any.
-func (issue *Issue) ClearLabels(doer *User) (err error) {
+func (issue *Issue) ClearLabels(doer *user_model.User) (err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -516,7 +517,7 @@ func (ts labelSorter) Swap(i, j int) {
 
 // ReplaceLabels removes all current labels and add new labels to the issue.
 // Triggers appropriate WebHooks, if any.
-func (issue *Issue) ReplaceLabels(labels []*Label, doer *User) (err error) {
+func (issue *Issue) ReplaceLabels(labels []*Label, doer *user_model.User) (err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -598,7 +599,7 @@ func updateIssueCols(e db.Engine, issue *Issue, cols ...string) error {
        return nil
 }
 
-func (issue *Issue) changeStatus(ctx context.Context, doer *User, isClosed, isMergePull bool) (*Comment, error) {
+func (issue *Issue) changeStatus(ctx context.Context, doer *user_model.User, isClosed, isMergePull bool) (*Comment, error) {
        // Reload the issue
        currentIssue, err := getIssueByID(db.GetEngine(ctx), issue.ID)
        if err != nil {
@@ -621,7 +622,7 @@ func (issue *Issue) changeStatus(ctx context.Context, doer *User, isClosed, isMe
        return issue.doChangeStatus(ctx, doer, isMergePull)
 }
 
-func (issue *Issue) doChangeStatus(ctx context.Context, doer *User, isMergePull bool) (*Comment, error) {
+func (issue *Issue) doChangeStatus(ctx context.Context, doer *user_model.User, isMergePull bool) (*Comment, error) {
        e := db.GetEngine(ctx)
        // Check for open dependencies
        if issue.IsClosed && issue.Repo.isDependenciesEnabled(e) {
@@ -684,7 +685,7 @@ func (issue *Issue) doChangeStatus(ctx context.Context, doer *User, isMergePull
 }
 
 // ChangeStatus changes issue status to open or closed.
-func (issue *Issue) ChangeStatus(doer *User, isClosed bool) (*Comment, error) {
+func (issue *Issue) ChangeStatus(doer *user_model.User, isClosed bool) (*Comment, error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return nil, err
@@ -711,7 +712,7 @@ func (issue *Issue) ChangeStatus(doer *User, isClosed bool) (*Comment, error) {
 }
 
 // ChangeTitle changes the title of this issue, as the given user.
-func (issue *Issue) ChangeTitle(doer *User, oldTitle string) (err error) {
+func (issue *Issue) ChangeTitle(doer *user_model.User, oldTitle string) (err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -745,7 +746,7 @@ func (issue *Issue) ChangeTitle(doer *User, oldTitle string) (err error) {
 }
 
 // ChangeRef changes the branch of this issue, as the given user.
-func (issue *Issue) ChangeRef(doer *User, oldRef string) (err error) {
+func (issue *Issue) ChangeRef(doer *user_model.User, oldRef string) (err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -778,7 +779,7 @@ func (issue *Issue) ChangeRef(doer *User, oldRef string) (err error) {
 }
 
 // AddDeletePRBranchComment adds delete branch comment for pull request issue
-func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branchName string) error {
+func AddDeletePRBranchComment(doer *user_model.User, repo *Repository, issueID int64, branchName string) error {
        issue, err := getIssueByID(db.GetEngine(db.DefaultContext), issueID)
        if err != nil {
                return err
@@ -823,7 +824,7 @@ func (issue *Issue) UpdateAttachments(uuids []string) (err error) {
 }
 
 // ChangeContent changes issue content, as the given user.
-func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
+func (issue *Issue) ChangeContent(doer *user_model.User, content string) (err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -922,7 +923,7 @@ type NewIssueOptions struct {
        IsPull      bool
 }
 
-func newIssue(ctx context.Context, doer *User, opts NewIssueOptions) (err error) {
+func newIssue(ctx context.Context, doer *user_model.User, opts NewIssueOptions) (err error) {
        e := db.GetEngine(ctx)
        opts.Issue.Title = strings.TrimSpace(opts.Issue.Title)
 
@@ -1380,7 +1381,7 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
 }
 
 // GetRepoIDsForIssuesOptions find all repo ids for the given options
-func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *User) ([]int64, error) {
+func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]int64, error) {
        repoIDs := make([]int64, 0, 5)
        e := db.GetEngine(db.DefaultContext)
 
@@ -1455,7 +1456,7 @@ func GetParticipantsIDsByIssueID(issueID int64) ([]int64, error) {
 }
 
 // IsUserParticipantsOfIssue return true if user is participants of an issue
-func IsUserParticipantsOfIssue(user *User, issue *Issue) bool {
+func IsUserParticipantsOfIssue(user *user_model.User, issue *Issue) bool {
        userIDs, err := issue.getParticipantIDsByIssue(db.GetEngine(db.DefaultContext))
        if err != nil {
                log.Error(err.Error())
@@ -1465,7 +1466,7 @@ func IsUserParticipantsOfIssue(user *User, issue *Issue) bool {
 }
 
 // UpdateIssueMentions updates issue-user relations for mentioned users.
-func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*User) error {
+func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_model.User) error {
        if len(mentions) == 0 {
                return nil
        }
@@ -1843,7 +1844,7 @@ func SearchIssueIDsByKeyword(kw string, repoIDs []int64, limit, start int) (int6
 // UpdateIssueByAPI updates all allowed fields of given issue.
 // If the issue status is changed a statusChangeComment is returned
 // similarly if the title is changed the titleChanged bool is set to true
-func UpdateIssueByAPI(issue *Issue, doer *User) (statusChangeComment *Comment, titleChanged bool, err error) {
+func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return nil, false, err
@@ -1898,7 +1899,7 @@ func UpdateIssueByAPI(issue *Issue, doer *User) (statusChangeComment *Comment, t
 }
 
 // UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.
-func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *User) (err error) {
+func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *user_model.User) (err error) {
        // if the deadline hasn't changed do nothing
        if issue.DeadlineUnix == deadlineUnix {
                return nil
@@ -2017,7 +2018,7 @@ func (issue *Issue) updateClosedNum(e db.Engine) (err error) {
 }
 
 // FindAndUpdateIssueMentions finds users mentioned in the given content string, and saves them in the database.
-func (issue *Issue) FindAndUpdateIssueMentions(ctx context.Context, doer *User, content string) (mentions []*User, err error) {
+func (issue *Issue) FindAndUpdateIssueMentions(ctx context.Context, doer *user_model.User, content string) (mentions []*user_model.User, err error) {
        rawMentions := references.FindAllMentionsMarkdown(content)
        mentions, err = issue.ResolveMentionsByVisibility(ctx, doer, rawMentions)
        if err != nil {
@@ -2031,7 +2032,7 @@ func (issue *Issue) FindAndUpdateIssueMentions(ctx context.Context, doer *User,
 
 // ResolveMentionsByVisibility returns the users mentioned in an issue, removing those that
 // don't have access to reading it. Teams are expanded into their users, but organizations are ignored.
-func (issue *Issue) ResolveMentionsByVisibility(ctx context.Context, doer *User, mentions []string) (users []*User, err error) {
+func (issue *Issue) ResolveMentionsByVisibility(ctx context.Context, doer *user_model.User, mentions []string) (users []*user_model.User, err error) {
        if len(mentions) == 0 {
                return
        }
@@ -2100,7 +2101,7 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx context.Context, doer *User,
                                }
                        }
                        if len(checked) != 0 {
-                               teamusers := make([]*User, 0, 20)
+                               teamusers := make([]*user_model.User, 0, 20)
                                if err := db.GetEngine(ctx).
                                        Join("INNER", "team_user", "team_user.uid = `user`.id").
                                        In("`team_user`.team_id", checked).
@@ -2110,7 +2111,7 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx context.Context, doer *User,
                                        return nil, fmt.Errorf("get teams users: %v", err)
                                }
                                if len(teamusers) > 0 {
-                                       users = make([]*User, 0, len(teamusers))
+                                       users = make([]*user_model.User, 0, len(teamusers))
                                        for _, user := range teamusers {
                                                if already, ok := resolved[user.LowerName]; !ok || !already {
                                                        users = append(users, user)
@@ -2134,10 +2135,10 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx context.Context, doer *User,
        }
 
        if users == nil {
-               users = make([]*User, 0, len(mentionUsers))
+               users = make([]*user_model.User, 0, len(mentionUsers))
        }
 
-       unchecked := make([]*User, 0, len(mentionUsers))
+       unchecked := make([]*user_model.User, 0, len(mentionUsers))
        if err := db.GetEngine(ctx).
                Where("`user`.is_active = ?", true).
                And("`user`.prohibit_login = ?", false).
index 996a3a8563eef984e0b2183d9ed168a0179a6158..527549171ec7c9b4648cdc918886b771605984e0 100644 (file)
@@ -9,6 +9,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/util"
 )
 
@@ -31,7 +32,7 @@ func (issue *Issue) LoadAssignees() error {
 // This loads all assignees of an issue
 func (issue *Issue) loadAssignees(e db.Engine) (err error) {
        // Reset maybe preexisting assignees
-       issue.Assignees = []*User{}
+       issue.Assignees = []*user_model.User{}
 
        err = e.Table("`user`").
                Join("INNER", "issue_assignees", "assignee_id = `user`.id").
@@ -63,11 +64,11 @@ func GetAssigneeIDsByIssue(issueID int64) ([]int64, error) {
 }
 
 // GetAssigneesByIssue returns everyone assigned to that issue
-func GetAssigneesByIssue(issue *Issue) (assignees []*User, err error) {
+func GetAssigneesByIssue(issue *Issue) (assignees []*user_model.User, err error) {
        return getAssigneesByIssue(db.GetEngine(db.DefaultContext), issue)
 }
 
-func getAssigneesByIssue(e db.Engine, issue *Issue) (assignees []*User, err error) {
+func getAssigneesByIssue(e db.Engine, issue *Issue) (assignees []*user_model.User, err error) {
        err = issue.loadAssignees(e)
        if err != nil {
                return assignees, err
@@ -77,11 +78,11 @@ func getAssigneesByIssue(e db.Engine, issue *Issue) (assignees []*User, err erro
 }
 
 // IsUserAssignedToIssue returns true when the user is assigned to the issue
-func IsUserAssignedToIssue(issue *Issue, user *User) (isAssigned bool, err error) {
+func IsUserAssignedToIssue(issue *Issue, user *user_model.User) (isAssigned bool, err error) {
        return isUserAssignedToIssue(db.GetEngine(db.DefaultContext), issue, user)
 }
 
-func isUserAssignedToIssue(e db.Engine, issue *Issue, user *User) (isAssigned bool, err error) {
+func isUserAssignedToIssue(e db.Engine, issue *Issue, user *user_model.User) (isAssigned bool, err error) {
        return e.Get(&IssueAssignees{IssueID: issue.ID, AssigneeID: user.ID})
 }
 
@@ -92,7 +93,7 @@ func clearAssigneeByUserID(sess db.Engine, userID int64) (err error) {
 }
 
 // ToggleAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
-func (issue *Issue) ToggleAssignee(doer *User, assigneeID int64) (removed bool, comment *Comment, err error) {
+func (issue *Issue) ToggleAssignee(doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return false, nil, err
@@ -111,7 +112,7 @@ func (issue *Issue) ToggleAssignee(doer *User, assigneeID int64) (removed bool,
        return removed, comment, nil
 }
 
-func (issue *Issue) toggleAssignee(ctx context.Context, doer *User, assigneeID int64, isCreate bool) (removed bool, comment *Comment, err error) {
+func (issue *Issue) toggleAssignee(ctx context.Context, doer *user_model.User, assigneeID int64, isCreate bool) (removed bool, comment *Comment, err error) {
        sess := db.GetEngine(ctx)
        removed, err = toggleUserAssignee(sess, issue, assigneeID)
        if err != nil {
@@ -148,7 +149,7 @@ func (issue *Issue) toggleAssignee(ctx context.Context, doer *User, assigneeID i
 // toggles user assignee state in database
 func toggleUserAssignee(e db.Engine, issue *Issue, assigneeID int64) (removed bool, err error) {
        // Check if the user exists
-       assignee, err := getUserByID(e, assigneeID)
+       assignee, err := user_model.GetUserByIDEngine(e, assigneeID)
        if err != nil {
                return false, err
        }
@@ -196,7 +197,7 @@ func MakeIDsFromAPIAssigneesToAdd(oneAssignee string, multipleAssignees []string
        }
 
        // Get the IDs of all assignees
-       assigneeIDs, err = GetUserIDsByNames(requestAssignees, false)
+       assigneeIDs, err = user_model.GetUserIDsByNames(requestAssignees, false)
 
        return
 }
index b604f13bd5abb0be78a6522830c8bd047014adc8..dd9a42b572bf84fda3999a96a9428881cf88bff1 100644 (file)
@@ -8,6 +8,7 @@ import (
        "testing"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -20,19 +21,19 @@ func TestUpdateAssignee(t *testing.T) {
        assert.NoError(t, err)
 
        // Assign multiple users
-       user2, err := GetUserByID(2)
+       user2, err := user_model.GetUserByID(2)
        assert.NoError(t, err)
-       _, _, err = issue.ToggleAssignee(&User{ID: 1}, user2.ID)
+       _, _, err = issue.ToggleAssignee(&user_model.User{ID: 1}, user2.ID)
        assert.NoError(t, err)
 
-       user3, err := GetUserByID(3)
+       user3, err := user_model.GetUserByID(3)
        assert.NoError(t, err)
-       _, _, err = issue.ToggleAssignee(&User{ID: 1}, user3.ID)
+       _, _, err = issue.ToggleAssignee(&user_model.User{ID: 1}, user3.ID)
        assert.NoError(t, err)
 
-       user1, err := GetUserByID(1) // This user is already assigned (see the definition in fixtures), so running  UpdateAssignee should unassign him
+       user1, err := user_model.GetUserByID(1) // This user is already assigned (see the definition in fixtures), so running  UpdateAssignee should unassign him
        assert.NoError(t, err)
-       _, _, err = issue.ToggleAssignee(&User{ID: 1}, user1.ID)
+       _, _, err = issue.ToggleAssignee(&user_model.User{ID: 1}, user1.ID)
        assert.NoError(t, err)
 
        // Check if he got removed
@@ -44,7 +45,7 @@ func TestUpdateAssignee(t *testing.T) {
        assignees, err := GetAssigneesByIssue(issue)
        assert.NoError(t, err)
 
-       var expectedAssignees []*User
+       var expectedAssignees []*user_model.User
        expectedAssignees = append(expectedAssignees, user2, user3)
 
        for in, assignee := range assignees {
@@ -57,7 +58,7 @@ func TestUpdateAssignee(t *testing.T) {
        assert.True(t, isAssigned)
 
        // This user should not be assigned
-       isAssigned, err = IsUserAssignedToIssue(issue, &User{ID: 4})
+       isAssigned, err = IsUserAssignedToIssue(issue, &user_model.User{ID: 4})
        assert.NoError(t, err)
        assert.False(t, isAssigned)
 }
@@ -65,8 +66,8 @@ func TestUpdateAssignee(t *testing.T) {
 func TestMakeIDsFromAPIAssigneesToAdd(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       _ = unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
-       _ = unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       _ = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
+       _ = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        IDs, err := MakeIDsFromAPIAssigneesToAdd("", []string{""})
        assert.NoError(t, err)
index 8429596c821ff048eeefb662b63a544cbc434cf6..417caccfaf8a66de2cbfcad40b367672a08bff18 100644 (file)
@@ -17,6 +17,7 @@ import (
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/issues"
        repo_model "code.gitea.io/gitea/models/repo"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/json"
        "code.gitea.io/gitea/modules/log"
@@ -148,10 +149,10 @@ func (rd RoleDescriptor) HasRole(role string) bool {
 
 // Comment represents a comment in commit and issue page.
 type Comment struct {
-       ID               int64       `xorm:"pk autoincr"`
-       Type             CommentType `xorm:"INDEX"`
-       PosterID         int64       `xorm:"INDEX"`
-       Poster           *User       `xorm:"-"`
+       ID               int64            `xorm:"pk autoincr"`
+       Type             CommentType      `xorm:"INDEX"`
+       PosterID         int64            `xorm:"INDEX"`
+       Poster           *user_model.User `xorm:"-"`
        OriginalAuthor   string
        OriginalAuthorID int64
        IssueID          int64  `xorm:"INDEX"`
@@ -172,11 +173,11 @@ type Comment struct {
        Time             *TrackedTime `xorm:"-"`
        AssigneeID       int64
        RemovedAssignee  bool
-       Assignee         *User `xorm:"-"`
-       AssigneeTeamID   int64 `xorm:"NOT NULL DEFAULT 0"`
-       AssigneeTeam     *Team `xorm:"-"`
+       Assignee         *user_model.User `xorm:"-"`
+       AssigneeTeamID   int64            `xorm:"NOT NULL DEFAULT 0"`
+       AssigneeTeam     *Team            `xorm:"-"`
        ResolveDoerID    int64
-       ResolveDoer      *User `xorm:"-"`
+       ResolveDoer      *user_model.User `xorm:"-"`
        OldTitle         string
        NewTitle         string
        OldRef           string
@@ -284,11 +285,11 @@ func (c *Comment) loadPoster(e db.Engine) (err error) {
                return nil
        }
 
-       c.Poster, err = getUserByID(e, c.PosterID)
+       c.Poster, err = user_model.GetUserByIDEngine(e, c.PosterID)
        if err != nil {
-               if IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        c.PosterID = -1
-                       c.Poster = NewGhostUser()
+                       c.Poster = user_model.NewGhostUser()
                } else {
                        log.Error("getUserByID[%d]: %v", c.ID, err)
                }
@@ -519,12 +520,12 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
        var err error
 
        if c.AssigneeID > 0 && c.Assignee == nil {
-               c.Assignee, err = GetUserByIDCtx(db.DefaultContext, c.AssigneeID)
+               c.Assignee, err = user_model.GetUserByIDCtx(db.DefaultContext, c.AssigneeID)
                if err != nil {
-                       if !IsErrUserNotExist(err) {
+                       if !user_model.IsErrUserNotExist(err) {
                                return err
                        }
-                       c.Assignee = NewGhostUser()
+                       c.Assignee = user_model.NewGhostUser()
                }
        } else if c.AssigneeTeamID > 0 && c.AssigneeTeam == nil {
                if err = c.LoadIssue(); err != nil {
@@ -554,10 +555,10 @@ func (c *Comment) LoadResolveDoer() (err error) {
        if c.ResolveDoerID == 0 || c.Type != CommentTypeCode {
                return nil
        }
-       c.ResolveDoer, err = GetUserByIDCtx(db.DefaultContext, c.ResolveDoerID)
+       c.ResolveDoer, err = user_model.GetUserByIDCtx(db.DefaultContext, c.ResolveDoerID)
        if err != nil {
-               if IsErrUserNotExist(err) {
-                       c.ResolveDoer = NewGhostUser()
+               if user_model.IsErrUserNotExist(err) {
+                       c.ResolveDoer = user_model.NewGhostUser()
                        err = nil
                }
        }
@@ -628,7 +629,7 @@ func (c *Comment) LoadReview() error {
 
 var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines?`)
 
-func (c *Comment) checkInvalidation(doer *User, repo *git.Repository, branch string) error {
+func (c *Comment) checkInvalidation(doer *user_model.User, repo *git.Repository, branch string) error {
        // FIXME differentiate between previous and proposed line
        commit, err := repo.LineBlame(branch, repo.Path, c.TreePath, uint(c.UnsignedLine()))
        if err != nil && (strings.Contains(err.Error(), "fatal: no such path") || notEnoughLines.MatchString(err.Error())) {
@@ -647,7 +648,7 @@ func (c *Comment) checkInvalidation(doer *User, repo *git.Repository, branch str
 
 // CheckInvalidation checks if the line of code comment got changed by another commit.
 // If the line got changed the comment is going to be invalidated.
-func (c *Comment) CheckInvalidation(repo *git.Repository, doer *User, branch string) error {
+func (c *Comment) CheckInvalidation(repo *git.Repository, doer *user_model.User, branch string) error {
        return c.checkInvalidation(doer, repo, branch)
 }
 
@@ -824,7 +825,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
        return updateIssueCols(e, opts.Issue, "updated_unix")
 }
 
-func createDeadlineComment(ctx context.Context, doer *User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) {
+func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) {
        var content string
        var commentType CommentType
 
@@ -861,7 +862,7 @@ func createDeadlineComment(ctx context.Context, doer *User, issue *Issue, newDea
 }
 
 // Creates issue dependency comment
-func createIssueDependencyComment(ctx context.Context, doer *User, issue, dependentIssue *Issue, add bool) (err error) {
+func createIssueDependencyComment(ctx context.Context, doer *user_model.User, issue, dependentIssue *Issue, add bool) (err error) {
        cType := CommentTypeAddDependency
        if !add {
                cType = CommentTypeRemoveDependency
@@ -896,7 +897,7 @@ func createIssueDependencyComment(ctx context.Context, doer *User, issue, depend
 // CreateCommentOptions defines options for creating comment
 type CreateCommentOptions struct {
        Type  CommentType
-       Doer  *User
+       Doer  *user_model.User
        Repo  *Repository
        Issue *Issue
        Label *Label
@@ -952,7 +953,7 @@ func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) {
 }
 
 // CreateRefComment creates a commit reference comment to issue.
-func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commitSHA string) error {
+func CreateRefComment(doer *user_model.User, repo *Repository, issue *Issue, content, commitSHA string) error {
        if len(commitSHA) == 0 {
                return fmt.Errorf("cannot create reference with empty commit SHA")
        }
@@ -1072,7 +1073,7 @@ func CountComments(opts *FindCommentsOptions) (int64, error) {
 }
 
 // UpdateComment updates information of comment.
-func UpdateComment(c *Comment, doer *User) error {
+func UpdateComment(c *Comment, doer *user_model.User) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -1143,11 +1144,11 @@ func deleteComment(e db.Engine, comment *Comment) error {
 // CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS
 type CodeComments map[string]map[int64][]*Comment
 
-func fetchCodeComments(e db.Engine, issue *Issue, currentUser *User) (CodeComments, error) {
+func fetchCodeComments(e db.Engine, issue *Issue, currentUser *user_model.User) (CodeComments, error) {
        return fetchCodeCommentsByReview(e, issue, currentUser, nil)
 }
 
-func fetchCodeCommentsByReview(e db.Engine, issue *Issue, currentUser *User, review *Review) (CodeComments, error) {
+func fetchCodeCommentsByReview(e db.Engine, issue *Issue, currentUser *user_model.User, review *Review) (CodeComments, error) {
        pathToLineToComment := make(CodeComments)
        if review == nil {
                review = &Review{ID: 0}
@@ -1172,7 +1173,7 @@ func fetchCodeCommentsByReview(e db.Engine, issue *Issue, currentUser *User, rev
        return pathToLineToComment, nil
 }
 
-func findCodeComments(e db.Engine, opts FindCommentsOptions, issue *Issue, currentUser *User, review *Review) ([]*Comment, error) {
+func findCodeComments(e db.Engine, opts FindCommentsOptions, issue *Issue, currentUser *user_model.User, review *Review) ([]*Comment, error) {
        var comments []*Comment
        if review == nil {
                review = &Review{ID: 0}
@@ -1241,7 +1242,7 @@ func findCodeComments(e db.Engine, opts FindCommentsOptions, issue *Issue, curre
 }
 
 // FetchCodeCommentsByLine fetches the code comments for a given treePath and line number
-func FetchCodeCommentsByLine(issue *Issue, currentUser *User, treePath string, line int64) ([]*Comment, error) {
+func FetchCodeCommentsByLine(issue *Issue, currentUser *user_model.User, treePath string, line int64) ([]*Comment, error) {
        opts := FindCommentsOptions{
                Type:     CommentTypeCode,
                IssueID:  issue.ID,
@@ -1252,7 +1253,7 @@ func FetchCodeCommentsByLine(issue *Issue, currentUser *User, treePath string, l
 }
 
 // FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
-func FetchCodeComments(issue *Issue, currentUser *User) (CodeComments, error) {
+func FetchCodeComments(issue *Issue, currentUser *user_model.User) (CodeComments, error) {
        return fetchCodeComments(db.GetEngine(db.DefaultContext), issue, currentUser)
 }
 
@@ -1277,7 +1278,7 @@ func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID
 }
 
 // CreatePushPullComment create push code to pull base comment
-func CreatePushPullComment(pusher *User, pr *PullRequest, oldCommitID, newCommitID string) (comment *Comment, err error) {
+func CreatePushPullComment(pusher *user_model.User, pr *PullRequest, oldCommitID, newCommitID string) (comment *Comment, err error) {
        if pr.HasMerged || oldCommitID == "" || newCommitID == "" {
                return nil, nil
        }
index 3c587fc8f71914016e026249a3a443e8e7bf425e..ef6aff9cbe215104ff707ca9508567743787e130 100644 (file)
@@ -7,6 +7,7 @@ package models
 import (
        "code.gitea.io/gitea/models/db"
        repo_model "code.gitea.io/gitea/models/repo"
+       user_model "code.gitea.io/gitea/models/user"
 )
 
 // CommentList defines a list of comments
@@ -28,7 +29,7 @@ func (comments CommentList) loadPosters(e db.Engine) error {
        }
 
        posterIDs := comments.getPosterIDs()
-       posterMaps := make(map[int64]*User, len(posterIDs))
+       posterMaps := make(map[int64]*user_model.User, len(posterIDs))
        left := len(posterIDs)
        for left > 0 {
                limit := defaultMaxInSize
@@ -51,7 +52,7 @@ func (comments CommentList) loadPosters(e db.Engine) error {
                }
                var ok bool
                if comment.Poster, ok = posterMaps[comment.PosterID]; !ok {
-                       comment.Poster = NewGhostUser()
+                       comment.Poster = user_model.NewGhostUser()
                }
        }
        return nil
@@ -217,7 +218,7 @@ func (comments CommentList) loadAssignees(e db.Engine) error {
        }
 
        assigneeIDs := comments.getAssigneeIDs()
-       assignees := make(map[int64]*User, len(assigneeIDs))
+       assignees := make(map[int64]*user_model.User, len(assigneeIDs))
        left := len(assigneeIDs)
        for left > 0 {
                limit := defaultMaxInSize
@@ -226,13 +227,13 @@ func (comments CommentList) loadAssignees(e db.Engine) error {
                }
                rows, err := e.
                        In("id", assigneeIDs[:limit]).
-                       Rows(new(User))
+                       Rows(new(user_model.User))
                if err != nil {
                        return err
                }
 
                for rows.Next() {
-                       var user User
+                       var user user_model.User
                        err = rows.Scan(&user)
                        if err != nil {
                                rows.Close()
index 4d3607b3e15b30e4b03d51b467f7a70b18b00dfb..5ab4892bc7cd8b2368600f1fd99524246b578b5f 100644 (file)
@@ -9,6 +9,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -18,7 +19,7 @@ func TestCreateComment(t *testing.T) {
 
        issue := unittest.AssertExistsAndLoadBean(t, &Issue{}).(*Issue)
        repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: issue.RepoID}).(*Repository)
-       doer := unittest.AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
+       doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        now := time.Now().Unix()
        comment, err := CreateComment(&CreateCommentOptions{
@@ -46,7 +47,7 @@ func TestFetchCodeComments(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
        issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        res, err := FetchCodeComments(issue, user)
        assert.NoError(t, err)
        assert.Contains(t, res, "README.md")
@@ -54,7 +55,7 @@ func TestFetchCodeComments(t *testing.T) {
        assert.Len(t, res["README.md"][4], 1)
        assert.Equal(t, int64(4), res["README.md"][4][0].ID)
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        res, err = FetchCodeComments(issue, user2)
        assert.NoError(t, err)
        assert.Len(t, res, 1)
index ab81ef0c68442d30b081e760cbf2bbb5997a6feb..9fef652b4e67b36a5f324dd2dde5adac13a46baa 100644 (file)
@@ -7,6 +7,7 @@ package models
 import (
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/timeutil"
@@ -36,7 +37,7 @@ const (
 )
 
 // CreateIssueDependency creates a new dependency for an issue
-func CreateIssueDependency(user *User, issue, dep *Issue) error {
+func CreateIssueDependency(user *user_model.User, issue, dep *Issue) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -78,7 +79,7 @@ func CreateIssueDependency(user *User, issue, dep *Issue) error {
 }
 
 // RemoveIssueDependency removes a dependency from an issue
-func RemoveIssueDependency(user *User, issue, dep *Issue, depType DependencyType) (err error) {
+func RemoveIssueDependency(user *user_model.User, issue, dep *Issue, depType DependencyType) (err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
index 86ac98b733a6b7b90dd719bb1b9c4bfaa616d4c2..61215dedeffeb5b27cc8b9e5307d81e377b8cf30 100644 (file)
@@ -8,6 +8,7 @@ import (
        "testing"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -16,7 +17,7 @@ func TestCreateIssueDependency(t *testing.T) {
        // Prepare
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user1, err := GetUserByID(1)
+       user1, err := user_model.GetUserByID(1)
        assert.NoError(t, err)
 
        issue1, err := GetIssueByID(1)
index 2858b12dde64ee641def8f73c3a1fa9dac5447e8..9b36d8dfdf17bac604fb36af8973c3121f63d75a 100644 (file)
@@ -15,6 +15,7 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/timeutil"
 
        "xorm.io/builder"
@@ -665,7 +666,7 @@ func HasIssueLabel(issueID, labelID int64) bool {
 
 // newIssueLabel this function creates a new label it does not check if the label is valid for the issue
 // YOU MUST CHECK THIS BEFORE THIS FUNCTION
-func newIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *User) (err error) {
+func newIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *user_model.User) (err error) {
        e := db.GetEngine(ctx)
        if _, err = e.Insert(&IssueLabel{
                IssueID: issue.ID,
@@ -694,7 +695,7 @@ func newIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *User)
 }
 
 // NewIssueLabel creates a new issue-label relation.
-func NewIssueLabel(issue *Issue, label *Label, doer *User) (err error) {
+func NewIssueLabel(issue *Issue, label *Label, doer *user_model.User) (err error) {
        if HasIssueLabel(issue.ID, label.ID) {
                return nil
        }
@@ -728,7 +729,7 @@ func NewIssueLabel(issue *Issue, label *Label, doer *User) (err error) {
 }
 
 // newIssueLabels add labels to an issue. It will check if the labels are valid for the issue
-func newIssueLabels(ctx context.Context, issue *Issue, labels []*Label, doer *User) (err error) {
+func newIssueLabels(ctx context.Context, issue *Issue, labels []*Label, doer *user_model.User) (err error) {
        e := db.GetEngine(ctx)
        if err = issue.loadRepo(e); err != nil {
                return err
@@ -749,7 +750,7 @@ func newIssueLabels(ctx context.Context, issue *Issue, labels []*Label, doer *Us
 }
 
 // NewIssueLabels creates a list of issue-label relations.
-func NewIssueLabels(issue *Issue, labels []*Label, doer *User) (err error) {
+func NewIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -768,7 +769,7 @@ func NewIssueLabels(issue *Issue, labels []*Label, doer *User) (err error) {
        return committer.Commit()
 }
 
-func deleteIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *User) (err error) {
+func deleteIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *user_model.User) (err error) {
        e := db.GetEngine(ctx)
        if count, err := e.Delete(&IssueLabel{
                IssueID: issue.ID,
@@ -798,7 +799,7 @@ func deleteIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *Use
 }
 
 // DeleteIssueLabel deletes issue-label relation.
-func DeleteIssueLabel(issue *Issue, label *Label, doer *User) (err error) {
+func DeleteIssueLabel(issue *Issue, label *Label, doer *user_model.User) (err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
index d0f807a56e6a36812276472acd88d21315483520..aa3c92b28277c375c06ca7ba2a339c2450fc930d 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -296,7 +297,7 @@ func TestNewIssueLabel(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
        label := unittest.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
        issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
-       doer := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        // add new IssueLabel
        prevNumIssues := label.NumIssues
@@ -322,7 +323,7 @@ func TestNewIssueLabels(t *testing.T) {
        label1 := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
        label2 := unittest.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
        issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 5}).(*Issue)
-       doer := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        assert.NoError(t, NewIssueLabels(issue, []*Label{label1, label2}, doer))
        unittest.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
@@ -352,7 +353,7 @@ func TestDeleteIssueLabel(t *testing.T) {
        testSuccess := func(labelID, issueID, doerID int64) {
                label := unittest.AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
                issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue)
-               doer := unittest.AssertExistsAndLoadBean(t, &User{ID: doerID}).(*User)
+               doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: doerID}).(*user_model.User)
 
                expectedNumIssues := label.NumIssues
                expectedNumClosedIssues := label.NumClosedIssues
index 6eeb2a961a56e982ef2d1cebeffc189d1a22274a..7c98f60b3a3c5512ddd6d1c3ad1b8ac6d7a9d90f 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        repo_model "code.gitea.io/gitea/models/repo"
+       user_model "code.gitea.io/gitea/models/user"
 
        "xorm.io/builder"
 )
@@ -84,7 +85,7 @@ func (issues IssueList) loadPosters(e db.Engine) error {
        }
 
        posterIDs := issues.getPosterIDs()
-       posterMaps := make(map[int64]*User, len(posterIDs))
+       posterMaps := make(map[int64]*user_model.User, len(posterIDs))
        left := len(posterIDs)
        for left > 0 {
                limit := defaultMaxInSize
@@ -107,7 +108,7 @@ func (issues IssueList) loadPosters(e db.Engine) error {
                }
                var ok bool
                if issue.Poster, ok = posterMaps[issue.PosterID]; !ok {
-                       issue.Poster = NewGhostUser()
+                       issue.Poster = user_model.NewGhostUser()
                }
        }
        return nil
@@ -219,11 +220,11 @@ func (issues IssueList) loadAssignees(e db.Engine) error {
        }
 
        type AssigneeIssue struct {
-               IssueAssignee *IssueAssignees `xorm:"extends"`
-               Assignee      *User           `xorm:"extends"`
+               IssueAssignee *IssueAssignees  `xorm:"extends"`
+               Assignee      *user_model.User `xorm:"extends"`
        }
 
-       assignees := make(map[int64][]*User, len(issues))
+       assignees := make(map[int64][]*user_model.User, len(issues))
        issueIDs := issues.getIssueIDs()
        left := len(issueIDs)
        for left > 0 {
index d0b9c660c210da4fc12eb8968c8c59c8cab54368..66a932225ad68e28e7ffd738b76bd227389f41c6 100644 (file)
@@ -4,11 +4,14 @@
 
 package models
 
-import "code.gitea.io/gitea/models/db"
+import (
+       "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
+)
 
 // IssueLockOptions defines options for locking and/or unlocking an issue/PR
 type IssueLockOptions struct {
-       Doer   *User
+       Doer   *user_model.User
        Issue  *Issue
        Reason string
 }
index de4e13b4bb40cf15eb1162f55e119057de4a8f17..a85c86546458591ef87609bb40c06e29cd9c048f 100644 (file)
@@ -11,6 +11,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/timeutil"
@@ -267,7 +268,7 @@ func changeMilestoneStatus(e db.Engine, m *Milestone, isClosed bool) error {
        return updateRepoMilestoneNum(e, m.RepoID)
 }
 
-func changeMilestoneAssign(ctx context.Context, doer *User, issue *Issue, oldMilestoneID int64) error {
+func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *Issue, oldMilestoneID int64) error {
        e := db.GetEngine(ctx)
        if err := updateIssueCols(e, issue, "milestone_id"); err != nil {
                return err
@@ -307,7 +308,7 @@ func changeMilestoneAssign(ctx context.Context, doer *User, issue *Issue, oldMil
 }
 
 // ChangeMilestoneAssign changes assignment of milestone for issue.
-func ChangeMilestoneAssign(issue *Issue, doer *User, oldMilestoneID int64) (err error) {
+func ChangeMilestoneAssign(issue *Issue, doer *user_model.User, oldMilestoneID int64) (err error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
index 2956e40f0658026fe58ada7593594f749b85e616..21d90a61189a8689c85cd87fa93b084e9bbab9b9 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/timeutil"
@@ -240,7 +241,7 @@ func TestUpdateMilestoneCounters(t *testing.T) {
 func TestChangeMilestoneAssign(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
        issue := unittest.AssertExistsAndLoadBean(t, &Issue{RepoID: 1}).(*Issue)
-       doer := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        assert.NotNil(t, issue)
        assert.NotNil(t, doer)
 
index 933246544b7a18c20f7d9be51e0f4553c29f0036..fb34db4ed58fd5198d3fb5921099d97195fb0dd6 100644 (file)
@@ -9,6 +9,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/timeutil"
 
@@ -24,7 +25,7 @@ type Reaction struct {
        UserID           int64              `xorm:"INDEX UNIQUE(s) NOT NULL"`
        OriginalAuthorID int64              `xorm:"INDEX UNIQUE(s) NOT NULL DEFAULT(0)"`
        OriginalAuthor   string             `xorm:"INDEX UNIQUE(s)"`
-       User             *User              `xorm:"-"`
+       User             *user_model.User   `xorm:"-"`
        CreatedUnix      timeutil.TimeStamp `xorm:"INDEX created"`
 }
 
@@ -136,7 +137,7 @@ func createReaction(e db.Engine, opts *ReactionOptions) (*Reaction, error) {
 // ReactionOptions defines options for creating or deleting reactions
 type ReactionOptions struct {
        Type    string
-       Doer    *User
+       Doer    *user_model.User
        Issue   *Issue
        Comment *Comment
 }
@@ -165,7 +166,7 @@ func CreateReaction(opts *ReactionOptions) (*Reaction, error) {
 }
 
 // CreateIssueReaction creates a reaction on issue.
-func CreateIssueReaction(doer *User, issue *Issue, content string) (*Reaction, error) {
+func CreateIssueReaction(doer *user_model.User, issue *Issue, content string) (*Reaction, error) {
        return CreateReaction(&ReactionOptions{
                Type:  content,
                Doer:  doer,
@@ -174,7 +175,7 @@ func CreateIssueReaction(doer *User, issue *Issue, content string) (*Reaction, e
 }
 
 // CreateCommentReaction creates a reaction on comment.
-func CreateCommentReaction(doer *User, issue *Issue, comment *Comment, content string) (*Reaction, error) {
+func CreateCommentReaction(doer *user_model.User, issue *Issue, comment *Comment, content string) (*Reaction, error) {
        return CreateReaction(&ReactionOptions{
                Type:    content,
                Doer:    doer,
@@ -216,7 +217,7 @@ func DeleteReaction(opts *ReactionOptions) error {
 }
 
 // DeleteIssueReaction deletes a reaction on issue.
-func DeleteIssueReaction(doer *User, issue *Issue, content string) error {
+func DeleteIssueReaction(doer *user_model.User, issue *Issue, content string) error {
        return DeleteReaction(&ReactionOptions{
                Type:  content,
                Doer:  doer,
@@ -225,7 +226,7 @@ func DeleteIssueReaction(doer *User, issue *Issue, content string) error {
 }
 
 // DeleteCommentReaction deletes a reaction on comment.
-func DeleteCommentReaction(doer *User, issue *Issue, comment *Comment, content string) error {
+func DeleteCommentReaction(doer *user_model.User, issue *Issue, comment *Comment, content string) error {
        return DeleteReaction(&ReactionOptions{
                Type:    content,
                Doer:    doer,
@@ -235,11 +236,11 @@ func DeleteCommentReaction(doer *User, issue *Issue, comment *Comment, content s
 }
 
 // LoadUser load user of reaction
-func (r *Reaction) LoadUser() (*User, error) {
+func (r *Reaction) LoadUser() (*user_model.User, error) {
        if r.User != nil {
                return r.User, nil
        }
-       user, err := GetUserByIDCtx(db.DefaultContext, r.UserID)
+       user, err := user_model.GetUserByIDCtx(db.DefaultContext, r.UserID)
        if err != nil {
                return nil, err
        }
@@ -285,13 +286,13 @@ func (list ReactionList) getUserIDs() []int64 {
        return keysInt64(userIDs)
 }
 
-func (list ReactionList) loadUsers(e db.Engine, repo *Repository) ([]*User, error) {
+func (list ReactionList) loadUsers(e db.Engine, repo *Repository) ([]*user_model.User, error) {
        if len(list) == 0 {
                return nil, nil
        }
 
        userIDs := list.getUserIDs()
-       userMaps := make(map[int64]*User, len(userIDs))
+       userMaps := make(map[int64]*user_model.User, len(userIDs))
        err := e.
                In("id", userIDs).
                Find(&userMaps)
@@ -301,18 +302,18 @@ func (list ReactionList) loadUsers(e db.Engine, repo *Repository) ([]*User, erro
 
        for _, reaction := range list {
                if reaction.OriginalAuthor != "" {
-                       reaction.User = NewReplaceUser(fmt.Sprintf("%s(%s)", reaction.OriginalAuthor, repo.OriginalServiceType.Name()))
+                       reaction.User = user_model.NewReplaceUser(fmt.Sprintf("%s(%s)", reaction.OriginalAuthor, repo.OriginalServiceType.Name()))
                } else if user, ok := userMaps[reaction.UserID]; ok {
                        reaction.User = user
                } else {
-                       reaction.User = NewGhostUser()
+                       reaction.User = user_model.NewGhostUser()
                }
        }
        return valuesUser(userMaps), nil
 }
 
 // LoadUsers loads reactions' all users
-func (list ReactionList) LoadUsers(repo *Repository) ([]*User, error) {
+func (list ReactionList) LoadUsers(repo *Repository) ([]*user_model.User, error) {
        return list.loadUsers(db.GetEngine(db.DefaultContext), repo)
 }
 
index c01e4add7acfc3210f67da4b30356bd10badd18b..458250ac5864e55db1be9c40b89dc62f89716d5a 100644 (file)
@@ -8,12 +8,13 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
 
        "github.com/stretchr/testify/assert"
 )
 
-func addReaction(t *testing.T, doer *User, issue *Issue, comment *Comment, content string) {
+func addReaction(t *testing.T, doer *user_model.User, issue *Issue, comment *Comment, content string) {
        var reaction *Reaction
        var err error
        if comment == nil {
@@ -28,7 +29,7 @@ func addReaction(t *testing.T, doer *User, issue *Issue, comment *Comment, conte
 func TestIssueAddReaction(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
 
@@ -40,7 +41,7 @@ func TestIssueAddReaction(t *testing.T) {
 func TestIssueAddDuplicateReaction(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
 
@@ -61,7 +62,7 @@ func TestIssueAddDuplicateReaction(t *testing.T) {
 func TestIssueDeleteReaction(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
 
@@ -78,11 +79,11 @@ func TestIssueReactionCount(t *testing.T) {
 
        setting.UI.ReactionMaxUserNum = 2
 
-       user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
-       user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
-       user4 := unittest.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
-       ghost := NewGhostUser()
+       user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
+       ghost := user_model.NewGhostUser()
 
        issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
 
@@ -114,7 +115,7 @@ func TestIssueReactionCount(t *testing.T) {
 func TestIssueCommentAddReaction(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
 
@@ -128,10 +129,10 @@ func TestIssueCommentAddReaction(t *testing.T) {
 func TestIssueCommentDeleteReaction(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
-       user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
-       user4 := unittest.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
+       user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
 
        issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
        repo1 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: issue1.RepoID}).(*Repository)
@@ -155,7 +156,7 @@ func TestIssueCommentDeleteReaction(t *testing.T) {
 func TestIssueCommentReactionCount(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        issue1 := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
 
index eaec5d924e8c905c0cf86fab27e6253277ab3789..7754e90a864b2fa9721b7e48b4d3e7dc686d4de3 100644 (file)
@@ -10,6 +10,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/timeutil"
 )
 
@@ -104,7 +105,7 @@ func hasUserStopwatch(e db.Engine, userID int64) (exists bool, sw *Stopwatch, er
 }
 
 // FinishIssueStopwatchIfPossible if stopwatch exist then finish it otherwise ignore
-func FinishIssueStopwatchIfPossible(ctx context.Context, user *User, issue *Issue) error {
+func FinishIssueStopwatchIfPossible(ctx context.Context, user *user_model.User, issue *Issue) error {
        _, exists, err := getStopwatch(ctx, user.ID, issue.ID)
        if err != nil {
                return err
@@ -116,7 +117,7 @@ func FinishIssueStopwatchIfPossible(ctx context.Context, user *User, issue *Issu
 }
 
 // CreateOrStopIssueStopwatch create an issue stopwatch if it's not exist, otherwise finish it
-func CreateOrStopIssueStopwatch(user *User, issue *Issue) error {
+func CreateOrStopIssueStopwatch(user *user_model.User, issue *Issue) error {
        _, exists, err := getStopwatch(db.DefaultContext, user.ID, issue.ID)
        if err != nil {
                return err
@@ -128,7 +129,7 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error {
 }
 
 // FinishIssueStopwatch if stopwatch exist then finish it otherwise return an error
-func FinishIssueStopwatch(ctx context.Context, user *User, issue *Issue) error {
+func FinishIssueStopwatch(ctx context.Context, user *user_model.User, issue *Issue) error {
        sw, exists, err := getStopwatch(ctx, user.ID, issue.ID)
        if err != nil {
                return err
@@ -174,7 +175,7 @@ func FinishIssueStopwatch(ctx context.Context, user *User, issue *Issue) error {
 }
 
 // CreateIssueStopwatch creates a stopwatch if not exist, otherwise return an error
-func CreateIssueStopwatch(ctx context.Context, user *User, issue *Issue) error {
+func CreateIssueStopwatch(ctx context.Context, user *user_model.User, issue *Issue) error {
        e := db.GetEngine(ctx)
        if err := issue.loadRepo(e); err != nil {
                return err
@@ -223,7 +224,7 @@ func CreateIssueStopwatch(ctx context.Context, user *User, issue *Issue) error {
 }
 
 // CancelStopwatch removes the given stopwatch and logs it into issue's timeline.
-func CancelStopwatch(user *User, issue *Issue) error {
+func CancelStopwatch(user *user_model.User, issue *Issue) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -235,7 +236,7 @@ func CancelStopwatch(user *User, issue *Issue) error {
        return committer.Commit()
 }
 
-func cancelStopwatch(ctx context.Context, user *User, issue *Issue) error {
+func cancelStopwatch(ctx context.Context, user *user_model.User, issue *Issue) error {
        e := db.GetEngine(ctx)
        sw, exists, err := getStopwatch(ctx, user.ID, issue.ID)
        if err != nil {
index ceb579d0955712292a313d2e52afc854a6a55107..0f578f101f14b86e110d3ed98925da4c881b5574 100644 (file)
@@ -8,6 +8,7 @@ import (
        "testing"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/timeutil"
 
        "github.com/stretchr/testify/assert"
@@ -16,7 +17,7 @@ import (
 func TestCancelStopwatch(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user1, err := GetUserByID(1)
+       user1, err := user_model.GetUserByID(1)
        assert.NoError(t, err)
 
        issue1, err := GetIssueByID(1)
@@ -56,9 +57,9 @@ func TestHasUserStopwatch(t *testing.T) {
 func TestCreateOrStopIssueStopwatch(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user2, err := GetUserByID(2)
+       user2, err := user_model.GetUserByID(2)
        assert.NoError(t, err)
-       user3, err := GetUserByID(3)
+       user3, err := user_model.GetUserByID(3)
        assert.NoError(t, err)
 
        issue1, err := GetIssueByID(1)
index 7942b7e78539ac92f01bac3315727a11d829895b..a9e19438d6c1eeb4cc2a9cb47000361251aa5e10 100644 (file)
@@ -13,6 +13,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -23,7 +24,7 @@ func TestIssue_ReplaceLabels(t *testing.T) {
        testSuccess := func(issueID int64, labelIDs []int64) {
                issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue)
                repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: issue.RepoID}).(*Repository)
-               doer := unittest.AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
+               doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
                labels := make([]*Label, len(labelIDs))
                for i, labelID := range labelIDs {
@@ -110,7 +111,7 @@ func TestIssue_ClearLabels(t *testing.T) {
        for _, test := range tests {
                assert.NoError(t, unittest.PrepareTestDatabase())
                issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: test.issueID}).(*Issue)
-               doer := unittest.AssertExistsAndLoadBean(t, &User{ID: test.doerID}).(*User)
+               doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID}).(*user_model.User)
                assert.NoError(t, issue.ClearLabels(doer))
                unittest.AssertNotExistsBean(t, &IssueLabel{IssueID: test.issueID})
        }
@@ -322,7 +323,7 @@ func TestIssue_SearchIssueIDsByKeyword(t *testing.T) {
 
 func TestGetRepoIDsForIssuesOptions(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        for _, test := range []struct {
                Opts            IssuesOptions
                ExpectedRepoIDs []int64
@@ -354,7 +355,7 @@ func testInsertIssue(t *testing.T, title, content string, expectIndex int64) *Is
        var newIssue Issue
        t.Run(title, func(t *testing.T) {
                repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
-               user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+               user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
                issue := Issue{
                        RepoID:   repo.ID,
@@ -396,10 +397,10 @@ func TestIssue_ResolveMentions(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
        testSuccess := func(owner, repo, doer string, mentions []string, expected []int64) {
-               o := unittest.AssertExistsAndLoadBean(t, &User{LowerName: owner}).(*User)
+               o := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: owner}).(*user_model.User)
                r := unittest.AssertExistsAndLoadBean(t, &Repository{OwnerID: o.ID, LowerName: repo}).(*Repository)
                issue := &Issue{RepoID: r.ID}
-               d := unittest.AssertExistsAndLoadBean(t, &User{LowerName: doer}).(*User)
+               d := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: doer}).(*user_model.User)
                resolved, err := issue.ResolveMentionsByVisibility(db.DefaultContext, d, mentions)
                assert.NoError(t, err)
                ids := make([]int64, len(resolved))
index 55d585a55ccf4378fde686d5349d2cc8a1faa458..392bf91e1944a65710c4df4ff3dc988bb4692139 100644 (file)
@@ -8,6 +8,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
 
        "xorm.io/builder"
@@ -15,15 +16,15 @@ import (
 
 // TrackedTime represents a time that was spent for a specific issue.
 type TrackedTime struct {
-       ID          int64     `xorm:"pk autoincr"`
-       IssueID     int64     `xorm:"INDEX"`
-       Issue       *Issue    `xorm:"-"`
-       UserID      int64     `xorm:"INDEX"`
-       User        *User     `xorm:"-"`
-       Created     time.Time `xorm:"-"`
-       CreatedUnix int64     `xorm:"created"`
-       Time        int64     `xorm:"NOT NULL"`
-       Deleted     bool      `xorm:"NOT NULL DEFAULT false"`
+       ID          int64            `xorm:"pk autoincr"`
+       IssueID     int64            `xorm:"INDEX"`
+       Issue       *Issue           `xorm:"-"`
+       UserID      int64            `xorm:"INDEX"`
+       User        *user_model.User `xorm:"-"`
+       Created     time.Time        `xorm:"-"`
+       CreatedUnix int64            `xorm:"created"`
+       Time        int64            `xorm:"NOT NULL"`
+       Deleted     bool             `xorm:"NOT NULL DEFAULT false"`
 }
 
 func init() {
@@ -55,7 +56,7 @@ func (t *TrackedTime) loadAttributes(e db.Engine) (err error) {
                }
        }
        if t.User == nil {
-               t.User, err = getUserByID(e, t.UserID)
+               t.User, err = user_model.GetUserByIDEngine(e, t.UserID)
                if err != nil {
                        return
                }
@@ -153,7 +154,7 @@ func GetTrackedSeconds(opts FindTrackedTimesOptions) (int64, error) {
 }
 
 // AddTime will add the given time (in seconds) to the issue
-func AddTime(user *User, issue *Issue, amount int64, created time.Time) (*TrackedTime, error) {
+func AddTime(user *user_model.User, issue *Issue, amount int64, created time.Time) (*TrackedTime, error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return nil, err
@@ -184,7 +185,7 @@ func AddTime(user *User, issue *Issue, amount int64, created time.Time) (*Tracke
        return t, committer.Commit()
 }
 
-func addTime(e db.Engine, user *User, issue *Issue, amount int64, created time.Time) (*TrackedTime, error) {
+func addTime(e db.Engine, user *user_model.User, issue *Issue, amount int64, created time.Time) (*TrackedTime, error) {
        if created.IsZero() {
                created = time.Now()
        }
@@ -202,7 +203,7 @@ func addTime(e db.Engine, user *User, issue *Issue, amount int64, created time.T
 }
 
 // TotalTimes returns the spent time for each user by an issue
-func TotalTimes(options *FindTrackedTimesOptions) (map[*User]string, error) {
+func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string, error) {
        trackedTimes, err := GetTrackedTimes(options)
        if err != nil {
                return nil, err
@@ -213,12 +214,12 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*User]string, error) {
                totalTimesByUser[t.UserID] += t.Time
        }
 
-       totalTimes := make(map[*User]string)
+       totalTimes := make(map[*user_model.User]string)
        // Fetching User and making time human readable
        for userID, total := range totalTimesByUser {
-               user, err := GetUserByID(userID)
+               user, err := user_model.GetUserByID(userID)
                if err != nil {
-                       if IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                continue
                        }
                        return nil, err
@@ -229,7 +230,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*User]string, error) {
 }
 
 // DeleteIssueUserTimes deletes times for issue
-func DeleteIssueUserTimes(issue *Issue, user *User) error {
+func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
index 83420f5a152a6f9d43c5c372ba03d2f9ec46f62f..97efd8bb729cfa334009eeb6b1d515a1d6b731b1 100644 (file)
@@ -9,6 +9,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -16,7 +17,7 @@ import (
 func TestAddTime(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user3, err := GetUserByID(3)
+       user3, err := user_model.GetUserByID(3)
        assert.NoError(t, err)
 
        issue1, err := GetIssueByID(1)
index 5bac406ad01bddf8bed23ffd764841f9f0db3c87..bf5c2593a3f0788439d0a9e3fdfd7060731e0e4f 100644 (file)
@@ -6,6 +6,7 @@ package models
 
 import (
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/timeutil"
 )
 
@@ -71,7 +72,7 @@ func getIssueWatch(e db.Engine, userID, issueID int64) (iw *IssueWatch, exists b
 
 // CheckIssueWatch check if an user is watching an issue
 // it takes participants and repo watch into account
-func CheckIssueWatch(user *User, issue *Issue) (bool, error) {
+func CheckIssueWatch(user *user_model.User, issue *Issue) (bool, error) {
        iw, exist, err := getIssueWatch(db.GetEngine(db.DefaultContext), user.ID, issue.ID)
        if err != nil {
                return false, err
index 55483ce57bd0b1b5525ddadda2e6263fea64c36d..ceaff62be12ceda257f6bab67b6c01c2fbec27a9 100644 (file)
@@ -9,6 +9,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/references"
 )
@@ -21,7 +22,7 @@ type crossReference struct {
 // crossReferencesContext is context to pass along findCrossReference functions
 type crossReferencesContext struct {
        Type        CommentType
-       Doer        *User
+       Doer        *user_model.User
        OrigIssue   *Issue
        OrigComment *Comment
        RemoveOld   bool
@@ -60,7 +61,7 @@ func neuterCrossReferencesIds(e db.Engine, ids []int64) error {
 //          \/     \/            \/
 //
 
-func (issue *Issue) addCrossReferences(stdCtx context.Context, doer *User, removeOld bool) error {
+func (issue *Issue) addCrossReferences(stdCtx context.Context, doer *user_model.User, removeOld bool) error {
        var commentType CommentType
        if issue.IsPull {
                commentType = CommentTypePullRef
@@ -242,7 +243,7 @@ func (issue *Issue) verifyReferencedIssue(e db.Engine, ctx *crossReferencesConte
 //         \/             \/      \/     \/     \/
 //
 
-func (comment *Comment) addCrossReferences(stdCtx context.Context, doer *User, removeOld bool) error {
+func (comment *Comment) addCrossReferences(stdCtx context.Context, doer *user_model.User, removeOld bool) error {
        if comment.Type != CommentTypeCode && comment.Type != CommentTypeComment {
                return nil
        }
index c40e545fa89c9300662042e59f3628616425b08d..06f937c80d71911bd5151053e11f4e13c0bc65d8 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/references"
 
        "github.com/stretchr/testify/assert"
@@ -79,7 +80,7 @@ func TestXRef_NeuterCrossReferences(t *testing.T) {
        assert.Equal(t, CommentTypeIssueRef, ref.Type)
        assert.Equal(t, references.XRefActionNone, ref.RefAction)
 
-       d := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        i.Title = "title2, no mentions"
        assert.NoError(t, i.ChangeTitle(d, title))
 
@@ -91,7 +92,7 @@ func TestXRef_NeuterCrossReferences(t *testing.T) {
 func TestXRef_ResolveCrossReferences(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       d := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        i1 := testCreateIssue(t, 1, 2, "title1", "content1", false)
        i2 := testCreateIssue(t, 1, 2, "title2", "content2", false)
@@ -126,7 +127,7 @@ func TestXRef_ResolveCrossReferences(t *testing.T) {
 
 func testCreateIssue(t *testing.T, repo, doer int64, title, content string, ispull bool) *Issue {
        r := unittest.AssertExistsAndLoadBean(t, &Repository{ID: repo}).(*Repository)
-       d := unittest.AssertExistsAndLoadBean(t, &User{ID: doer}).(*User)
+       d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: doer}).(*user_model.User)
 
        idx, err := db.GetNextResourceIndex("issue_index", r.ID)
        assert.NoError(t, err)
@@ -157,7 +158,7 @@ func testCreateIssue(t *testing.T, repo, doer int64, title, content string, ispu
 
 func testCreatePR(t *testing.T, repo, doer int64, title, content string) *PullRequest {
        r := unittest.AssertExistsAndLoadBean(t, &Repository{ID: repo}).(*Repository)
-       d := unittest.AssertExistsAndLoadBean(t, &User{ID: doer}).(*User)
+       d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: doer}).(*user_model.User)
        i := &Issue{RepoID: r.ID, PosterID: d.ID, Poster: d, Title: title, Content: content, IsPull: true}
        pr := &PullRequest{HeadRepoID: repo, BaseRepoID: repo, HeadBranch: "head", BaseBranch: "base", Status: PullRequestStatusMergeable}
        assert.NoError(t, NewPullRequest(r, i, nil, nil, pr))
@@ -166,7 +167,7 @@ func testCreatePR(t *testing.T, repo, doer int64, title, content string) *PullRe
 }
 
 func testCreateComment(t *testing.T, repo, doer, issue int64, content string) *Comment {
-       d := unittest.AssertExistsAndLoadBean(t, &User{ID: doer}).(*User)
+       d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: doer}).(*user_model.User)
        i := unittest.AssertExistsAndLoadBean(t, &Issue{ID: issue}).(*Issue)
        c := &Comment{Type: CommentTypeComment, PosterID: doer, Poster: d, IssueID: issue, Issue: i, Content: content}
 
index 40539d2b781838e1566839c4f8cf76ce148d8552..da5e61ed0bcddc525a236c104407617c03861b4e 100644 (file)
@@ -8,6 +8,7 @@ import (
        "errors"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/lfs"
        "code.gitea.io/gitea/modules/timeutil"
 
@@ -132,7 +133,7 @@ func (repo *Repository) CountLFSMetaObjects() (int64, error) {
 }
 
 // LFSObjectAccessible checks if a provided Oid is accessible to the user
-func LFSObjectAccessible(user *User, oid string) (bool, error) {
+func LFSObjectAccessible(user *user_model.User, oid string) (bool, error) {
        if user.IsAdmin {
                count, err := db.GetEngine(db.DefaultContext).Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
                return count > 0, err
@@ -143,7 +144,7 @@ func LFSObjectAccessible(user *User, oid string) (bool, error) {
 }
 
 // LFSAutoAssociate auto associates accessible LFSMetaObjects
-func LFSAutoAssociate(metas []*LFSMetaObject, user *User, repoID int64) error {
+func LFSAutoAssociate(metas []*LFSMetaObject, user *user_model.User, repoID int64) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
index 943699290f201aad5e4809ad374c385669e57e4b..15513ea1dd83a4cd49081d7d29897d8d1454b291 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
 
        "xorm.io/xorm"
@@ -22,7 +23,6 @@ type LFSLock struct {
        ID      int64       `xorm:"pk autoincr"`
        Repo    *Repository `xorm:"-"`
        RepoID  int64       `xorm:"INDEX NOT NULL"`
-       Owner   *User       `xorm:"-"`
        OwnerID int64       `xorm:"INDEX NOT NULL"`
        Path    string      `xorm:"TEXT"`
        Created time.Time   `xorm:"created"`
@@ -34,7 +34,6 @@ func init() {
 
 // BeforeInsert is invoked from XORM before inserting an object of this type.
 func (l *LFSLock) BeforeInsert() {
-       l.OwnerID = l.Owner.ID
        l.RepoID = l.Repo.ID
        l.Path = cleanPath(l.Path)
 }
@@ -42,10 +41,6 @@ func (l *LFSLock) BeforeInsert() {
 // AfterLoad is invoked from XORM after setting the values of all fields of this object.
 func (l *LFSLock) AfterLoad(session *xorm.Session) {
        var err error
-       l.Owner, err = getUserByID(session, l.OwnerID)
-       if err != nil {
-               log.Error("LFS lock AfterLoad failed OwnerId[%d] not found: %v", l.OwnerID, err)
-       }
        l.Repo, err = getRepositoryByID(session, l.RepoID)
        if err != nil {
                log.Error("LFS lock AfterLoad failed RepoId[%d] not found: %v", l.RepoID, err)
@@ -58,7 +53,7 @@ func cleanPath(p string) string {
 
 // CreateLFSLock creates a new lock.
 func CreateLFSLock(lock *LFSLock) (*LFSLock, error) {
-       err := CheckLFSAccessForRepo(lock.Owner, lock.Repo, AccessModeWrite)
+       err := CheckLFSAccessForRepo(lock.OwnerID, lock.Repo, AccessModeWrite)
        if err != nil {
                return nil, err
        }
@@ -123,13 +118,13 @@ func CountLFSLockByRepoID(repoID int64) (int64, error) {
 }
 
 // DeleteLFSLockByID deletes a lock by given ID.
-func DeleteLFSLockByID(id int64, u *User, force bool) (*LFSLock, error) {
+func DeleteLFSLockByID(id int64, u *user_model.User, force bool) (*LFSLock, error) {
        lock, err := GetLFSLockByID(id)
        if err != nil {
                return nil, err
        }
 
-       err = CheckLFSAccessForRepo(u, lock.Repo, AccessModeWrite)
+       err = CheckLFSAccessForRepo(u.ID, lock.Repo, AccessModeWrite)
        if err != nil {
                return nil, err
        }
@@ -143,10 +138,14 @@ func DeleteLFSLockByID(id int64, u *User, force bool) (*LFSLock, error) {
 }
 
 // CheckLFSAccessForRepo check needed access mode base on action
-func CheckLFSAccessForRepo(u *User, repo *Repository, mode AccessMode) error {
-       if u == nil {
+func CheckLFSAccessForRepo(ownerID int64, repo *Repository, mode AccessMode) error {
+       if ownerID == 0 {
                return ErrLFSUnauthorizedAction{repo.ID, "undefined", mode}
        }
+       u, err := user_model.GetUserByID(ownerID)
+       if err != nil {
+               return err
+       }
        perm, err := GetUserRepoPermission(repo, u)
        if err != nil {
                return err
index 5c99a2b2f7b047ed9b2d471de1a55299a33a8688..87e59f5b11714563351fe8ca6f9d66571a387794 100644 (file)
@@ -8,6 +8,7 @@ import (
        "testing"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -16,7 +17,7 @@ import (
 func TestFixturesAreConsistent(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
        unittest.CheckConsistencyFor(t,
-               &User{},
+               &user_model.User{},
                &Repository{},
                &Issue{},
                &PullRequest{},
index db785586474d7cd9a09306abbd5484f46603fdf7..ef8a1e83b89f303296d2a4a198acec0a71bacc39 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/timeutil"
@@ -62,10 +63,10 @@ type Notification struct {
 
        UpdatedBy int64 `xorm:"INDEX NOT NULL"`
 
-       Issue      *Issue      `xorm:"-"`
-       Repository *Repository `xorm:"-"`
-       Comment    *Comment    `xorm:"-"`
-       User       *User       `xorm:"-"`
+       Issue      *Issue           `xorm:"-"`
+       Repository *Repository      `xorm:"-"`
+       Comment    *Comment         `xorm:"-"`
+       User       *user_model.User `xorm:"-"`
 
        CreatedUnix timeutil.TimeStamp `xorm:"created INDEX NOT NULL"`
        UpdatedUnix timeutil.TimeStamp `xorm:"updated INDEX NOT NULL"`
@@ -139,7 +140,7 @@ func CountNotifications(opts *FindNotificationOptions) (int64, error) {
 }
 
 // CreateRepoTransferNotification creates  notification for the user a repository was transferred to
-func CreateRepoTransferNotification(doer, newOwner *User, repo *Repository) error {
+func CreateRepoTransferNotification(doer, newOwner *user_model.User, repo *Repository) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -258,9 +259,9 @@ func createOrUpdateIssueNotifications(e db.Engine, issueID, commentID, notificat
        // notify
        for userID := range toNotify {
                issue.Repo.Units = nil
-               user, err := getUserByID(e, userID)
+               user, err := user_model.GetUserByIDEngine(e, userID)
                if err != nil {
-                       if IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                continue
                        }
 
@@ -355,11 +356,11 @@ func getIssueNotification(e db.Engine, userID, issueID int64) (*Notification, er
 }
 
 // NotificationsForUser returns notifications for a given user and status
-func NotificationsForUser(user *User, statuses []NotificationStatus, page, perPage int) (NotificationList, error) {
+func NotificationsForUser(user *user_model.User, statuses []NotificationStatus, page, perPage int) (NotificationList, error) {
        return notificationsForUser(db.GetEngine(db.DefaultContext), user, statuses, page, perPage)
 }
 
-func notificationsForUser(e db.Engine, user *User, statuses []NotificationStatus, page, perPage int) (notifications []*Notification, err error) {
+func notificationsForUser(e db.Engine, user *user_model.User, statuses []NotificationStatus, page, perPage int) (notifications []*Notification, err error) {
        if len(statuses) == 0 {
                return
        }
@@ -378,7 +379,7 @@ func notificationsForUser(e db.Engine, user *User, statuses []NotificationStatus
 }
 
 // CountUnread count unread notifications for a user
-func CountUnread(user *User) int64 {
+func CountUnread(user *user_model.User) int64 {
        return countUnread(db.GetEngine(db.DefaultContext), user.ID)
 }
 
@@ -452,7 +453,7 @@ func (n *Notification) loadComment(e db.Engine) (err error) {
 
 func (n *Notification) loadUser(e db.Engine) (err error) {
        if n.User == nil {
-               n.User, err = getUserByID(e, n.UserID)
+               n.User, err = user_model.GetUserByIDEngine(e, n.UserID)
                if err != nil {
                        return fmt.Errorf("getUserByID [%d]: %v", n.UserID, err)
                }
@@ -733,11 +734,11 @@ func (nl NotificationList) LoadComments() ([]int, error) {
 }
 
 // GetNotificationCount returns the notification count for user
-func GetNotificationCount(user *User, status NotificationStatus) (int64, error) {
+func GetNotificationCount(user *user_model.User, status NotificationStatus) (int64, error) {
        return getNotificationCount(db.GetEngine(db.DefaultContext), user, status)
 }
 
-func getNotificationCount(e db.Engine, user *User, status NotificationStatus) (count int64, err error) {
+func getNotificationCount(e db.Engine, user *user_model.User, status NotificationStatus) (count int64, err error) {
        count, err = e.
                Where("user_id = ?", user.ID).
                And("status = ?", status).
@@ -788,7 +789,7 @@ func setRepoNotificationStatusReadIfUnread(e db.Engine, userID, repoID int64) er
 }
 
 // SetNotificationStatus change the notification status
-func SetNotificationStatus(notificationID int64, user *User, status NotificationStatus) (*Notification, error) {
+func SetNotificationStatus(notificationID int64, user *user_model.User, status NotificationStatus) (*Notification, error) {
        notification, err := getNotificationByID(db.GetEngine(db.DefaultContext), notificationID)
        if err != nil {
                return notification, err
@@ -826,7 +827,7 @@ func getNotificationByID(e db.Engine, notificationID int64) (*Notification, erro
 }
 
 // UpdateNotificationStatuses updates the statuses of all of a user's notifications that are of the currentStatus type to the desiredStatus
-func UpdateNotificationStatuses(user *User, currentStatus, desiredStatus NotificationStatus) error {
+func UpdateNotificationStatuses(user *user_model.User, currentStatus, desiredStatus NotificationStatus) error {
        n := &Notification{Status: desiredStatus, UpdatedBy: user.ID}
        _, err := db.GetEngine(db.DefaultContext).
                Where("user_id = ? AND status = ?", user.ID, currentStatus).
index 19fad25f99fbb6ddc65dd23db33249ce00ad4d45..3b05f34c551fd83c131d2edc8b41e211bc1a7d4f 100644 (file)
@@ -8,6 +8,7 @@ import (
        "testing"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -29,7 +30,7 @@ func TestCreateOrUpdateIssueNotifications(t *testing.T) {
 
 func TestNotificationsForUser(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        statuses := []NotificationStatus{NotificationStatusRead, NotificationStatusUnread}
        notfs, err := NotificationsForUser(user, statuses, 1, 10)
        assert.NoError(t, err)
@@ -63,7 +64,7 @@ func TestNotification_GetIssue(t *testing.T) {
 
 func TestGetNotificationCount(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        cnt, err := GetNotificationCount(user, NotificationStatusRead)
        assert.NoError(t, err)
        assert.EqualValues(t, 0, cnt)
@@ -75,7 +76,7 @@ func TestGetNotificationCount(t *testing.T) {
 
 func TestSetNotificationStatus(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        notf := unittest.AssertExistsAndLoadBean(t,
                &Notification{UserID: user.ID, Status: NotificationStatusRead}).(*Notification)
        _, err := SetNotificationStatus(notf.ID, user, NotificationStatusPinned)
@@ -91,7 +92,7 @@ func TestSetNotificationStatus(t *testing.T) {
 
 func TestUpdateNotificationStatuses(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        notfUnread := unittest.AssertExistsAndLoadBean(t,
                &Notification{UserID: user.ID, Status: NotificationStatusUnread}).(*Notification)
        notfRead := unittest.AssertExistsAndLoadBean(t,
index ea73d03d422e628128bcf3cf157b31c59c8d63dc..63e1b99af55f4cb89973f387028b711a67995965 100644 (file)
@@ -21,10 +21,10 @@ import (
 )
 
 // Organization represents an organization
-type Organization User
+type Organization user_model.User
 
 // OrgFromUser converts user to organization
-func OrgFromUser(user *User) *Organization {
+func OrgFromUser(user *user_model.User) *Organization {
        return (*Organization)(user)
 }
 
@@ -188,8 +188,8 @@ func (org *Organization) RemoveOrgRepo(repoID int64) error {
 }
 
 // AsUser returns the org as user object
-func (org *Organization) AsUser() *User {
-       return (*User)(org)
+func (org *Organization) AsUser() *user_model.User {
+       return (*user_model.User)(org)
 }
 
 // DisplayName returns full name if it's not empty,
@@ -204,34 +204,34 @@ func (org *Organization) CustomAvatarRelativePath() string {
 }
 
 // CreateOrganization creates record of a new organization.
-func CreateOrganization(org *Organization, owner *User) (err error) {
+func CreateOrganization(org *Organization, owner *user_model.User) (err error) {
        if !owner.CanCreateOrganization() {
                return ErrUserNotAllowedCreateOrg{}
        }
 
-       if err = IsUsableUsername(org.Name); err != nil {
+       if err = user_model.IsUsableUsername(org.Name); err != nil {
                return err
        }
 
-       isExist, err := IsUserExist(0, org.Name)
+       isExist, err := user_model.IsUserExist(0, org.Name)
        if err != nil {
                return err
        } else if isExist {
-               return ErrUserAlreadyExist{org.Name}
+               return user_model.ErrUserAlreadyExist{Name: org.Name}
        }
 
        org.LowerName = strings.ToLower(org.Name)
-       if org.Rands, err = GetUserSalt(); err != nil {
+       if org.Rands, err = user_model.GetUserSalt(); err != nil {
                return err
        }
-       if org.Salt, err = GetUserSalt(); err != nil {
+       if org.Salt, err = user_model.GetUserSalt(); err != nil {
                return err
        }
        org.UseCustomAvatar = true
        org.MaxRepoCreation = -1
        org.NumTeams = 1
        org.NumMembers = 1
-       org.Type = UserTypeOrganization
+       org.Type = user_model.UserTypeOrganization
 
        ctx, committer, err := db.TxContext()
        if err != nil {
@@ -246,7 +246,7 @@ func CreateOrganization(org *Organization, owner *User) (err error) {
        if err = db.Insert(ctx, org); err != nil {
                return fmt.Errorf("insert organization: %v", err)
        }
-       if err = generateRandomAvatar(db.GetEngine(ctx), org.AsUser()); err != nil {
+       if err = user_model.GenerateRandomAvatarCtx(ctx, org.AsUser()); err != nil {
                return fmt.Errorf("generate random avatar: %v", err)
        }
 
@@ -304,7 +304,7 @@ func GetOrgByName(name string) (*Organization, error) {
        }
        u := &Organization{
                LowerName: strings.ToLower(name),
-               Type:      UserTypeOrganization,
+               Type:      user_model.UserTypeOrganization,
        }
        has, err := db.GetEngine(db.DefaultContext).Get(u)
        if err != nil {
@@ -325,7 +325,7 @@ func CountOrganizations() int64 {
 
 // DeleteOrganization deletes models associated to an organization.
 func DeleteOrganization(ctx context.Context, org *Organization) error {
-       if org.Type != UserTypeOrganization {
+       if org.Type != user_model.UserTypeOrganization {
                return fmt.Errorf("%s is a user not an organization", org.Name)
        }
 
@@ -340,7 +340,7 @@ func DeleteOrganization(ctx context.Context, org *Organization) error {
                return fmt.Errorf("deleteBeans: %v", err)
        }
 
-       if _, err := e.ID(org.ID).Delete(new(User)); err != nil {
+       if _, err := e.ID(org.ID).Delete(new(user_model.User)); err != nil {
                return fmt.Errorf("Delete: %v", err)
        }
 
@@ -433,12 +433,12 @@ func (org *Organization) GetOrgUserMaxAuthorizeLevel(uid int64) (AccessMode, err
 }
 
 // GetUsersWhoCanCreateOrgRepo returns users which are able to create repo in organization
-func GetUsersWhoCanCreateOrgRepo(orgID int64) ([]*User, error) {
+func GetUsersWhoCanCreateOrgRepo(orgID int64) ([]*user_model.User, error) {
        return getUsersWhoCanCreateOrgRepo(db.GetEngine(db.DefaultContext), orgID)
 }
 
-func getUsersWhoCanCreateOrgRepo(e db.Engine, orgID int64) ([]*User, error) {
-       users := make([]*User, 0, 10)
+func getUsersWhoCanCreateOrgRepo(e db.Engine, orgID int64) ([]*user_model.User, error) {
+       users := make([]*user_model.User, 0, 10)
        return users, e.
                Join("INNER", "`team_user`", "`team_user`.uid=`user`.id").
                Join("INNER", "`team`", "`team`.id=`team_user`.team_id").
@@ -450,8 +450,8 @@ func getUsersWhoCanCreateOrgRepo(e db.Engine, orgID int64) ([]*User, error) {
 type MinimalOrg = Organization
 
 // GetUserOrgsList returns one user's all orgs list
-func GetUserOrgsList(user *User) ([]*MinimalOrg, error) {
-       schema, err := db.TableInfo(new(User))
+func GetUserOrgsList(user *user_model.User) ([]*MinimalOrg, error) {
+       schema, err := db.TableInfo(new(user_model.User))
        if err != nil {
                return nil, err
        }
@@ -507,6 +507,12 @@ func GetUserOrgsList(user *User) ([]*MinimalOrg, error) {
        return orgs, nil
 }
 
+// SearchOrganizationsOptions options to filter organizations
+type SearchOrganizationsOptions struct {
+       db.ListOptions
+       All bool
+}
+
 // FindOrgOptions finds orgs options
 type FindOrgOptions struct {
        db.ListOptions
@@ -549,7 +555,7 @@ func FindOrgs(opts FindOrgOptions) ([]*Organization, error) {
 func CountOrgs(opts FindOrgOptions) (int64, error) {
        return db.GetEngine(db.DefaultContext).
                Where(opts.toConds()).
-               Count(new(User))
+               Count(new(user_model.User))
 }
 
 func getOwnedOrgsByUserID(sess db.Engine, userID int64) ([]*Organization, error) {
@@ -564,11 +570,11 @@ func getOwnedOrgsByUserID(sess db.Engine, userID int64) ([]*Organization, error)
 }
 
 // HasOrgOrUserVisible tells if the given user can see the given org or user
-func HasOrgOrUserVisible(org, user *User) bool {
+func HasOrgOrUserVisible(org, user *user_model.User) bool {
        return hasOrgOrUserVisible(db.GetEngine(db.DefaultContext), org, user)
 }
 
-func hasOrgOrUserVisible(e db.Engine, orgOrUser, user *User) bool {
+func hasOrgOrUserVisible(e db.Engine, orgOrUser, user *user_model.User) bool {
        // Not SignedUser
        if user == nil {
                return orgOrUser.Visibility == structs.VisibleTypePublic
@@ -585,7 +591,7 @@ func hasOrgOrUserVisible(e db.Engine, orgOrUser, user *User) bool {
 }
 
 // HasOrgsVisible tells if the given user can see at least one of the orgs provided
-func HasOrgsVisible(orgs []*Organization, user *User) bool {
+func HasOrgsVisible(orgs []*Organization, user *user_model.User) bool {
        if len(orgs) == 0 {
                return false
        }
@@ -718,7 +724,11 @@ func GetOrgByIDCtx(ctx context.Context, id int64) (*Organization, error) {
        if err != nil {
                return nil, err
        } else if !has {
-               return nil, ErrUserNotExist{id, "", 0}
+               return nil, user_model.ErrUserNotExist{
+                       UID:   id,
+                       Name:  "",
+                       KeyID: 0,
+               }
        }
        return u, nil
 }
@@ -896,17 +906,17 @@ type AccessibleReposEnvironment interface {
        Repos(page, pageSize int) ([]*Repository, error)
        MirrorRepos() ([]*Repository, error)
        AddKeyword(keyword string)
-       SetSort(SearchOrderBy)
+       SetSort(db.SearchOrderBy)
 }
 
 type accessibleReposEnv struct {
        org     *Organization
-       user    *User
+       user    *user_model.User
        team    *Team
        teamIDs []int64
        e       db.Engine
        keyword string
-       orderBy SearchOrderBy
+       orderBy db.SearchOrderBy
 }
 
 // AccessibleReposEnv builds an AccessibleReposEnvironment for the repositories in `org`
@@ -916,10 +926,10 @@ func (org *Organization) AccessibleReposEnv(userID int64) (AccessibleReposEnviro
 }
 
 func (org *Organization) accessibleReposEnv(e db.Engine, userID int64) (AccessibleReposEnvironment, error) {
-       var user *User
+       var user *user_model.User
 
        if userID > 0 {
-               u, err := getUserByID(e, userID)
+               u, err := user_model.GetUserByIDEngine(e, userID)
                if err != nil {
                        return nil, err
                }
@@ -935,7 +945,7 @@ func (org *Organization) accessibleReposEnv(e db.Engine, userID int64) (Accessib
                user:    user,
                teamIDs: teamIDs,
                e:       e,
-               orderBy: SearchOrderByRecentUpdated,
+               orderBy: db.SearchOrderByRecentUpdated,
        }, nil
 }
 
@@ -946,7 +956,7 @@ func (org *Organization) AccessibleTeamReposEnv(team *Team) AccessibleReposEnvir
                org:     org,
                team:    team,
                e:       db.GetEngine(db.DefaultContext),
-               orderBy: SearchOrderByRecentUpdated,
+               orderBy: db.SearchOrderByRecentUpdated,
        }
 }
 
@@ -1049,6 +1059,6 @@ func (env *accessibleReposEnv) AddKeyword(keyword string) {
        env.keyword = keyword
 }
 
-func (env *accessibleReposEnv) SetSort(orderBy SearchOrderBy) {
+func (env *accessibleReposEnv) SetSort(orderBy db.SearchOrderBy) {
        env.orderBy = orderBy
 }
index 1bdffe2cb15c7b5e2df08f5ccd9de64ec6bd6ece..510a0dcfaae252707984deb399266adc3d42aee0 100644 (file)
@@ -14,6 +14,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
 
@@ -30,8 +31,8 @@ type Team struct {
        Name                    string
        Description             string
        Authorize               AccessMode
-       Repos                   []*Repository `xorm:"-"`
-       Members                 []*User       `xorm:"-"`
+       Repos                   []*Repository      `xorm:"-"`
+       Members                 []*user_model.User `xorm:"-"`
        NumRepos                int
        NumMembers              int
        Units                   []*TeamUnit `xorm:"-"`
@@ -456,7 +457,7 @@ func (t *Team) unitEnabled(e db.Engine, tp unit.Type) bool {
 func IsUsableTeamName(name string) error {
        switch name {
        case "new":
-               return ErrNameReserved{name}
+               return db.ErrNameReserved{Name: name}
        default:
                return nil
        }
@@ -473,7 +474,7 @@ func NewTeam(t *Team) (err error) {
                return err
        }
 
-       has, err := db.GetEngine(db.DefaultContext).ID(t.OrgID).Get(new(User))
+       has, err := db.GetEngine(db.DefaultContext).ID(t.OrgID).Get(new(user_model.User))
        if err != nil {
                return err
        }
@@ -760,14 +761,14 @@ func getTeamUsersByTeamID(e db.Engine, teamID int64) ([]*TeamUser, error) {
                Find(&teamUsers)
 }
 
-func getTeamMembers(e db.Engine, teamID int64) (_ []*User, err error) {
+func getTeamMembers(e db.Engine, teamID int64) (_ []*user_model.User, err error) {
        teamUsers, err := getTeamUsersByTeamID(e, teamID)
        if err != nil {
                return nil, fmt.Errorf("get team-users: %v", err)
        }
-       members := make([]*User, len(teamUsers))
+       members := make([]*user_model.User, len(teamUsers))
        for i, teamUser := range teamUsers {
-               member, err := getUserByID(e, teamUser.UID)
+               member, err := user_model.GetUserByIDEngine(e, teamUser.UID)
                if err != nil {
                        return nil, fmt.Errorf("get user '%d': %v", teamUser.UID, err)
                }
@@ -780,7 +781,7 @@ func getTeamMembers(e db.Engine, teamID int64) (_ []*User, err error) {
 }
 
 // GetTeamMembers returns all members in given team of organization.
-func GetTeamMembers(teamID int64) ([]*User, error) {
+func GetTeamMembers(teamID int64) ([]*user_model.User, error) {
        return getTeamMembers(db.GetEngine(db.DefaultContext), teamID)
 }
 
index b912dd83f2644bcf8917830f674be113fe25c67e..450cf7dd5515b1338cf37ae14e675c263151abb5 100644 (file)
@@ -8,7 +8,9 @@ import (
        "strings"
        "testing"
 
+       "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -74,7 +76,7 @@ func TestTeam_AddMember(t *testing.T) {
                team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team)
                assert.NoError(t, team.AddMember(userID))
                unittest.AssertExistsAndLoadBean(t, &TeamUser{UID: userID, TeamID: teamID})
-               unittest.CheckConsistencyFor(t, &Team{ID: teamID}, &User{ID: team.OrgID})
+               unittest.CheckConsistencyFor(t, &Team{ID: teamID}, &user_model.User{ID: team.OrgID})
        }
        test(1, 2)
        test(1, 4)
@@ -151,7 +153,7 @@ func TestTeam_RemoveRepository(t *testing.T) {
 
 func TestIsUsableTeamName(t *testing.T) {
        assert.NoError(t, IsUsableTeamName("usable"))
-       assert.True(t, IsErrNameReserved(IsUsableTeamName("new")))
+       assert.True(t, db.IsErrNameReserved(IsUsableTeamName("new")))
 }
 
 func TestNewTeam(t *testing.T) {
@@ -161,7 +163,7 @@ func TestNewTeam(t *testing.T) {
        team := &Team{Name: teamName, OrgID: 3}
        assert.NoError(t, NewTeam(team))
        unittest.AssertExistsAndLoadBean(t, &Team{Name: teamName})
-       unittest.CheckConsistencyFor(t, &Team{}, &User{ID: team.OrgID})
+       unittest.CheckConsistencyFor(t, &Team{}, &user_model.User{ID: team.OrgID})
 }
 
 func TestGetTeam(t *testing.T) {
@@ -243,7 +245,7 @@ func TestDeleteTeam(t *testing.T) {
        unittest.AssertNotExistsBean(t, &TeamUser{TeamID: team.ID})
 
        // check that team members don't have "leftover" access to repos
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
        accessMode, err := AccessLevel(user, repo)
        assert.NoError(t, err)
@@ -321,7 +323,7 @@ func TestAddTeamMember(t *testing.T) {
                team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team)
                assert.NoError(t, AddTeamMember(team, userID))
                unittest.AssertExistsAndLoadBean(t, &TeamUser{UID: userID, TeamID: teamID})
-               unittest.CheckConsistencyFor(t, &Team{ID: teamID}, &User{ID: team.OrgID})
+               unittest.CheckConsistencyFor(t, &Team{ID: teamID}, &user_model.User{ID: team.OrgID})
        }
        test(1, 2)
        test(1, 4)
index 805c63300b374a28a70cb2b59473d697bca2d5d8..c24064c5b8b14d5fa6bf345400e021aba18c1a03 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/structs"
 
@@ -130,7 +131,7 @@ func TestUser_AddMember(t *testing.T) {
        org = unittest.AssertExistsAndLoadBean(t, &Organization{ID: 3}).(*Organization)
        assert.Equal(t, prevNumMembers, org.NumMembers)
 
-       unittest.CheckConsistencyFor(t, &User{})
+       unittest.CheckConsistencyFor(t, &user_model.User{})
 }
 
 func TestUser_RemoveMember(t *testing.T) {
@@ -153,7 +154,7 @@ func TestUser_RemoveMember(t *testing.T) {
        org = unittest.AssertExistsAndLoadBean(t, &Organization{ID: 3}).(*Organization)
        assert.Equal(t, prevNumMembers, org.NumMembers)
 
-       unittest.CheckConsistencyFor(t, &User{}, &Team{})
+       unittest.CheckConsistencyFor(t, &user_model.User{}, &Team{})
 }
 
 func TestUser_RemoveOrgRepo(t *testing.T) {
@@ -174,7 +175,7 @@ func TestUser_RemoveOrgRepo(t *testing.T) {
        assert.NoError(t, org.RemoveOrgRepo(unittest.NonexistentID))
 
        unittest.CheckConsistencyFor(t,
-               &User{ID: org.ID},
+               &user_model.User{ID: org.ID},
                &Team{OrgID: org.ID},
                &Repository{ID: repo.ID})
 }
@@ -183,37 +184,37 @@ func TestCreateOrganization(t *testing.T) {
        // successful creation of org
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        const newOrgName = "neworg"
        org := &Organization{
                Name: newOrgName,
        }
 
-       unittest.AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
+       unittest.AssertNotExistsBean(t, &user_model.User{Name: newOrgName, Type: user_model.UserTypeOrganization})
        assert.NoError(t, CreateOrganization(org, owner))
        org = unittest.AssertExistsAndLoadBean(t,
-               &Organization{Name: newOrgName, Type: UserTypeOrganization}).(*Organization)
+               &Organization{Name: newOrgName, Type: user_model.UserTypeOrganization}).(*Organization)
        ownerTeam := unittest.AssertExistsAndLoadBean(t,
                &Team{Name: ownerTeamName, OrgID: org.ID}).(*Team)
        unittest.AssertExistsAndLoadBean(t, &TeamUser{UID: owner.ID, TeamID: ownerTeam.ID})
-       unittest.CheckConsistencyFor(t, &User{}, &Team{})
+       unittest.CheckConsistencyFor(t, &user_model.User{}, &Team{})
 }
 
 func TestCreateOrganization2(t *testing.T) {
        // unauthorized creation of org
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
        const newOrgName = "neworg"
        org := &Organization{
                Name: newOrgName,
        }
 
-       unittest.AssertNotExistsBean(t, &Organization{Name: newOrgName, Type: UserTypeOrganization})
+       unittest.AssertNotExistsBean(t, &Organization{Name: newOrgName, Type: user_model.UserTypeOrganization})
        err := CreateOrganization(org, owner)
        assert.Error(t, err)
        assert.True(t, IsErrUserNotAllowedCreateOrg(err))
-       unittest.AssertNotExistsBean(t, &Organization{Name: newOrgName, Type: UserTypeOrganization})
+       unittest.AssertNotExistsBean(t, &Organization{Name: newOrgName, Type: user_model.UserTypeOrganization})
        unittest.CheckConsistencyFor(t, &Organization{}, &Team{})
 }
 
@@ -221,23 +222,23 @@ func TestCreateOrganization3(t *testing.T) {
        // create org with same name as existent org
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       org := &Organization{Name: "user3"}                        // should already exist
-       unittest.AssertExistsAndLoadBean(t, &User{Name: org.Name}) // sanity check
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       org := &Organization{Name: "user3"}                                   // should already exist
+       unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: org.Name}) // sanity check
        err := CreateOrganization(org, owner)
        assert.Error(t, err)
-       assert.True(t, IsErrUserAlreadyExist(err))
-       unittest.CheckConsistencyFor(t, &User{}, &Team{})
+       assert.True(t, user_model.IsErrUserAlreadyExist(err))
+       unittest.CheckConsistencyFor(t, &user_model.User{}, &Team{})
 }
 
 func TestCreateOrganization4(t *testing.T) {
        // create org with unusable name
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        err := CreateOrganization(&Organization{Name: "assets"}, owner)
        assert.Error(t, err)
-       assert.True(t, IsErrNameReserved(err))
+       assert.True(t, db.IsErrNameReserved(err))
        unittest.CheckConsistencyFor(t, &Organization{}, &Team{})
 }
 
@@ -258,7 +259,7 @@ func TestGetOrgByName(t *testing.T) {
 
 func TestCountOrganizations(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       expected, err := db.GetEngine(db.DefaultContext).Where("type=?", UserTypeOrganization).Count(&User{})
+       expected, err := db.GetEngine(db.DefaultContext).Where("type=?", user_model.UserTypeOrganization).Count(&user_model.User{})
        assert.NoError(t, err)
        assert.Equal(t, expected, CountOrganizations())
 }
@@ -444,7 +445,7 @@ func TestChangeOrgUserStatus(t *testing.T) {
 func TestAddOrgUser(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
        testSuccess := func(orgID, userID int64, isPublic bool) {
-               org := unittest.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
+               org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: orgID}).(*user_model.User)
                expectedNumMembers := org.NumMembers
                if !unittest.BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
                        expectedNumMembers++
@@ -453,7 +454,7 @@ func TestAddOrgUser(t *testing.T) {
                ou := &OrgUser{OrgID: orgID, UID: userID}
                unittest.AssertExistsAndLoadBean(t, ou)
                assert.Equal(t, isPublic, ou.IsPublic)
-               org = unittest.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
+               org = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: orgID}).(*user_model.User)
                assert.EqualValues(t, expectedNumMembers, org.NumMembers)
        }
 
@@ -465,20 +466,20 @@ func TestAddOrgUser(t *testing.T) {
        setting.Service.DefaultOrgMemberVisible = true
        testSuccess(6, 3, true)
 
-       unittest.CheckConsistencyFor(t, &User{}, &Team{})
+       unittest.CheckConsistencyFor(t, &user_model.User{}, &Team{})
 }
 
 func TestRemoveOrgUser(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
        testSuccess := func(orgID, userID int64) {
-               org := unittest.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
+               org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: orgID}).(*user_model.User)
                expectedNumMembers := org.NumMembers
                if unittest.BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
                        expectedNumMembers--
                }
                assert.NoError(t, RemoveOrgUser(orgID, userID))
                unittest.AssertNotExistsBean(t, &OrgUser{OrgID: orgID, UID: userID})
-               org = unittest.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
+               org = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: orgID}).(*user_model.User)
                assert.EqualValues(t, expectedNumMembers, org.NumMembers)
        }
        testSuccess(3, 4)
@@ -488,7 +489,7 @@ func TestRemoveOrgUser(t *testing.T) {
        assert.Error(t, err)
        assert.True(t, IsErrLastOrgOwner(err))
        unittest.AssertExistsAndLoadBean(t, &OrgUser{OrgID: 7, UID: 5})
-       unittest.CheckConsistencyFor(t, &User{}, &Team{})
+       unittest.CheckConsistencyFor(t, &user_model.User{}, &Team{})
 }
 
 func TestUser_GetUserTeamIDs(t *testing.T) {
@@ -572,8 +573,8 @@ func TestAccessibleReposEnv_MirrorRepos(t *testing.T) {
 
 func TestHasOrgVisibleTypePublic(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
 
        const newOrgName = "test-org-public"
        org := &Organization{
@@ -581,10 +582,10 @@ func TestHasOrgVisibleTypePublic(t *testing.T) {
                Visibility: structs.VisibleTypePublic,
        }
 
-       unittest.AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
+       unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization})
        assert.NoError(t, CreateOrganization(org, owner))
        org = unittest.AssertExistsAndLoadBean(t,
-               &Organization{Name: org.Name, Type: UserTypeOrganization}).(*Organization)
+               &Organization{Name: org.Name, Type: user_model.UserTypeOrganization}).(*Organization)
        test1 := HasOrgOrUserVisible(org.AsUser(), owner)
        test2 := HasOrgOrUserVisible(org.AsUser(), user3)
        test3 := HasOrgOrUserVisible(org.AsUser(), nil)
@@ -595,8 +596,8 @@ func TestHasOrgVisibleTypePublic(t *testing.T) {
 
 func TestHasOrgVisibleTypeLimited(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
 
        const newOrgName = "test-org-limited"
        org := &Organization{
@@ -604,10 +605,10 @@ func TestHasOrgVisibleTypeLimited(t *testing.T) {
                Visibility: structs.VisibleTypeLimited,
        }
 
-       unittest.AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
+       unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization})
        assert.NoError(t, CreateOrganization(org, owner))
        org = unittest.AssertExistsAndLoadBean(t,
-               &Organization{Name: org.Name, Type: UserTypeOrganization}).(*Organization)
+               &Organization{Name: org.Name, Type: user_model.UserTypeOrganization}).(*Organization)
        test1 := HasOrgOrUserVisible(org.AsUser(), owner)
        test2 := HasOrgOrUserVisible(org.AsUser(), user3)
        test3 := HasOrgOrUserVisible(org.AsUser(), nil)
@@ -618,8 +619,8 @@ func TestHasOrgVisibleTypeLimited(t *testing.T) {
 
 func TestHasOrgVisibleTypePrivate(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
 
        const newOrgName = "test-org-private"
        org := &Organization{
@@ -627,10 +628,10 @@ func TestHasOrgVisibleTypePrivate(t *testing.T) {
                Visibility: structs.VisibleTypePrivate,
        }
 
-       unittest.AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
+       unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization})
        assert.NoError(t, CreateOrganization(org, owner))
        org = unittest.AssertExistsAndLoadBean(t,
-               &Organization{Name: org.Name, Type: UserTypeOrganization}).(*Organization)
+               &Organization{Name: org.Name, Type: user_model.UserTypeOrganization}).(*Organization)
        test1 := HasOrgOrUserVisible(org.AsUser(), owner)
        test2 := HasOrgOrUserVisible(org.AsUser(), user3)
        test3 := HasOrgOrUserVisible(org.AsUser(), nil)
index 6f314ca931f453da3945e0522c2cb1b9b4166267..fb08efa994e84908648e9a54852158b2e50ce444 100644 (file)
@@ -9,6 +9,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
 )
 
 // ProjectIssue saves relation from issue to a project
@@ -130,7 +131,7 @@ func (p *Project) NumOpenIssues() int {
 }
 
 // ChangeProjectAssign changes the project associated with an issue
-func ChangeProjectAssign(issue *Issue, doer *User, newProjectID int64) error {
+func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -144,7 +145,7 @@ func ChangeProjectAssign(issue *Issue, doer *User, newProjectID int64) error {
        return committer.Commit()
 }
 
-func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *User, newProjectID int64) error {
+func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error {
        e := db.GetEngine(ctx)
        oldProjectID := issue.projectID(e)
 
index 1e1dd13c571ecef8a3a7e7fb6de8aae3143876b2..85ca0b3fc8d5152db9b1ed8d7f293426ace26dcc 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/timeutil"
@@ -78,7 +79,7 @@ type PullRequest struct {
        HasMerged      bool               `xorm:"INDEX"`
        MergedCommitID string             `xorm:"VARCHAR(40)"`
        MergerID       int64              `xorm:"INDEX"`
-       Merger         *User              `xorm:"-"`
+       Merger         *user_model.User   `xorm:"-"`
        MergedUnix     timeutil.TimeStamp `xorm:"updated INDEX"`
 
        isHeadRepoLoaded bool `xorm:"-"`
@@ -109,10 +110,10 @@ func (pr *PullRequest) MustHeadUserName() string {
 // Note: don't try to get Issue because will end up recursive querying.
 func (pr *PullRequest) loadAttributes(e db.Engine) (err error) {
        if pr.HasMerged && pr.Merger == nil {
-               pr.Merger, err = getUserByID(e, pr.MergerID)
-               if IsErrUserNotExist(err) {
+               pr.Merger, err = user_model.GetUserByIDEngine(e, pr.MergerID)
+               if user_model.IsErrUserNotExist(err) {
                        pr.MergerID = -1
-                       pr.Merger = NewGhostUser()
+                       pr.Merger = user_model.NewGhostUser()
                } else if err != nil {
                        return fmt.Errorf("getUserByID [%d]: %v", pr.MergerID, err)
                }
@@ -310,7 +311,7 @@ func (pr *PullRequest) getReviewedByLines(writer io.Writer) error {
                        break
                }
 
-               if err := review.loadReviewer(sess); err != nil && !IsErrUserNotExist(err) {
+               if err := review.loadReviewer(sess); err != nil && !user_model.IsErrUserNotExist(err) {
                        log.Error("Unable to LoadReviewer[%d] for PR ID %d : %v", review.ReviewerID, pr.ID, err)
                        return err
                } else if review.Reviewer == nil {
index 57ef210213950f5dbd01ec444017c878ddc09a82..7c5b83ae5f27501346acecf0748b596e513d8bde 100644 (file)
@@ -8,6 +8,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
@@ -147,7 +148,7 @@ func (prs PullRequestList) LoadAttributes() error {
        return prs.loadAttributes(db.GetEngine(db.DefaultContext))
 }
 
-func (prs PullRequestList) invalidateCodeComments(e db.Engine, doer *User, repo *git.Repository, branch string) error {
+func (prs PullRequestList) invalidateCodeComments(e db.Engine, doer *user_model.User, repo *git.Repository, branch string) error {
        if len(prs) == 0 {
                return nil
        }
@@ -168,6 +169,6 @@ func (prs PullRequestList) invalidateCodeComments(e db.Engine, doer *User, repo
 }
 
 // InvalidateCodeComments will lookup the prs for code comments which got invalidated by change
-func (prs PullRequestList) InvalidateCodeComments(doer *User, repo *git.Repository, branch string) error {
+func (prs PullRequestList) InvalidateCodeComments(doer *user_model.User, repo *git.Repository, branch string) error {
        return prs.invalidateCodeComments(db.GetEngine(db.DefaultContext), doer, repo, branch)
 }
index 028a3e5c3b6597622573ffbc1c910acd063d81d2..269e8e06d2025d1c10a8c0628237f9189e4f8586 100644 (file)
@@ -7,13 +7,14 @@ package models
 import (
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/login"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
 )
 
 // SignMerge determines if we should sign a PR merge commit to the base repository
-func (pr *PullRequest) SignMerge(u *User, tmpBasePath, baseCommit, headCommit string) (bool, string, *git.Signature, error) {
+func (pr *PullRequest) SignMerge(u *user_model.User, tmpBasePath, baseCommit, headCommit string) (bool, string, *git.Signature, error) {
        if err := pr.LoadBaseRepo(); err != nil {
                log.Error("Unable to get Base Repo for pull request")
                return false, "", nil, err
index c967cca313916013c4b25b6100fb9654fd5f7677..2281dbffdafb7df3510b910bca7fb579db68436a 100644 (file)
@@ -10,6 +10,7 @@ import (
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -264,7 +265,7 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
                },
        }
        baseRepo := &Repository{Name: "testRepo", ID: 1}
-       baseRepo.Owner = &User{Name: "testOwner"}
+       baseRepo.Owner = &user_model.User{Name: "testOwner"}
        baseRepo.Units = []*RepoUnit{&externalTracker}
 
        pr := unittest.AssertExistsAndLoadBean(t, &PullRequest{ID: 2, BaseRepo: baseRepo}).(*PullRequest)
index 69d2ceda5e183dcfa37a4a600ac3c89c2bd5027b..f60024c7109d7d02221e677796494ca71cd406b7 100644 (file)
@@ -15,6 +15,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        repo_model "code.gitea.io/gitea/models/repo"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/timeutil"
        "code.gitea.io/gitea/modules/util"
@@ -24,12 +25,12 @@ import (
 
 // Release represents a release of repository.
 type Release struct {
-       ID               int64       `xorm:"pk autoincr"`
-       RepoID           int64       `xorm:"INDEX UNIQUE(n)"`
-       Repo             *Repository `xorm:"-"`
-       PublisherID      int64       `xorm:"INDEX"`
-       Publisher        *User       `xorm:"-"`
-       TagName          string      `xorm:"INDEX UNIQUE(n)"`
+       ID               int64            `xorm:"pk autoincr"`
+       RepoID           int64            `xorm:"INDEX UNIQUE(n)"`
+       Repo             *Repository      `xorm:"-"`
+       PublisherID      int64            `xorm:"INDEX"`
+       Publisher        *user_model.User `xorm:"-"`
+       TagName          string           `xorm:"INDEX UNIQUE(n)"`
        OriginalAuthor   string
        OriginalAuthorID int64 `xorm:"index"`
        LowerTagName     string
@@ -60,10 +61,10 @@ func (r *Release) loadAttributes(e db.Engine) error {
                }
        }
        if r.Publisher == nil {
-               r.Publisher, err = getUserByID(e, r.PublisherID)
+               r.Publisher, err = user_model.GetUserByIDEngine(e, r.PublisherID)
                if err != nil {
-                       if IsErrUserNotExist(err) {
-                               r.Publisher = NewGhostUser()
+                       if user_model.IsErrUserNotExist(err) {
+                               r.Publisher = user_model.NewGhostUser()
                        } else {
                                return err
                        }
index 860c5c4813d2fa66452160e7b3322e4d29db5321..bf5c160297dbcd6644999ea14997c16b029013ce 100644 (file)
@@ -27,6 +27,7 @@ import (
        "code.gitea.io/gitea/models/db"
        repo_model "code.gitea.io/gitea/models/repo"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/models/webhook"
        "code.gitea.io/gitea/modules/lfs"
        "code.gitea.io/gitea/modules/log"
@@ -44,9 +45,6 @@ import (
 var (
        // ErrMirrorNotExist mirror does not exist error
        ErrMirrorNotExist = errors.New("Mirror does not exist")
-
-       // ErrNameEmpty name is empty error
-       ErrNameEmpty = errors.New("Name is empty")
 )
 
 var (
@@ -195,7 +193,7 @@ type Repository struct {
        ID                  int64 `xorm:"pk autoincr"`
        OwnerID             int64 `xorm:"UNIQUE(s) index"`
        OwnerName           string
-       Owner               *User              `xorm:"-"`
+       Owner               *user_model.User   `xorm:"-"`
        LowerName           string             `xorm:"UNIQUE(s) INDEX NOT NULL"`
        Name                string             `xorm:"INDEX NOT NULL"`
        Description         string             `xorm:"TEXT"`
@@ -308,11 +306,11 @@ func (repo *Repository) AfterLoad() {
        repo.NumOpenProjects = repo.NumProjects - repo.NumClosedProjects
 }
 
-// MustOwner always returns a valid *User object to avoid
+// MustOwner always returns a valid *user_model.User object to avoid
 // conceptually impossible error handling.
 // It creates a fake object that contains error details
 // when error occurs.
-func (repo *Repository) MustOwner() *User {
+func (repo *Repository) MustOwner() *user_model.User {
        return repo.mustOwner(db.GetEngine(db.DefaultContext))
 }
 
@@ -364,11 +362,11 @@ func (repo *Repository) getUnits(e db.Engine) (err error) {
 }
 
 // CheckUnitUser check whether user could visit the unit of this repository
-func (repo *Repository) CheckUnitUser(user *User, unitType unit.Type) bool {
+func (repo *Repository) CheckUnitUser(user *user_model.User, unitType unit.Type) bool {
        return repo.checkUnitUser(db.GetEngine(db.DefaultContext), user, unitType)
 }
 
-func (repo *Repository) checkUnitUser(e db.Engine, user *User, unitType unit.Type) bool {
+func (repo *Repository) checkUnitUser(e db.Engine, user *user_model.User, unitType unit.Type) bool {
        if user.IsAdmin {
                return true
        }
@@ -465,7 +463,7 @@ func (repo *Repository) getOwner(e db.Engine) (err error) {
                return nil
        }
 
-       repo.Owner, err = getUserByID(e, repo.OwnerID)
+       repo.Owner, err = user_model.GetUserByIDEngine(e, repo.OwnerID)
        return err
 }
 
@@ -474,9 +472,9 @@ func (repo *Repository) GetOwner() error {
        return repo.getOwner(db.GetEngine(db.DefaultContext))
 }
 
-func (repo *Repository) mustOwner(e db.Engine) *User {
+func (repo *Repository) mustOwner(e db.Engine) *user_model.User {
        if err := repo.getOwner(e); err != nil {
-               return &User{
+               return &user_model.User{
                        Name:     "error",
                        FullName: err.Error(),
                }
@@ -537,7 +535,7 @@ func (repo *Repository) ComposeDocumentMetas() map[string]string {
        return repo.DocumentRenderingMetas
 }
 
-func (repo *Repository) getAssignees(e db.Engine) (_ []*User, err error) {
+func (repo *Repository) getAssignees(e db.Engine) (_ []*user_model.User, err error) {
        if err = repo.getOwner(e); err != nil {
                return nil, err
        }
@@ -551,7 +549,7 @@ func (repo *Repository) getAssignees(e db.Engine) (_ []*User, err error) {
 
        // Leave a seat for owner itself to append later, but if owner is an organization
        // and just waste 1 unit is cheaper than re-allocate memory once.
-       users := make([]*User, 0, len(accesses)+1)
+       users := make([]*user_model.User, 0, len(accesses)+1)
        if len(accesses) > 0 {
                userIDs := make([]int64, len(accesses))
                for i := 0; i < len(accesses); i++ {
@@ -571,17 +569,17 @@ func (repo *Repository) getAssignees(e db.Engine) (_ []*User, err error) {
 
 // GetAssignees returns all users that have write access and can be assigned to issues
 // of the repository,
-func (repo *Repository) GetAssignees() (_ []*User, err error) {
+func (repo *Repository) GetAssignees() (_ []*user_model.User, err error) {
        return repo.getAssignees(db.GetEngine(db.DefaultContext))
 }
 
-func (repo *Repository) getReviewers(e db.Engine, doerID, posterID int64) ([]*User, error) {
+func (repo *Repository) getReviewers(e db.Engine, doerID, posterID int64) ([]*user_model.User, error) {
        // Get the owner of the repository - this often already pre-cached and if so saves complexity for the following queries
        if err := repo.getOwner(e); err != nil {
                return nil, err
        }
 
-       var users []*User
+       var users []*user_model.User
 
        if repo.IsPrivate || repo.Owner.Visibility == api.VisibleTypePrivate {
                // This a private repository:
@@ -623,7 +621,7 @@ func (repo *Repository) getReviewers(e db.Engine, doerID, posterID int64) ([]*Us
 // * for public repositories this returns all users that have read access or higher to the repository,
 // all repo watchers and all organization members.
 // TODO: may be we should have a busy choice for users to block review request to them.
-func (repo *Repository) GetReviewers(doerID, posterID int64) ([]*User, error) {
+func (repo *Repository) GetReviewers(doerID, posterID int64) ([]*user_model.User, error) {
        return repo.getReviewers(db.GetEngine(db.DefaultContext), doerID, posterID)
 }
 
@@ -761,7 +759,7 @@ func (repo *Repository) UpdateSize(ctx context.Context) error {
 }
 
 // CanUserForkRepo returns true if specified user can fork repository.
-func CanUserForkRepo(user *User, repo *Repository) (bool, error) {
+func CanUserForkRepo(user *user_model.User, repo *Repository) (bool, error) {
        if user == nil {
                return false, nil
        }
@@ -781,7 +779,7 @@ func CanUserForkRepo(user *User, repo *Repository) (bool, error) {
 }
 
 // CanUserDelete returns true if user could delete the repository
-func (repo *Repository) CanUserDelete(user *User) (bool, error) {
+func (repo *Repository) CanUserDelete(user *user_model.User) (bool, error) {
        if user.IsAdmin || user.ID == repo.OwnerID {
                return true, nil
        }
@@ -818,12 +816,12 @@ func (repo *Repository) CanEnableEditor() bool {
 }
 
 // GetReaders returns all users that have explicit read access or higher to the repository.
-func (repo *Repository) GetReaders() (_ []*User, err error) {
+func (repo *Repository) GetReaders() (_ []*user_model.User, err error) {
        return repo.getUsersWithAccessMode(db.GetEngine(db.DefaultContext), AccessModeRead)
 }
 
 // GetWriters returns all users that have write access to the repository.
-func (repo *Repository) GetWriters() (_ []*User, err error) {
+func (repo *Repository) GetWriters() (_ []*user_model.User, err error) {
        return repo.getUsersWithAccessMode(db.GetEngine(db.DefaultContext), AccessModeWrite)
 }
 
@@ -836,7 +834,7 @@ func (repo *Repository) IsReader(userID int64) (bool, error) {
 }
 
 // getUsersWithAccessMode returns users that have at least given access mode to the repository.
-func (repo *Repository) getUsersWithAccessMode(e db.Engine, mode AccessMode) (_ []*User, err error) {
+func (repo *Repository) getUsersWithAccessMode(e db.Engine, mode AccessMode) (_ []*user_model.User, err error) {
        if err = repo.getOwner(e); err != nil {
                return nil, err
        }
@@ -848,7 +846,7 @@ func (repo *Repository) getUsersWithAccessMode(e db.Engine, mode AccessMode) (_
 
        // Leave a seat for owner itself to append later, but if owner is an organization
        // and just waste 1 unit is cheaper than re-allocate memory once.
-       users := make([]*User, 0, len(accesses)+1)
+       users := make([]*user_model.User, 0, len(accesses)+1)
        if len(accesses) > 0 {
                userIDs := make([]int64, len(accesses))
                for i := 0; i < len(accesses); i++ {
@@ -884,7 +882,7 @@ func (repo *Repository) ReadBy(userID int64) error {
        return setRepoNotificationStatusReadIfUnread(db.GetEngine(db.DefaultContext), userID, repo.ID)
 }
 
-func isRepositoryExist(e db.Engine, u *User, repoName string) (bool, error) {
+func isRepositoryExist(e db.Engine, u *user_model.User, repoName string) (bool, error) {
        has, err := e.Get(&Repository{
                OwnerID:   u.ID,
                LowerName: strings.ToLower(repoName),
@@ -897,7 +895,7 @@ func isRepositoryExist(e db.Engine, u *User, repoName string) (bool, error) {
 }
 
 // IsRepositoryExist returns true if the repository with given name under user has already existed.
-func IsRepositoryExist(u *User, repoName string) (bool, error) {
+func IsRepositoryExist(u *user_model.User, repoName string) (bool, error) {
        return isRepositoryExist(db.GetEngine(db.DefaultContext), u, repoName)
 }
 
@@ -951,7 +949,7 @@ func (repo *Repository) CloneLink() (cl *CloneLink) {
 }
 
 // CheckCreateRepository check if could created a repository
-func CheckCreateRepository(doer, u *User, name string, overwriteOrAdopt bool) error {
+func CheckCreateRepository(doer, u *user_model.User, name string, overwriteOrAdopt bool) error {
        if !doer.CanCreateRepo() {
                return ErrReachLimitOfRepo{u.MaxRepoCreation}
        }
@@ -1041,15 +1039,15 @@ var (
 
 // IsUsableRepoName returns true when repository is usable
 func IsUsableRepoName(name string) error {
-       if alphaDashDotPattern.MatchString(name) {
+       if db.AlphaDashDotPattern.MatchString(name) {
                // Note: usually this error is normally caught up earlier in the UI
-               return ErrNameCharsNotAllowed{Name: name}
+               return db.ErrNameCharsNotAllowed{Name: name}
        }
-       return isUsableName(reservedRepoNames, reservedRepoPatterns, name)
+       return db.IsUsableName(reservedRepoNames, reservedRepoPatterns, name)
 }
 
 // CreateRepository creates a repository for the user/organization.
-func CreateRepository(ctx context.Context, doer, u *User, repo *Repository, overwriteOrAdopt bool) (err error) {
+func CreateRepository(ctx context.Context, doer, u *user_model.User, repo *Repository, overwriteOrAdopt bool) (err error) {
        if err = IsUsableRepoName(repo.Name); err != nil {
                return err
        }
@@ -1115,11 +1113,11 @@ func CreateRepository(ctx context.Context, doer, u *User, repo *Repository, over
 
        // Remember visibility preference.
        u.LastRepoVisibility = repo.IsPrivate
-       if err = updateUserCols(db.GetEngine(ctx), u, "last_repo_visibility"); err != nil {
+       if err = user_model.UpdateUserColsEngine(db.GetEngine(ctx), u, "last_repo_visibility"); err != nil {
                return fmt.Errorf("updateUser: %v", err)
        }
 
-       if _, err = db.GetEngine(ctx).Incr("num_repos").ID(u.ID).Update(new(User)); err != nil {
+       if _, err = db.GetEngine(ctx).Incr("num_repos").ID(u.ID).Update(new(user_model.User)); err != nil {
                return fmt.Errorf("increment user total_repos: %v", err)
        }
        u.NumRepos++
@@ -1232,7 +1230,7 @@ func CountUserRepositories(userID int64, private bool) int64 {
 
 // RepoPath returns repository path by given user and repository name.
 func RepoPath(userName, repoName string) string {
-       return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
+       return filepath.Join(user_model.UserPath(userName), strings.ToLower(repoName)+".git")
 }
 
 // IncrementRepoForkNum increment repository fork number
@@ -1248,7 +1246,7 @@ func DecrementRepoForkNum(ctx context.Context, repoID int64) error {
 }
 
 // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
-func ChangeRepositoryName(doer *User, repo *Repository, newRepoName string) (err error) {
+func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName string) (err error) {
        oldRepoName := repo.Name
        newRepoName = strings.ToLower(newRepoName)
        if err = IsUsableRepoName(newRepoName); err != nil {
@@ -1441,7 +1439,7 @@ func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes [
 
 // DeleteRepository deletes a repository for a user or organization.
 // make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock)
-func DeleteRepository(doer *User, uid, repoID int64) error {
+func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -1450,7 +1448,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
        sess := db.GetEngine(ctx)
 
        // In case is a organization.
-       org, err := getUserByID(sess, uid)
+       org, err := user_model.GetUserByIDEngine(sess, uid)
        if err != nil {
                return err
        }
@@ -1802,11 +1800,11 @@ func getRepositoryCount(e db.Engine, ownerID int64) (int64, error) {
        return e.Count(&Repository{OwnerID: ownerID})
 }
 
-func getPublicRepositoryCount(e db.Engine, u *User) (int64, error) {
+func getPublicRepositoryCount(e db.Engine, u *user_model.User) (int64, error) {
        return e.Where("is_private = ?", false).Count(&Repository{OwnerID: u.ID})
 }
 
-func getPrivateRepositoryCount(e db.Engine, u *User) (int64, error) {
+func getPrivateRepositoryCount(e db.Engine, u *user_model.User) (int64, error) {
        return e.Where("is_private = ?", true).Count(&Repository{OwnerID: u.ID})
 }
 
@@ -1816,12 +1814,12 @@ func GetRepositoryCount(ctx context.Context, ownerID int64) (int64, error) {
 }
 
 // GetPublicRepositoryCount returns the total number of public repositories of user.
-func GetPublicRepositoryCount(u *User) (int64, error) {
+func GetPublicRepositoryCount(u *user_model.User) (int64, error) {
        return getPublicRepositoryCount(db.GetEngine(db.DefaultContext), u)
 }
 
 // GetPrivateRepositoryCount returns the total number of private repositories of user.
-func GetPrivateRepositoryCount(u *User) (int64, error) {
+func GetPrivateRepositoryCount(u *user_model.User) (int64, error) {
        return getPrivateRepositoryCount(db.GetEngine(db.DefaultContext), u)
 }
 
@@ -2155,7 +2153,7 @@ func (repo *Repository) GetTrustModel() TrustModelType {
        return trustModel
 }
 
-func updateUserStarNumbers(users []User) error {
+func updateUserStarNumbers(users []user_model.User) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -2176,7 +2174,7 @@ func DoctorUserStarNum() (err error) {
        const batchSize = 100
 
        for start := 0; ; start += batchSize {
-               users := make([]User, 0, batchSize)
+               users := make([]user_model.User, 0, batchSize)
                if err = db.GetEngine(db.DefaultContext).Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil {
                        return
                }
index 5986da7e77ae928d39a0dd72c6eeee79291ffacd..d3d4c7bbd714d95b3cfe9a03994f5aab9bff5e38 100644 (file)
@@ -10,6 +10,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
 
        "xorm.io/xorm"
@@ -94,13 +95,13 @@ func GetActivityStatsTopAuthors(repo *Repository, timeFrom time.Time, count int)
        }
        users := make(map[int64]*ActivityAuthorData)
        var unknownUserID int64
-       unknownUserAvatarLink := NewGhostUser().AvatarLink()
+       unknownUserAvatarLink := user_model.NewGhostUser().AvatarLink()
        for _, v := range code.Authors {
                if len(v.Email) == 0 {
                        continue
                }
-               u, err := GetUserByEmail(v.Email)
-               if u == nil || IsErrUserNotExist(err) {
+               u, err := user_model.GetUserByEmail(v.Email)
+               if u == nil || user_model.IsErrUserNotExist(err) {
                        unknownUserID--
                        users[unknownUserID] = &ActivityAuthorData{
                                Name:       v.Name,
index 6502d7959cab9f43eeff53d7afd43e047f5b394b..11d1a0e1d09b02ff9a39428b12fec234cd4e4226 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/timeutil"
 
@@ -30,7 +31,7 @@ func init() {
        db.RegisterModel(new(Collaboration))
 }
 
-func (repo *Repository) addCollaborator(e db.Engine, u *User) error {
+func (repo *Repository) addCollaborator(e db.Engine, u *user_model.User) error {
        collaboration := &Collaboration{
                RepoID: repo.ID,
                UserID: u.ID,
@@ -52,7 +53,7 @@ func (repo *Repository) addCollaborator(e db.Engine, u *User) error {
 }
 
 // AddCollaborator adds new collaboration to a repository with default access mode.
-func (repo *Repository) AddCollaborator(u *User) error {
+func (repo *Repository) AddCollaborator(u *user_model.User) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -80,7 +81,7 @@ func (repo *Repository) getCollaborations(e db.Engine, listOptions db.ListOption
 
 // Collaborator represents a user with collaboration details.
 type Collaborator struct {
-       *User
+       *user_model.User
        Collaboration *Collaboration
 }
 
@@ -92,11 +93,11 @@ func (repo *Repository) getCollaborators(e db.Engine, listOptions db.ListOptions
 
        collaborators := make([]*Collaborator, 0, len(collaborations))
        for _, c := range collaborations {
-               user, err := getUserByID(e, c.UserID)
+               user, err := user_model.GetUserByIDEngine(e, c.UserID)
                if err != nil {
-                       if IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                log.Warn("Inconsistent DB: User: %d is listed as collaborator of %-v but does not exist", c.UserID, repo)
-                               user = NewGhostUser()
+                               user = user_model.NewGhostUser()
                        } else {
                                return nil, err
                        }
@@ -227,7 +228,7 @@ func (repo *Repository) DeleteCollaboration(uid int64) (err error) {
 }
 
 func (repo *Repository) reconsiderIssueAssignees(e db.Engine, uid int64) error {
-       user, err := getUserByID(e, uid)
+       user, err := user_model.GetUserByIDEngine(e, uid)
        if err != nil {
                return err
        }
index 060afc2139bd746ffcc80f7308e54d886b770c00..94dd238cb6ff9e74b6a115311d60bfe7afc9200b 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -19,9 +20,9 @@ func TestRepository_AddCollaborator(t *testing.T) {
        testSuccess := func(repoID, userID int64) {
                repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
                assert.NoError(t, repo.GetOwner())
-               user := unittest.AssertExistsAndLoadBean(t, &User{ID: userID}).(*User)
+               user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}).(*user_model.User)
                assert.NoError(t, repo.AddCollaborator(user))
-               unittest.CheckConsistencyFor(t, &Repository{ID: repoID}, &User{ID: userID})
+               unittest.CheckConsistencyFor(t, &Repository{ID: repoID}, &user_model.User{ID: userID})
        }
        testSuccess(1, 4)
        testSuccess(1, 4)
index 511b446711da382eacefaa7642f6555e6be12307..ff86f61577ede7570ccffb9cff789bffed5bb41d 100644 (file)
@@ -9,6 +9,7 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/util"
 
@@ -55,7 +56,7 @@ func (repos RepositoryList) loadAttributes(e db.Engine) error {
        }
 
        // Load owners.
-       users := make(map[int64]*User, len(set))
+       users := make(map[int64]*user_model.User, len(set))
        if err := e.
                Where("id > 0").
                In("id", keysInt64(set)).
@@ -135,12 +136,12 @@ func (repos MirrorRepositoryList) LoadAttributes() error {
 // SearchRepoOptions holds the search options
 type SearchRepoOptions struct {
        db.ListOptions
-       Actor           *User
+       Actor           *user_model.User
        Keyword         string
        OwnerID         int64
        PriorityOwnerID int64
        TeamID          int64
-       OrderBy         SearchOrderBy
+       OrderBy         db.SearchOrderBy
        Private         bool // Include private repositories in results
        StarredByID     int64
        WatchedByID     int64
@@ -182,31 +183,6 @@ type SearchRepoOptions struct {
        LowerNames []string
 }
 
-// SearchOrderBy is used to sort the result
-type SearchOrderBy string
-
-func (s SearchOrderBy) String() string {
-       return string(s)
-}
-
-// Strings for sorting result
-const (
-       SearchOrderByAlphabetically        SearchOrderBy = "name ASC"
-       SearchOrderByAlphabeticallyReverse SearchOrderBy = "name DESC"
-       SearchOrderByLeastUpdated          SearchOrderBy = "updated_unix ASC"
-       SearchOrderByRecentUpdated         SearchOrderBy = "updated_unix DESC"
-       SearchOrderByOldest                SearchOrderBy = "created_unix ASC"
-       SearchOrderByNewest                SearchOrderBy = "created_unix DESC"
-       SearchOrderBySize                  SearchOrderBy = "size ASC"
-       SearchOrderBySizeReverse           SearchOrderBy = "size DESC"
-       SearchOrderByID                    SearchOrderBy = "id ASC"
-       SearchOrderByIDReverse             SearchOrderBy = "id DESC"
-       SearchOrderByStars                 SearchOrderBy = "num_stars ASC"
-       SearchOrderByStarsReverse          SearchOrderBy = "num_stars DESC"
-       SearchOrderByForks                 SearchOrderBy = "num_forks ASC"
-       SearchOrderByForksReverse          SearchOrderBy = "num_forks DESC"
-)
-
 // SearchRepositoryCondition creates a query condition according search repository options
 func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
        cond := builder.NewCond()
@@ -278,7 +254,7 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
                                                                Join("INNER", "`user`", "`user`.id = `org_user`.org_id").
                                                                Where(builder.Eq{
                                                                        "`org_user`.uid":    opts.OwnerID,
-                                                                       "`user`.type":       UserTypeOrganization,
+                                                                       "`user`.type":       user_model.UserTypeOrganization,
                                                                        "`user`.visibility": structs.VisibleTypePrivate,
                                                                })))),
                        )
@@ -401,11 +377,11 @@ func searchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond) (db
        }
 
        if len(opts.OrderBy) == 0 {
-               opts.OrderBy = SearchOrderByAlphabetically
+               opts.OrderBy = db.SearchOrderByAlphabetically
        }
 
        if opts.PriorityOwnerID > 0 {
-               opts.OrderBy = SearchOrderBy(fmt.Sprintf("CASE WHEN owner_id = %d THEN 0 ELSE owner_id END, %s", opts.PriorityOwnerID, opts.OrderBy))
+               opts.OrderBy = db.SearchOrderBy(fmt.Sprintf("CASE WHEN owner_id = %d THEN 0 ELSE owner_id END, %s", opts.PriorityOwnerID, opts.OrderBy))
        }
 
        sess := db.GetEngine(db.DefaultContext)
@@ -429,7 +405,7 @@ func searchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond) (db
 }
 
 // accessibleRepositoryCondition takes a user a returns a condition for checking if a repository is accessible
-func accessibleRepositoryCondition(user *User) builder.Cond {
+func accessibleRepositoryCondition(user *user_model.User) builder.Cond {
        cond := builder.NewCond()
 
        if user == nil || !user.IsRestricted || user.ID <= 0 {
@@ -443,7 +419,7 @@ func accessibleRepositoryCondition(user *User) builder.Cond {
                        // 2. Aren't in an private organisation or limited organisation if we're not logged in
                        builder.NotIn("`repository`.owner_id", builder.Select("id").From("`user`").Where(
                                builder.And(
-                                       builder.Eq{"type": UserTypeOrganization},
+                                       builder.Eq{"type": user_model.UserTypeOrganization},
                                        builder.In("visibility", orgVisibilityLimit)),
                        ))))
        }
@@ -508,13 +484,13 @@ func SearchRepositoryIDs(opts *SearchRepoOptions) ([]int64, int64, error) {
 }
 
 // AccessibleRepoIDsQuery queries accessible repository ids. Usable as a subquery wherever repo ids need to be filtered.
-func AccessibleRepoIDsQuery(user *User) *builder.Builder {
+func AccessibleRepoIDsQuery(user *user_model.User) *builder.Builder {
        // NB: Please note this code needs to still work if user is nil
        return builder.Select("id").From("repository").Where(accessibleRepositoryCondition(user))
 }
 
 // FindUserAccessibleRepoIDs find all accessible repositories' ID by user's id
-func FindUserAccessibleRepoIDs(user *User) ([]int64, error) {
+func FindUserAccessibleRepoIDs(user *user_model.User) ([]int64, error) {
        repoIDs := make([]int64, 0, 10)
        if err := db.GetEngine(db.DefaultContext).
                Table("repository").
index a6304cf1aaf52cec5f7aba011fb305526398940b..96abb9037ab74aaae6fd3296421fe21edef3711f 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
 )
 
@@ -140,11 +141,11 @@ func (p *Permission) ColorFormat(s fmt.State) {
 }
 
 // GetUserRepoPermission returns the user permissions to the repository
-func GetUserRepoPermission(repo *Repository, user *User) (Permission, error) {
+func GetUserRepoPermission(repo *Repository, user *user_model.User) (Permission, error) {
        return getUserRepoPermission(db.GetEngine(db.DefaultContext), repo, user)
 }
 
-func getUserRepoPermission(e db.Engine, repo *Repository, user *User) (perm Permission, err error) {
+func getUserRepoPermission(e db.Engine, repo *Repository, user *user_model.User) (perm Permission, err error) {
        if log.IsTrace() {
                defer func() {
                        if user == nil {
@@ -274,7 +275,7 @@ func getUserRepoPermission(e db.Engine, repo *Repository, user *User) (perm Perm
 }
 
 // IsUserRealRepoAdmin check if this user is real repo admin
-func IsUserRealRepoAdmin(repo *Repository, user *User) (bool, error) {
+func IsUserRealRepoAdmin(repo *Repository, user *user_model.User) (bool, error) {
        if repo.OwnerID == user.ID {
                return true, nil
        }
@@ -294,11 +295,11 @@ func IsUserRealRepoAdmin(repo *Repository, user *User) (bool, error) {
 }
 
 // IsUserRepoAdmin return true if user has admin right of a repo
-func IsUserRepoAdmin(repo *Repository, user *User) (bool, error) {
+func IsUserRepoAdmin(repo *Repository, user *user_model.User) (bool, error) {
        return isUserRepoAdmin(db.GetEngine(db.DefaultContext), repo, user)
 }
 
-func isUserRepoAdmin(e db.Engine, repo *Repository, user *User) (bool, error) {
+func isUserRepoAdmin(e db.Engine, repo *Repository, user *user_model.User) (bool, error) {
        if user == nil || repo == nil {
                return false, nil
        }
@@ -329,17 +330,17 @@ func isUserRepoAdmin(e db.Engine, repo *Repository, user *User) (bool, error) {
 
 // AccessLevel returns the Access a user has to a repository. Will return NoneAccess if the
 // user does not have access.
-func AccessLevel(user *User, repo *Repository) (AccessMode, error) {
+func AccessLevel(user *user_model.User, repo *Repository) (AccessMode, error) {
        return accessLevelUnit(db.GetEngine(db.DefaultContext), user, repo, unit.TypeCode)
 }
 
 // AccessLevelUnit returns the Access a user has to a repository's. Will return NoneAccess if the
 // user does not have access.
-func AccessLevelUnit(user *User, repo *Repository, unitType unit.Type) (AccessMode, error) {
+func AccessLevelUnit(user *user_model.User, repo *Repository, unitType unit.Type) (AccessMode, error) {
        return accessLevelUnit(db.GetEngine(db.DefaultContext), user, repo, unitType)
 }
 
-func accessLevelUnit(e db.Engine, user *User, repo *Repository, unitType unit.Type) (AccessMode, error) {
+func accessLevelUnit(e db.Engine, user *user_model.User, repo *Repository, unitType unit.Type) (AccessMode, error) {
        perm, err := getUserRepoPermission(e, repo, user)
        if err != nil {
                return AccessModeNone, err
@@ -347,24 +348,24 @@ func accessLevelUnit(e db.Engine, user *User, repo *Repository, unitType unit.Ty
        return perm.UnitAccessMode(unitType), nil
 }
 
-func hasAccessUnit(e db.Engine, user *User, repo *Repository, unitType unit.Type, testMode AccessMode) (bool, error) {
+func hasAccessUnit(e db.Engine, user *user_model.User, repo *Repository, unitType unit.Type, testMode AccessMode) (bool, error) {
        mode, err := accessLevelUnit(e, user, repo, unitType)
        return testMode <= mode, err
 }
 
 // HasAccessUnit returns true if user has testMode to the unit of the repository
-func HasAccessUnit(user *User, repo *Repository, unitType unit.Type, testMode AccessMode) (bool, error) {
+func HasAccessUnit(user *user_model.User, repo *Repository, unitType unit.Type, testMode AccessMode) (bool, error) {
        return hasAccessUnit(db.GetEngine(db.DefaultContext), user, repo, unitType, testMode)
 }
 
 // CanBeAssigned return true if user can be assigned to issue or pull requests in repo
 // Currently any write access (code, issues or pr's) is assignable, to match assignee list in user interface.
 // FIXME: user could send PullRequest also could be assigned???
-func CanBeAssigned(user *User, repo *Repository, isPull bool) (bool, error) {
+func CanBeAssigned(user *user_model.User, repo *Repository, isPull bool) (bool, error) {
        return canBeAssigned(db.GetEngine(db.DefaultContext), user, repo, isPull)
 }
 
-func canBeAssigned(e db.Engine, user *User, repo *Repository, _ bool) (bool, error) {
+func canBeAssigned(e db.Engine, user *user_model.User, repo *Repository, _ bool) (bool, error) {
        if user.IsOrganization() {
                return false, fmt.Errorf("Organization can't be added as assignee [user_id: %d, repo_id: %d]", user.ID, repo.ID)
        }
@@ -376,10 +377,10 @@ func canBeAssigned(e db.Engine, user *User, repo *Repository, _ bool) (bool, err
 }
 
 func hasAccess(e db.Engine, userID int64, repo *Repository) (bool, error) {
-       var user *User
+       var user *user_model.User
        var err error
        if userID > 0 {
-               user, err = getUserByID(e, userID)
+               user, err = user_model.GetUserByIDEngine(e, userID)
                if err != nil {
                        return false, err
                }
@@ -397,7 +398,7 @@ func HasAccess(userID int64, repo *Repository) (bool, error) {
 }
 
 // FilterOutRepoIdsWithoutUnitAccess filter out repos where user has no access to repositories
-func FilterOutRepoIdsWithoutUnitAccess(u *User, repoIDs []int64, units ...unit.Type) ([]int64, error) {
+func FilterOutRepoIdsWithoutUnitAccess(u *user_model.User, repoIDs []int64, units ...unit.Type) ([]int64, error) {
        i := 0
        for _, rID := range repoIDs {
                repo, err := GetRepositoryByID(rID)
index 180a85a2f5dce0effb022b637fbcd2a9397a3dda..ce046eba7a1bcbca3780900638f43410cf2b6d61 100644 (file)
@@ -10,6 +10,7 @@ import (
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -22,7 +23,7 @@ func TestRepoPermissionPublicNonOrgRepo(t *testing.T) {
        assert.NoError(t, repo.getUnits(db.GetEngine(db.DefaultContext)))
 
        // plain user
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        perm, err := GetUserRepoPermission(repo, user)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -40,7 +41,7 @@ func TestRepoPermissionPublicNonOrgRepo(t *testing.T) {
        }
 
        // collaborator
-       collaborator := unittest.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
+       collaborator := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, collaborator)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -49,7 +50,7 @@ func TestRepoPermissionPublicNonOrgRepo(t *testing.T) {
        }
 
        // owner
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, owner)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -58,7 +59,7 @@ func TestRepoPermissionPublicNonOrgRepo(t *testing.T) {
        }
 
        // admin
-       admin := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, admin)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -75,7 +76,7 @@ func TestRepoPermissionPrivateNonOrgRepo(t *testing.T) {
        assert.NoError(t, repo.getUnits(db.GetEngine(db.DefaultContext)))
 
        // plain user
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
        perm, err := GetUserRepoPermission(repo, user)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -101,7 +102,7 @@ func TestRepoPermissionPrivateNonOrgRepo(t *testing.T) {
        }
 
        // owner
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, owner)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -110,7 +111,7 @@ func TestRepoPermissionPrivateNonOrgRepo(t *testing.T) {
        }
 
        // admin
-       admin := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, admin)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -127,7 +128,7 @@ func TestRepoPermissionPublicOrgRepo(t *testing.T) {
        assert.NoError(t, repo.getUnits(db.GetEngine(db.DefaultContext)))
 
        // plain user
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
        perm, err := GetUserRepoPermission(repo, user)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -153,7 +154,7 @@ func TestRepoPermissionPublicOrgRepo(t *testing.T) {
        }
 
        // org member team owner
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, owner)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -162,7 +163,7 @@ func TestRepoPermissionPublicOrgRepo(t *testing.T) {
        }
 
        // org member team tester
-       member := unittest.AssertExistsAndLoadBean(t, &User{ID: 15}).(*User)
+       member := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 15}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, member)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -172,7 +173,7 @@ func TestRepoPermissionPublicOrgRepo(t *testing.T) {
        assert.False(t, perm.CanWrite(unit.TypeCode))
 
        // admin
-       admin := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, admin)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -189,7 +190,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) {
        assert.NoError(t, repo.getUnits(db.GetEngine(db.DefaultContext)))
 
        // plain user
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
        perm, err := GetUserRepoPermission(repo, user)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -215,7 +216,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) {
        }
 
        // org member team owner
-       owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 15}).(*User)
+       owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 15}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, owner)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
@@ -235,7 +236,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) {
        }
 
        // org member team tester
-       tester := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       tester := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, tester)
        assert.NoError(t, err)
        assert.True(t, perm.CanWrite(unit.TypeIssues))
@@ -243,7 +244,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) {
        assert.False(t, perm.CanRead(unit.TypeCode))
 
        // org member team reviewer
-       reviewer := unittest.AssertExistsAndLoadBean(t, &User{ID: 20}).(*User)
+       reviewer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 20}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, reviewer)
        assert.NoError(t, err)
        assert.False(t, perm.CanRead(unit.TypeIssues))
@@ -251,7 +252,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) {
        assert.True(t, perm.CanRead(unit.TypeCode))
 
        // admin
-       admin := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        perm, err = GetUserRepoPermission(repo, admin)
        assert.NoError(t, err)
        for _, unit := range repo.Units {
index f7a303b0c1242f60b17bb8837c472825c7003bf0..f30ba4748c66e823bcb596ce4542d1780c419cbc 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/login"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/process"
@@ -107,7 +108,7 @@ func PublicSigningKey(repoPath string) (string, error) {
 }
 
 // SignInitialCommit determines if we should sign the initial commit to this repository
-func SignInitialCommit(repoPath string, u *User) (bool, string, *git.Signature, error) {
+func SignInitialCommit(repoPath string, u *user_model.User) (bool, string, *git.Signature, error) {
        rules := signingModeFromStrings(setting.Repository.Signing.InitialCommit)
        signingKey, sig := SigningKey(repoPath)
        if signingKey == "" {
@@ -143,7 +144,7 @@ Loop:
 }
 
 // SignWikiCommit determines if we should sign the commits to this repository wiki
-func (repo *Repository) SignWikiCommit(u *User) (bool, string, *git.Signature, error) {
+func (repo *Repository) SignWikiCommit(u *user_model.User) (bool, string, *git.Signature, error) {
        rules := signingModeFromStrings(setting.Repository.Signing.Wiki)
        signingKey, sig := SigningKey(repo.WikiPath())
        if signingKey == "" {
@@ -196,7 +197,7 @@ Loop:
 }
 
 // SignCRUDAction determines if we should sign a CRUD commit to this repository
-func (repo *Repository) SignCRUDAction(u *User, tmpBasePath, parentCommit string) (bool, string, *git.Signature, error) {
+func (repo *Repository) SignCRUDAction(u *user_model.User, tmpBasePath, parentCommit string) (bool, string, *git.Signature, error) {
        rules := signingModeFromStrings(setting.Repository.Signing.CRUDActions)
        signingKey, sig := SigningKey(repo.RepoPath())
        if signingKey == "" {
index 5cc396eb76a2587495491fe11538da45861d8d78..e6aaedaae65c2e6466aa03e6d61a6530fd1b8262 100644 (file)
@@ -16,6 +16,7 @@ import (
        repo_model "code.gitea.io/gitea/models/repo"
        "code.gitea.io/gitea/models/unit"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/markup"
 
        "github.com/stretchr/testify/assert"
@@ -25,7 +26,7 @@ func TestMetas(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
        repo := &Repository{Name: "testRepo"}
-       repo.Owner = &User{Name: "testOwner"}
+       repo.Owner = &user_model.User{Name: "testOwner"}
        repo.OwnerName = repo.Owner.Name
 
        repo.Units = nil
@@ -73,8 +74,8 @@ func TestGetRepositoryCount(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
        count, err1 := GetRepositoryCount(db.DefaultContext, 10)
-       privateCount, err2 := GetPrivateRepositoryCount(&User{ID: int64(10)})
-       publicCount, err3 := GetPublicRepositoryCount(&User{ID: int64(10)})
+       privateCount, err2 := GetPrivateRepositoryCount(&user_model.User{ID: int64(10)})
+       publicCount, err3 := GetPublicRepositoryCount(&user_model.User{ID: int64(10)})
        assert.NoError(t, err1)
        assert.NoError(t, err2)
        assert.NoError(t, err3)
@@ -85,7 +86,7 @@ func TestGetRepositoryCount(t *testing.T) {
 func TestGetPublicRepositoryCount(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       count, err := GetPublicRepositoryCount(&User{ID: int64(10)})
+       count, err := GetPublicRepositoryCount(&user_model.User{ID: int64(10)})
        assert.NoError(t, err)
        assert.Equal(t, int64(1), count)
 }
@@ -93,7 +94,7 @@ func TestGetPublicRepositoryCount(t *testing.T) {
 func TestGetPrivateRepositoryCount(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       count, err := GetPrivateRepositoryCount(&User{ID: int64(10)})
+       count, err := GetPrivateRepositoryCount(&user_model.User{ID: int64(10)})
        assert.NoError(t, err)
        assert.Equal(t, int64(2), count)
 }
index 3b5ac21b09c0196154ca210887d157484ebbdbbb..9918a10d7670a15db4e7299ec85c775a3406d158 100644 (file)
@@ -9,6 +9,7 @@ import (
        "os"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/timeutil"
        "code.gitea.io/gitea/modules/util"
@@ -18,9 +19,9 @@ import (
 type RepoTransfer struct {
        ID          int64 `xorm:"pk autoincr"`
        DoerID      int64
-       Doer        *User `xorm:"-"`
+       Doer        *user_model.User `xorm:"-"`
        RecipientID int64
-       Recipient   *User `xorm:"-"`
+       Recipient   *user_model.User `xorm:"-"`
        RepoID      int64
        TeamIDs     []int64
        Teams       []*Team `xorm:"-"`
@@ -36,7 +37,7 @@ func init() {
 // LoadAttributes fetches the transfer recipient from the database
 func (r *RepoTransfer) LoadAttributes() error {
        if r.Recipient == nil {
-               u, err := GetUserByID(r.RecipientID)
+               u, err := user_model.GetUserByID(r.RecipientID)
                if err != nil {
                        return err
                }
@@ -60,7 +61,7 @@ func (r *RepoTransfer) LoadAttributes() error {
        }
 
        if r.Doer == nil {
-               u, err := GetUserByID(r.DoerID)
+               u, err := user_model.GetUserByID(r.DoerID)
                if err != nil {
                        return err
                }
@@ -74,7 +75,7 @@ func (r *RepoTransfer) LoadAttributes() error {
 // CanUserAcceptTransfer checks if the user has the rights to accept/decline a repo transfer.
 // For user, it checks if it's himself
 // For organizations, it checks if the user is able to create repos
-func (r *RepoTransfer) CanUserAcceptTransfer(u *User) bool {
+func (r *RepoTransfer) CanUserAcceptTransfer(u *user_model.User) bool {
        if err := r.LoadAttributes(); err != nil {
                log.Error("LoadAttributes: %v", err)
                return false
@@ -150,7 +151,7 @@ func TestRepositoryReadyForTransfer(status RepositoryStatus) error {
 
 // CreatePendingRepositoryTransfer transfer a repo from one owner to a new one.
 // it marks the repository transfer as "pending"
-func CreatePendingRepositoryTransfer(doer, newOwner *User, repoID int64, teams []*Team) error {
+func CreatePendingRepositoryTransfer(doer, newOwner *user_model.User, repoID int64, teams []*Team) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -201,7 +202,7 @@ func CreatePendingRepositoryTransfer(doer, newOwner *User, repoID int64, teams [
 }
 
 // TransferOwnership transfers all corresponding repository items from old user to new one.
-func TransferOwnership(doer *User, newOwnerName string, repo *Repository) (err error) {
+func TransferOwnership(doer *user_model.User, newOwnerName string, repo *Repository) (err error) {
        repoRenamed := false
        wikiRenamed := false
        oldOwnerName := doer.Name
@@ -242,7 +243,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) (err e
 
        sess := db.GetEngine(ctx)
 
-       newOwner, err := getUserByName(sess, newOwnerName)
+       newOwner, err := user_model.GetUserByNameCtx(ctx, newOwnerName)
        if err != nil {
                return fmt.Errorf("get new owner '%s': %v", newOwnerName, err)
        }
@@ -371,7 +372,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) (err e
        }
 
        // Rename remote repository to new path and delete local copy.
-       dir := UserPath(newOwner.Name)
+       dir := user_model.UserPath(newOwner.Name)
 
        if err := os.MkdirAll(dir, os.ModePerm); err != nil {
                return fmt.Errorf("Failed to create dir %s: %v", dir, err)
index 368fea598deacffc8f58c9309339403c2f717796..1bde5628c1966305ca052490eaa8cf3d70ab1c36 100644 (file)
@@ -8,6 +8,7 @@ import (
        "testing"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -15,7 +16,7 @@ import (
 func TestRepositoryTransfer(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       doer := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+       doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
 
        transfer, err := GetPendingRepositoryTransfer(repo)
@@ -30,7 +31,7 @@ func TestRepositoryTransfer(t *testing.T) {
        assert.Nil(t, transfer)
        assert.True(t, IsErrNoPendingTransfer(err))
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        assert.NoError(t, CreatePendingRepositoryTransfer(doer, user2, repo.ID, nil))
 
@@ -39,7 +40,7 @@ func TestRepositoryTransfer(t *testing.T) {
        assert.NoError(t, transfer.LoadAttributes())
        assert.Equal(t, "user2", transfer.Recipient.Name)
 
-       user6 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       user6 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        // Only transfer can be started at any given time
        err = CreatePendingRepositoryTransfer(doer, user6, repo.ID, nil)
@@ -47,7 +48,7 @@ func TestRepositoryTransfer(t *testing.T) {
        assert.True(t, IsErrRepoTransferInProgress(err))
 
        // Unknown user
-       err = CreatePendingRepositoryTransfer(doer, &User{ID: 1000, LowerName: "user1000"}, repo.ID, nil)
+       err = CreatePendingRepositoryTransfer(doer, &user_model.User{ID: 1000, LowerName: "user1000"}, repo.ID, nil)
        assert.Error(t, err)
 
        // Cancel transfer
index fb1b1086aa1ab143df33e465971c22166c5a7f46..e225c945e95acd8244c1ded490e5ac2d371c9a27 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/timeutil"
 )
@@ -166,18 +167,18 @@ func getRepoWatchersIDs(e db.Engine, repoID int64) ([]int64, error) {
 }
 
 // GetWatchers returns range of users watching given repository.
-func (repo *Repository) GetWatchers(opts db.ListOptions) ([]*User, error) {
+func (repo *Repository) GetWatchers(opts db.ListOptions) ([]*user_model.User, error) {
        sess := db.GetEngine(db.DefaultContext).Where("watch.repo_id=?", repo.ID).
                Join("LEFT", "watch", "`user`.id=`watch`.user_id").
                And("`watch`.mode<>?", RepoWatchModeDont)
        if opts.Page > 0 {
                sess = db.SetSessionPagination(sess, &opts)
-               users := make([]*User, 0, opts.PageSize)
+               users := make([]*user_model.User, 0, opts.PageSize)
 
                return users, sess.Find(&users)
        }
 
-       users := make([]*User, 0, 8)
+       users := make([]*user_model.User, 0, 8)
        return users, sess.Find(&users)
 }
 
@@ -232,7 +233,7 @@ func notifyWatchers(e db.Engine, actions ...*Action) error {
                        permIssue = make([]bool, len(watchers))
                        permPR = make([]bool, len(watchers))
                        for i, watcher := range watchers {
-                               user, err := getUserByID(e, watcher.UserID)
+                               user, err := user_model.GetUserByIDEngine(e, watcher.UserID)
                                if err != nil {
                                        permCode[i] = false
                                        permIssue[i] = false
index 00906c7a2730e5f94a13087c110ba43e6df40c86..1c4943f6993117ae8a83ebba5deaea295fe1f4cf 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/timeutil"
 
@@ -55,10 +56,10 @@ func (rt ReviewType) Icon() string {
 type Review struct {
        ID               int64 `xorm:"pk autoincr"`
        Type             ReviewType
-       Reviewer         *User `xorm:"-"`
-       ReviewerID       int64 `xorm:"index"`
-       ReviewerTeamID   int64 `xorm:"NOT NULL DEFAULT 0"`
-       ReviewerTeam     *Team `xorm:"-"`
+       Reviewer         *user_model.User `xorm:"-"`
+       ReviewerID       int64            `xorm:"index"`
+       ReviewerTeamID   int64            `xorm:"NOT NULL DEFAULT 0"`
+       ReviewerTeam     *Team            `xorm:"-"`
        OriginalAuthor   string
        OriginalAuthorID int64
        Issue            *Issue `xorm:"-"`
@@ -111,7 +112,7 @@ func (r *Review) loadReviewer(e db.Engine) (err error) {
        if r.ReviewerID == 0 || r.Reviewer != nil {
                return
        }
-       r.Reviewer, err = getUserByID(e, r.ReviewerID)
+       r.Reviewer, err = user_model.GetUserByIDEngine(e, r.ReviewerID)
        return
 }
 
@@ -224,7 +225,7 @@ type CreateReviewOptions struct {
        Content      string
        Type         ReviewType
        Issue        *Issue
-       Reviewer     *User
+       Reviewer     *user_model.User
        ReviewerTeam *Team
        Official     bool
        CommitID     string
@@ -232,11 +233,11 @@ type CreateReviewOptions struct {
 }
 
 // IsOfficialReviewer check if at least one of the provided reviewers can make official reviews in issue (counts towards required approvals)
-func IsOfficialReviewer(issue *Issue, reviewers ...*User) (bool, error) {
+func IsOfficialReviewer(issue *Issue, reviewers ...*user_model.User) (bool, error) {
        return isOfficialReviewer(db.GetEngine(db.DefaultContext), issue, reviewers...)
 }
 
-func isOfficialReviewer(e db.Engine, issue *Issue, reviewers ...*User) (bool, error) {
+func isOfficialReviewer(e db.Engine, issue *Issue, reviewers ...*user_model.User) (bool, error) {
        pr, err := getPullRequestByIssueID(e, issue.ID)
        if err != nil {
                return false, err
@@ -314,7 +315,7 @@ func CreateReview(opts CreateReviewOptions) (*Review, error) {
        return createReview(db.GetEngine(db.DefaultContext), opts)
 }
 
-func getCurrentReview(e db.Engine, reviewer *User, issue *Issue) (*Review, error) {
+func getCurrentReview(e db.Engine, reviewer *user_model.User, issue *Issue) (*Review, error) {
        if reviewer == nil {
                return nil, nil
        }
@@ -340,7 +341,7 @@ func ReviewExists(issue *Issue, treePath string, line int64) (bool, error) {
 }
 
 // GetCurrentReview returns the current pending review of reviewer for given issue
-func GetCurrentReview(reviewer *User, issue *Issue) (*Review, error) {
+func GetCurrentReview(reviewer *user_model.User, issue *Issue) (*Review, error) {
        return getCurrentReview(db.GetEngine(db.DefaultContext), reviewer, issue)
 }
 
@@ -358,7 +359,7 @@ func IsContentEmptyErr(err error) bool {
 }
 
 // SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
-func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) {
+func SubmitReview(doer *user_model.User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return nil, nil, err
@@ -627,7 +628,7 @@ func InsertReviews(reviews []*Review) error {
 }
 
 // AddReviewRequest add a review request from one reviewer
-func AddReviewRequest(issue *Issue, reviewer, doer *User) (*Comment, error) {
+func AddReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Comment, error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return nil, err
@@ -682,7 +683,7 @@ func AddReviewRequest(issue *Issue, reviewer, doer *User) (*Comment, error) {
 }
 
 // RemoveReviewRequest remove a review request from one reviewer
-func RemoveReviewRequest(issue *Issue, reviewer, doer *User) (*Comment, error) {
+func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Comment, error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return nil, err
@@ -736,7 +737,7 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *User) (*Comment, error) {
 }
 
 // AddTeamReviewRequest add a review request from one team
-func AddTeamReviewRequest(issue *Issue, reviewer *Team, doer *User) (*Comment, error) {
+func AddTeamReviewRequest(issue *Issue, reviewer *Team, doer *user_model.User) (*Comment, error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return nil, err
@@ -796,7 +797,7 @@ func AddTeamReviewRequest(issue *Issue, reviewer *Team, doer *User) (*Comment, e
 }
 
 // RemoveTeamReviewRequest remove a review request from one team
-func RemoveTeamReviewRequest(issue *Issue, reviewer *Team, doer *User) (*Comment, error) {
+func RemoveTeamReviewRequest(issue *Issue, reviewer *Team, doer *user_model.User) (*Comment, error) {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return nil, err
@@ -856,7 +857,7 @@ func RemoveTeamReviewRequest(issue *Issue, reviewer *Team, doer *User) (*Comment
 }
 
 // MarkConversation Add or remove Conversation mark for a code comment
-func MarkConversation(comment *Comment, doer *User, isResolve bool) (err error) {
+func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (err error) {
        if comment.Type != CommentTypeCode {
                return nil
        }
@@ -884,7 +885,7 @@ func MarkConversation(comment *Comment, doer *User, isResolve bool) (err error)
 
 // CanMarkConversation  Add or remove Conversation mark for a code comment permission check
 // the PR writer , offfcial reviewer and poster can do it
-func CanMarkConversation(issue *Issue, doer *User) (permResult bool, err error) {
+func CanMarkConversation(issue *Issue, doer *user_model.User) (permResult bool, err error) {
        if doer == nil || issue == nil {
                return false, fmt.Errorf("issue or doer is nil")
        }
index 7b8b86df1320bfb2be1cd0d687a8ad4872c4d60a..b9d156ceb18cbf3379b487d0200fe7d0b3ac1f9c 100644 (file)
@@ -8,6 +8,7 @@ import (
        "testing"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -72,7 +73,7 @@ func TestFindReviews(t *testing.T) {
 func TestGetCurrentReview(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
        issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        review, err := GetCurrentReview(user, issue)
        assert.NoError(t, err)
@@ -80,7 +81,7 @@ func TestGetCurrentReview(t *testing.T) {
        assert.Equal(t, ReviewTypePending, review.Type)
        assert.Equal(t, "Pending Review", review.Content)
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 7}).(*User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 7}).(*user_model.User)
        review2, err := GetCurrentReview(user2, issue)
        assert.Error(t, err)
        assert.True(t, IsErrReviewNotExist(err))
@@ -91,7 +92,7 @@ func TestCreateReview(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
        issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        review, err := CreateReview(CreateReviewOptions{
                Content:  "New Review",
@@ -108,9 +109,9 @@ func TestGetReviewersByIssueID(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
        issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 3}).(*Issue)
-       user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
-       user4 := unittest.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
 
        expectedReviews := []*Review{}
        expectedReviews = append(expectedReviews,
index 21d5b7d4964f9bcc033ce642238d4920dffeded1..780eb2e15ce8015cbfdeb5b8d6299ed177a129fe 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/login"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/timeutil"
        "code.gitea.io/gitea/modules/util"
@@ -324,7 +325,7 @@ func PublicKeyIsExternallyManaged(id int64) (bool, error) {
 }
 
 // DeletePublicKey deletes SSH key information both in database and authorized_keys file.
-func DeletePublicKey(doer *User, id int64) (err error) {
+func DeletePublicKey(doer *user_model.User, id int64) (err error) {
        key, err := GetPublicKeyByID(id)
        if err != nil {
                return err
@@ -390,7 +391,7 @@ func deleteKeysMarkedForDeletion(keys []string) (bool, error) {
 }
 
 // AddPublicKeysBySource add a users public keys. Returns true if there are changes.
-func AddPublicKeysBySource(usr *User, s *login.Source, sshPublicKeys []string) bool {
+func AddPublicKeysBySource(usr *user_model.User, s *login.Source, sshPublicKeys []string) bool {
        var sshKeysNeedUpdate bool
        for _, sshKey := range sshPublicKeys {
                var err error
@@ -428,7 +429,7 @@ func AddPublicKeysBySource(usr *User, s *login.Source, sshPublicKeys []string) b
 }
 
 // SynchronizePublicKeys updates a users public keys. Returns true if there are changes.
-func SynchronizePublicKeys(usr *User, s *login.Source, sshPublicKeys []string) bool {
+func SynchronizePublicKeys(usr *user_model.User, s *login.Source, sshPublicKeys []string) bool {
        var sshKeysNeedUpdate bool
 
        log.Trace("synchronizePublicKeys[%s]: Handling Public SSH Key synchronization for user %s", s.Name, usr.Name)
index c31379dcb47450211c8fdf28decf15f772158a5e..cf439f6282f7266063196dc89487d5d1675fbef7 100644 (file)
@@ -9,6 +9,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/timeutil"
 
        "xorm.io/builder"
@@ -212,7 +213,7 @@ func UpdateDeployKey(key *DeployKey) error {
 }
 
 // DeleteDeployKey deletes deploy key from its repository authorized_keys file if needed.
-func DeleteDeployKey(doer *User, id int64) error {
+func DeleteDeployKey(doer *user_model.User, id int64) error {
        ctx, committer, err := db.TxContext()
        if err != nil {
                return err
@@ -225,7 +226,7 @@ func DeleteDeployKey(doer *User, id int64) error {
        return committer.Commit()
 }
 
-func deleteDeployKey(sess db.Engine, doer *User, id int64) error {
+func deleteDeployKey(sess db.Engine, doer *user_model.User, id int64) error {
        key, err := getDeployKeyByID(sess, id)
        if err != nil {
                if IsErrDeployKeyNotExist(err) {
index 55d8e4039766b690e23ae4943f8948502284edb9..63c38f6886e5a67b62305fe8d97221872d5a25ee 100644 (file)
@@ -73,7 +73,7 @@ func addPrincipalKey(e db.Engine, key *PublicKey) (err error) {
 }
 
 // CheckPrincipalKeyString strips spaces and returns an error if the given principal contains newlines
-func CheckPrincipalKeyString(user *User, content string) (_ string, err error) {
+func CheckPrincipalKeyString(user *user_model.User, content string) (_ string, err error) {
        if setting.SSH.Disabled {
                return "", ErrSSHDisabled{}
        }
index c0b15be21a0adb10f9b658f1341ffff76cc32235..58bc77132da9973c3ab5612d6981c862e006d058 100644 (file)
@@ -6,6 +6,7 @@ package models
 
 import (
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/timeutil"
 )
 
@@ -74,16 +75,16 @@ func isStaring(e db.Engine, userID, repoID int64) bool {
 }
 
 // GetStargazers returns the users that starred the repo.
-func GetStargazers(repo *Repository, opts db.ListOptions) ([]*User, error) {
+func GetStargazers(repo *Repository, opts db.ListOptions) ([]*user_model.User, error) {
        sess := db.GetEngine(db.DefaultContext).Where("star.repo_id = ?", repo.ID).
                Join("LEFT", "star", "`user`.id = star.uid")
        if opts.Page > 0 {
                sess = db.SetSessionPagination(sess, &opts)
 
-               users := make([]*User, 0, opts.PageSize)
+               users := make([]*user_model.User, 0, opts.PageSize)
                return users, sess.Find(&users)
        }
 
-       users := make([]*User, 0, 8)
+       users := make([]*user_model.User, 0, 8)
        return users, sess.Find(&users)
 }
index cb300c1a87f5ae5acfbdc68b24a57e6bb3716447..9a2a0d5c47211006ecb627216a43923fa444b640 100644 (file)
@@ -45,7 +45,7 @@ type IssueByRepositoryCount struct {
 // GetStatistic returns the database statistics
 func GetStatistic() (stats Statistic) {
        e := db.GetEngine(db.DefaultContext)
-       stats.Counter.User = CountUsers()
+       stats.Counter.User = user_model.CountUsers()
        stats.Counter.Org = CountOrganizations()
        stats.Counter.PublicKey, _ = e.Count(new(PublicKey))
        stats.Counter.Repo = CountRepositories(true)
index 9bff00cd8cc65c339e4e2cb15614c2bbe8eddc53..19999572709004c9755713f04ccf5fc7fdd14225 100644 (file)
@@ -8,6 +8,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/json"
        "code.gitea.io/gitea/modules/migration"
        "code.gitea.io/gitea/modules/secret"
@@ -22,12 +23,12 @@ import (
 // Task represents a task
 type Task struct {
        ID             int64
-       DoerID         int64       `xorm:"index"` // operator
-       Doer           *User       `xorm:"-"`
-       OwnerID        int64       `xorm:"index"` // repo owner id, when creating, the repoID maybe zero
-       Owner          *User       `xorm:"-"`
-       RepoID         int64       `xorm:"index"`
-       Repo           *Repository `xorm:"-"`
+       DoerID         int64            `xorm:"index"` // operator
+       Doer           *user_model.User `xorm:"-"`
+       OwnerID        int64            `xorm:"index"` // repo owner id, when creating, the repoID maybe zero
+       Owner          *user_model.User `xorm:"-"`
+       RepoID         int64            `xorm:"index"`
+       Repo           *Repository      `xorm:"-"`
        Type           structs.TaskType
        Status         structs.TaskStatus `xorm:"index"`
        StartTime      timeutil.TimeStamp
@@ -75,12 +76,12 @@ func (task *Task) LoadDoer() error {
                return nil
        }
 
-       var doer User
+       var doer user_model.User
        has, err := db.GetEngine(db.DefaultContext).ID(task.DoerID).Get(&doer)
        if err != nil {
                return err
        } else if !has {
-               return ErrUserNotExist{
+               return user_model.ErrUserNotExist{
                        UID: task.DoerID,
                }
        }
@@ -95,12 +96,12 @@ func (task *Task) LoadOwner() error {
                return nil
        }
 
-       var owner User
+       var owner user_model.User
        has, err := db.GetEngine(db.DefaultContext).ID(task.OwnerID).Get(&owner)
        if err != nil {
                return err
        } else if !has {
-               return ErrUserNotExist{
+               return user_model.ErrUserNotExist{
                        UID: task.OwnerID,
                }
        }
index 4126606e2405fd5964a6ef5719c5522f3eb83033..9816fcc71305b5ca2c2e692e17b676a8c6b673a0 100644 (file)
@@ -7,491 +7,22 @@ package models
 
 import (
        "context"
-       "crypto/sha256"
-       "crypto/subtle"
-       "encoding/hex"
-       "errors"
        "fmt"
-       "net/url"
-       "os"
-       "path/filepath"
-       "regexp"
-       "strings"
        "time"
-       "unicode/utf8"
 
        _ "image/jpeg" // Needed for jpeg support
 
        "code.gitea.io/gitea/models/db"
-       "code.gitea.io/gitea/models/login"
        "code.gitea.io/gitea/models/unit"
        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/git"
-       "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/modules/timeutil"
-       "code.gitea.io/gitea/modules/util"
 
-       "golang.org/x/crypto/argon2"
-       "golang.org/x/crypto/bcrypt"
-       "golang.org/x/crypto/pbkdf2"
-       "golang.org/x/crypto/scrypt"
        "xorm.io/builder"
-       "xorm.io/xorm"
 )
 
-// UserType defines the user type
-type UserType int
-
-const (
-       // UserTypeIndividual defines an individual user
-       UserTypeIndividual UserType = iota // Historic reason to make it starts at 0.
-
-       // UserTypeOrganization defines an organization
-       UserTypeOrganization
-)
-
-const (
-       algoBcrypt = "bcrypt"
-       algoScrypt = "scrypt"
-       algoArgon2 = "argon2"
-       algoPbkdf2 = "pbkdf2"
-)
-
-// AvailableHashAlgorithms represents the available password hashing algorithms
-var AvailableHashAlgorithms = []string{
-       algoPbkdf2,
-       algoArgon2,
-       algoScrypt,
-       algoBcrypt,
-}
-
-const (
-       // EmailNotificationsEnabled indicates that the user would like to receive all email notifications
-       EmailNotificationsEnabled = "enabled"
-       // EmailNotificationsOnMention indicates that the user would like to be notified via email when mentioned.
-       EmailNotificationsOnMention = "onmention"
-       // EmailNotificationsDisabled indicates that the user would not like to be notified via email.
-       EmailNotificationsDisabled = "disabled"
-)
-
-var (
-       // ErrUserNameIllegal user name contains illegal characters error
-       ErrUserNameIllegal = errors.New("User name contains illegal characters")
-
-       // ErrLoginSourceNotActived login source is not actived error
-       ErrLoginSourceNotActived = errors.New("Login source is not actived")
-
-       // ErrUnsupportedLoginType login source is unknown error
-       ErrUnsupportedLoginType = errors.New("Login source is unknown")
-
-       // Characters prohibited in a user name (anything except A-Za-z0-9_.-)
-       alphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`)
-)
-
-// User represents the object of individual and member of organization.
-type User struct {
-       ID        int64  `xorm:"pk autoincr"`
-       LowerName string `xorm:"UNIQUE NOT NULL"`
-       Name      string `xorm:"UNIQUE NOT NULL"`
-       FullName  string
-       // Email is the primary email address (to be used for communication)
-       Email                        string `xorm:"NOT NULL"`
-       KeepEmailPrivate             bool
-       EmailNotificationsPreference string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'enabled'"`
-       Passwd                       string `xorm:"NOT NULL"`
-       PasswdHashAlgo               string `xorm:"NOT NULL DEFAULT 'argon2'"`
-
-       // MustChangePassword is an attribute that determines if a user
-       // is to change his/her password after registration.
-       MustChangePassword bool `xorm:"NOT NULL DEFAULT false"`
-
-       LoginType   login.Type
-       LoginSource int64 `xorm:"NOT NULL DEFAULT 0"`
-       LoginName   string
-       Type        UserType
-       Location    string
-       Website     string
-       Rands       string `xorm:"VARCHAR(10)"`
-       Salt        string `xorm:"VARCHAR(10)"`
-       Language    string `xorm:"VARCHAR(5)"`
-       Description string
-
-       CreatedUnix   timeutil.TimeStamp `xorm:"INDEX created"`
-       UpdatedUnix   timeutil.TimeStamp `xorm:"INDEX updated"`
-       LastLoginUnix timeutil.TimeStamp `xorm:"INDEX"`
-
-       // Remember visibility choice for convenience, true for private
-       LastRepoVisibility bool
-       // Maximum repository creation limit, -1 means use global default
-       MaxRepoCreation int `xorm:"NOT NULL DEFAULT -1"`
-
-       // IsActive true: primary email is activated, user can access Web UI and Git SSH.
-       // false: an inactive user can only log in Web UI for account operations (ex: activate the account by email), no other access.
-       IsActive bool `xorm:"INDEX"`
-       // the user is a Gitea admin, who can access all repositories and the admin pages.
-       IsAdmin bool
-       // true: the user is only allowed to see organizations/repositories that they has explicit rights to.
-       // (ex: in private Gitea instances user won't be allowed to see even organizations/repositories that are set as public)
-       IsRestricted bool `xorm:"NOT NULL DEFAULT false"`
-
-       AllowGitHook            bool
-       AllowImportLocal        bool // Allow migrate repository by local path
-       AllowCreateOrganization bool `xorm:"DEFAULT true"`
-
-       // true: the user is not allowed to log in Web UI. Git/SSH access could still be allowed (please refer to Git/SSH access related code/documents)
-       ProhibitLogin bool `xorm:"NOT NULL DEFAULT false"`
-
-       // Avatar
-       Avatar          string `xorm:"VARCHAR(2048) NOT NULL"`
-       AvatarEmail     string `xorm:"NOT NULL"`
-       UseCustomAvatar bool
-
-       // Counters
-       NumFollowers int
-       NumFollowing int `xorm:"NOT NULL DEFAULT 0"`
-       NumStars     int
-       NumRepos     int
-
-       // For organization
-       NumTeams                  int
-       NumMembers                int
-       Visibility                structs.VisibleType `xorm:"NOT NULL DEFAULT 0"`
-       RepoAdminChangeTeamAccess bool                `xorm:"NOT NULL DEFAULT false"`
-
-       // Preferences
-       DiffViewStyle       string `xorm:"NOT NULL DEFAULT ''"`
-       Theme               string `xorm:"NOT NULL DEFAULT ''"`
-       KeepActivityPrivate bool   `xorm:"NOT NULL DEFAULT false"`
-}
-
-func init() {
-       db.RegisterModel(new(User))
-}
-
-// SearchOrganizationsOptions options to filter organizations
-type SearchOrganizationsOptions struct {
-       db.ListOptions
-       All bool
-}
-
-// ColorFormat writes a colored string to identify this struct
-func (u *User) ColorFormat(s fmt.State) {
-       log.ColorFprintf(s, "%d:%s",
-               log.NewColoredIDValue(u.ID),
-               log.NewColoredValue(u.Name))
-}
-
-// BeforeUpdate is invoked from XORM before updating this object.
-func (u *User) BeforeUpdate() {
-       if u.MaxRepoCreation < -1 {
-               u.MaxRepoCreation = -1
-       }
-
-       // Organization does not need email
-       u.Email = strings.ToLower(u.Email)
-       if !u.IsOrganization() {
-               if len(u.AvatarEmail) == 0 {
-                       u.AvatarEmail = u.Email
-               }
-       }
-
-       u.LowerName = strings.ToLower(u.Name)
-       u.Location = base.TruncateString(u.Location, 255)
-       u.Website = base.TruncateString(u.Website, 255)
-       u.Description = base.TruncateString(u.Description, 255)
-}
-
-// AfterLoad is invoked from XORM after filling all the fields of this object.
-func (u *User) AfterLoad() {
-       if u.Theme == "" {
-               u.Theme = setting.UI.DefaultTheme
-       }
-}
-
-// SetLastLogin set time to last login
-func (u *User) SetLastLogin() {
-       u.LastLoginUnix = timeutil.TimeStampNow()
-}
-
-// UpdateUserDiffViewStyle updates the users diff view style
-func UpdateUserDiffViewStyle(u *User, style string) error {
-       u.DiffViewStyle = style
-       return UpdateUserCols(db.DefaultContext, u, "diff_view_style")
-}
-
-// UpdateUserTheme updates a users' theme irrespective of the site wide theme
-func UpdateUserTheme(u *User, themeName string) error {
-       u.Theme = themeName
-       return UpdateUserCols(db.DefaultContext, u, "theme")
-}
-
-// GetEmail returns an noreply email, if the user has set to keep his
-// email address private, otherwise the primary email address.
-func (u *User) GetEmail() string {
-       if u.KeepEmailPrivate {
-               return fmt.Sprintf("%s@%s", u.LowerName, setting.Service.NoReplyAddress)
-       }
-       return u.Email
-}
-
-// GetAllUsers returns a slice of all individual users found in DB.
-func GetAllUsers() ([]*User, error) {
-       users := make([]*User, 0)
-       return users, db.GetEngine(db.DefaultContext).OrderBy("id").Where("type = ?", UserTypeIndividual).Find(&users)
-}
-
-// IsLocal returns true if user login type is LoginPlain.
-func (u *User) IsLocal() bool {
-       return u.LoginType <= login.Plain
-}
-
-// IsOAuth2 returns true if user login type is LoginOAuth2.
-func (u *User) IsOAuth2() bool {
-       return u.LoginType == login.OAuth2
-}
-
-// MaxCreationLimit returns the number of repositories a user is allowed to create
-func (u *User) MaxCreationLimit() int {
-       if u.MaxRepoCreation <= -1 {
-               return setting.Repository.MaxCreationLimit
-       }
-       return u.MaxRepoCreation
-}
-
-// CanCreateRepo returns if user login can create a repository
-// NOTE: functions calling this assume a failure due to repository count limit; if new checks are added, those functions should be revised
-func (u *User) CanCreateRepo() bool {
-       if u.IsAdmin {
-               return true
-       }
-       if u.MaxRepoCreation <= -1 {
-               if setting.Repository.MaxCreationLimit <= -1 {
-                       return true
-               }
-               return u.NumRepos < setting.Repository.MaxCreationLimit
-       }
-       return u.NumRepos < u.MaxRepoCreation
-}
-
-// CanCreateOrganization returns true if user can create organisation.
-func (u *User) CanCreateOrganization() bool {
-       return u.IsAdmin || (u.AllowCreateOrganization && !setting.Admin.DisableRegularOrgCreation)
-}
-
-// CanEditGitHook returns true if user can edit Git hooks.
-func (u *User) CanEditGitHook() bool {
-       return !setting.DisableGitHooks && (u.IsAdmin || u.AllowGitHook)
-}
-
-// CanImportLocal returns true if user can migrate repository by local path.
-func (u *User) CanImportLocal() bool {
-       if !setting.ImportLocalPaths || u == nil {
-               return false
-       }
-       return u.IsAdmin || u.AllowImportLocal
-}
-
-// DashboardLink returns the user dashboard page link.
-func (u *User) DashboardLink() string {
-       if u.IsOrganization() {
-               return u.OrganisationLink() + "/dashboard"
-       }
-       return setting.AppSubURL + "/"
-}
-
-// HomeLink returns the user or organization home page link.
-func (u *User) HomeLink() string {
-       return setting.AppSubURL + "/" + url.PathEscape(u.Name)
-}
-
-// HTMLURL returns the user or organization's full link.
-func (u *User) HTMLURL() string {
-       return setting.AppURL + url.PathEscape(u.Name)
-}
-
-// OrganisationLink returns the organization sub page link.
-func (u *User) OrganisationLink() string {
-       return setting.AppSubURL + "/org/" + url.PathEscape(u.Name)
-}
-
-// GenerateEmailActivateCode generates an activate code based on user information and given e-mail.
-func (u *User) GenerateEmailActivateCode(email string) string {
-       code := base.CreateTimeLimitCode(
-               fmt.Sprintf("%d%s%s%s%s", u.ID, email, u.LowerName, u.Passwd, u.Rands),
-               setting.Service.ActiveCodeLives, nil)
-
-       // Add tail hex username
-       code += hex.EncodeToString([]byte(u.LowerName))
-       return code
-}
-
-// GetUserFollowers returns range of user's followers.
-func GetUserFollowers(u *User, listOptions db.ListOptions) ([]*User, error) {
-       sess := db.GetEngine(db.DefaultContext).
-               Where("follow.follow_id=?", u.ID).
-               Join("LEFT", "follow", "`user`.id=follow.user_id")
-
-       if listOptions.Page != 0 {
-               sess = db.SetSessionPagination(sess, &listOptions)
-
-               users := make([]*User, 0, listOptions.PageSize)
-               return users, sess.Find(&users)
-       }
-
-       users := make([]*User, 0, 8)
-       return users, sess.Find(&users)
-}
-
-// GetUserFollowing returns range of user's following.
-func GetUserFollowing(u *User, listOptions db.ListOptions) ([]*User, error) {
-       sess := db.GetEngine(db.DefaultContext).
-               Where("follow.user_id=?", u.ID).
-               Join("LEFT", "follow", "`user`.id=follow.follow_id")
-
-       if listOptions.Page != 0 {
-               sess = db.SetSessionPagination(sess, &listOptions)
-
-               users := make([]*User, 0, listOptions.PageSize)
-               return users, sess.Find(&users)
-       }
-
-       users := make([]*User, 0, 8)
-       return users, sess.Find(&users)
-}
-
-// NewGitSig generates and returns the signature of given user.
-func (u *User) NewGitSig() *git.Signature {
-       return &git.Signature{
-               Name:  u.GitName(),
-               Email: u.GetEmail(),
-               When:  time.Now(),
-       }
-}
-
-func hashPassword(passwd, salt, algo string) string {
-       var tempPasswd []byte
-
-       switch algo {
-       case algoBcrypt:
-               tempPasswd, _ = bcrypt.GenerateFromPassword([]byte(passwd), bcrypt.DefaultCost)
-               return string(tempPasswd)
-       case algoScrypt:
-               tempPasswd, _ = scrypt.Key([]byte(passwd), []byte(salt), 65536, 16, 2, 50)
-       case algoArgon2:
-               tempPasswd = argon2.IDKey([]byte(passwd), []byte(salt), 2, 65536, 8, 50)
-       case algoPbkdf2:
-               fallthrough
-       default:
-               tempPasswd = pbkdf2.Key([]byte(passwd), []byte(salt), 10000, 50, sha256.New)
-       }
-
-       return fmt.Sprintf("%x", tempPasswd)
-}
-
-// SetPassword hashes a password using the algorithm defined in the config value of PASSWORD_HASH_ALGO
-// change passwd, salt and passwd_hash_algo fields
-func (u *User) SetPassword(passwd string) (err error) {
-       if len(passwd) == 0 {
-               u.Passwd = ""
-               u.Salt = ""
-               u.PasswdHashAlgo = ""
-               return nil
-       }
-
-       if u.Salt, err = GetUserSalt(); err != nil {
-               return err
-       }
-       u.PasswdHashAlgo = setting.PasswordHashAlgo
-       u.Passwd = hashPassword(passwd, u.Salt, setting.PasswordHashAlgo)
-
-       return nil
-}
-
-// ValidatePassword checks if given password matches the one belongs to the user.
-func (u *User) ValidatePassword(passwd string) bool {
-       tempHash := hashPassword(passwd, u.Salt, u.PasswdHashAlgo)
-
-       if u.PasswdHashAlgo != algoBcrypt && subtle.ConstantTimeCompare([]byte(u.Passwd), []byte(tempHash)) == 1 {
-               return true
-       }
-       if u.PasswdHashAlgo == algoBcrypt && bcrypt.CompareHashAndPassword([]byte(u.Passwd), []byte(passwd)) == nil {
-               return true
-       }
-       return false
-}
-
-// IsPasswordSet checks if the password is set or left empty
-func (u *User) IsPasswordSet() bool {
-       return len(u.Passwd) != 0
-}
-
-// IsUserVisibleToViewer check if viewer is able to see user profile
-func IsUserVisibleToViewer(u *User, viewer *User) bool {
-       return isUserVisibleToViewer(db.GetEngine(db.DefaultContext), u, viewer)
-}
-
-func isUserVisibleToViewer(e db.Engine, u *User, viewer *User) bool {
-       if viewer != nil && viewer.IsAdmin {
-               return true
-       }
-
-       switch u.Visibility {
-       case structs.VisibleTypePublic:
-               return true
-       case structs.VisibleTypeLimited:
-               if viewer == nil || viewer.IsRestricted {
-                       return false
-               }
-               return true
-       case structs.VisibleTypePrivate:
-               if viewer == nil || viewer.IsRestricted {
-                       return false
-               }
-
-               // If they follow - they see each over
-               follower := user_model.IsFollowing(u.ID, viewer.ID)
-               if follower {
-                       return true
-               }
-
-               // Now we need to check if they in some organization together
-               count, err := e.Table("team_user").
-                       Where(
-                               builder.And(
-                                       builder.Eq{"uid": viewer.ID},
-                                       builder.Or(
-                                               builder.Eq{"org_id": u.ID},
-                                               builder.In("org_id",
-                                                       builder.Select("org_id").
-                                                               From("team_user", "t2").
-                                                               Where(builder.Eq{"uid": u.ID}))))).
-                       Count(new(TeamUser))
-               if err != nil {
-                       return false
-               }
-
-               if count < 0 {
-                       // No common organization
-                       return false
-               }
-
-               // they are in an organization together
-               return true
-       }
-       return false
-}
-
-// IsOrganization returns true if user is actually a organization.
-func (u *User) IsOrganization() bool {
-       return u.Type == UserTypeOrganization
-}
-
 // GetOrganizationCount returns count of membership of organization of the user.
-func GetOrganizationCount(ctx context.Context, u *User) (int64, error) {
+func GetOrganizationCount(ctx context.Context, u *user_model.User) (int64, error) {
        return db.GetEngine(ctx).
                Where("uid=?", u.ID).
                Count(new(OrgUser))
@@ -499,7 +30,7 @@ func GetOrganizationCount(ctx context.Context, u *User) (int64, error) {
 
 // GetRepositoryIDs returns repositories IDs where user owned and has unittypes
 // Caller shall check that units is not globally disabled
-func (u *User) GetRepositoryIDs(units ...unit.Type) ([]int64, error) {
+func GetRepositoryIDs(u *user_model.User, units ...unit.Type) ([]int64, error) {
        var ids []int64
 
        sess := db.GetEngine(db.DefaultContext).Table("repository").Cols("repository.id")
@@ -513,540 +44,91 @@ func (u *User) GetRepositoryIDs(units ...unit.Type) ([]int64, error) {
 }
 
 // GetActiveRepositoryIDs returns non-archived repositories IDs where user owned and has unittypes
-// Caller shall check that units is not globally disabled
-func (u *User) GetActiveRepositoryIDs(units ...unit.Type) ([]int64, error) {
-       var ids []int64
-
-       sess := db.GetEngine(db.DefaultContext).Table("repository").Cols("repository.id")
-
-       if len(units) > 0 {
-               sess = sess.Join("INNER", "repo_unit", "repository.id = repo_unit.repo_id")
-               sess = sess.In("repo_unit.type", units)
-       }
-
-       sess.Where(builder.Eq{"is_archived": false})
-
-       return ids, sess.Where("owner_id = ?", u.ID).GroupBy("repository.id").Find(&ids)
-}
-
-// GetOrgRepositoryIDs returns repositories IDs where user's team owned and has unittypes
-// Caller shall check that units is not globally disabled
-func (u *User) GetOrgRepositoryIDs(units ...unit.Type) ([]int64, error) {
-       var ids []int64
-
-       if err := db.GetEngine(db.DefaultContext).Table("repository").
-               Cols("repository.id").
-               Join("INNER", "team_user", "repository.owner_id = team_user.org_id").
-               Join("INNER", "team_repo", "(? != ? and repository.is_private != ?) OR (team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id)", true, u.IsRestricted, true).
-               Where("team_user.uid = ?", u.ID).
-               GroupBy("repository.id").Find(&ids); err != nil {
-               return nil, err
-       }
-
-       if len(units) > 0 {
-               return FilterOutRepoIdsWithoutUnitAccess(u, ids, units...)
-       }
-
-       return ids, nil
-}
-
-// GetActiveOrgRepositoryIDs returns non-archived repositories IDs where user's team owned and has unittypes
-// Caller shall check that units is not globally disabled
-func (u *User) GetActiveOrgRepositoryIDs(units ...unit.Type) ([]int64, error) {
-       var ids []int64
-
-       if err := db.GetEngine(db.DefaultContext).Table("repository").
-               Cols("repository.id").
-               Join("INNER", "team_user", "repository.owner_id = team_user.org_id").
-               Join("INNER", "team_repo", "(? != ? and repository.is_private != ?) OR (team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id)", true, u.IsRestricted, true).
-               Where("team_user.uid = ?", u.ID).
-               Where(builder.Eq{"is_archived": false}).
-               GroupBy("repository.id").Find(&ids); err != nil {
-               return nil, err
-       }
-
-       if len(units) > 0 {
-               return FilterOutRepoIdsWithoutUnitAccess(u, ids, units...)
-       }
-
-       return ids, nil
-}
-
-// GetAccessRepoIDs returns all repositories IDs where user's or user is a team member organizations
-// Caller shall check that units is not globally disabled
-func (u *User) GetAccessRepoIDs(units ...unit.Type) ([]int64, error) {
-       ids, err := u.GetRepositoryIDs(units...)
-       if err != nil {
-               return nil, err
-       }
-       ids2, err := u.GetOrgRepositoryIDs(units...)
-       if err != nil {
-               return nil, err
-       }
-       return append(ids, ids2...), nil
-}
-
-// GetActiveAccessRepoIDs returns all non-archived repositories IDs where user's or user is a team member organizations
-// Caller shall check that units is not globally disabled
-func (u *User) GetActiveAccessRepoIDs(units ...unit.Type) ([]int64, error) {
-       ids, err := u.GetActiveRepositoryIDs(units...)
-       if err != nil {
-               return nil, err
-       }
-       ids2, err := u.GetActiveOrgRepositoryIDs(units...)
-       if err != nil {
-               return nil, err
-       }
-       return append(ids, ids2...), nil
-}
-
-// DisplayName returns full name if it's not empty,
-// returns username otherwise.
-func (u *User) DisplayName() string {
-       trimmed := strings.TrimSpace(u.FullName)
-       if len(trimmed) > 0 {
-               return trimmed
-       }
-       return u.Name
-}
-
-// GetDisplayName returns full name if it's not empty and DEFAULT_SHOW_FULL_NAME is set,
-// returns username otherwise.
-func (u *User) GetDisplayName() string {
-       if setting.UI.DefaultShowFullName {
-               trimmed := strings.TrimSpace(u.FullName)
-               if len(trimmed) > 0 {
-                       return trimmed
-               }
-       }
-       return u.Name
-}
-
-func gitSafeName(name string) string {
-       return strings.TrimSpace(strings.NewReplacer("\n", "", "<", "", ">", "").Replace(name))
-}
-
-// GitName returns a git safe name
-func (u *User) GitName() string {
-       gitName := gitSafeName(u.FullName)
-       if len(gitName) > 0 {
-               return gitName
-       }
-       // Although u.Name should be safe if created in our system
-       // LDAP users may have bad names
-       gitName = gitSafeName(u.Name)
-       if len(gitName) > 0 {
-               return gitName
-       }
-       // Totally pathological name so it's got to be:
-       return fmt.Sprintf("user-%d", u.ID)
-}
-
-// ShortName ellipses username to length
-func (u *User) ShortName(length int) string {
-       return base.EllipsisString(u.Name, length)
-}
-
-// IsMailable checks if a user is eligible
-// to receive emails.
-func (u *User) IsMailable() bool {
-       return u.IsActive
-}
-
-// EmailNotifications returns the User's email notification preference
-func (u *User) EmailNotifications() string {
-       return u.EmailNotificationsPreference
-}
-
-// SetEmailNotifications sets the user's email notification preference
-func SetEmailNotifications(u *User, set string) error {
-       u.EmailNotificationsPreference = set
-       if err := UpdateUserCols(db.DefaultContext, u, "email_notifications_preference"); err != nil {
-               log.Error("SetEmailNotifications: %v", err)
-               return err
-       }
-       return nil
-}
-
-func isUserExist(e db.Engine, uid int64, name string) (bool, error) {
-       if len(name) == 0 {
-               return false, nil
-       }
-       return e.
-               Where("id!=?", uid).
-               Get(&User{LowerName: strings.ToLower(name)})
-}
-
-// IsUserExist checks if given user name exist,
-// the user name should be noncased unique.
-// If uid is presented, then check will rule out that one,
-// it is used when update a user name in settings page.
-func IsUserExist(uid int64, name string) (bool, error) {
-       return isUserExist(db.GetEngine(db.DefaultContext), uid, name)
-}
-
-// GetUserSalt returns a random user salt token.
-func GetUserSalt() (string, error) {
-       return util.RandomString(10)
-}
-
-// NewGhostUser creates and returns a fake user for someone has deleted his/her account.
-func NewGhostUser() *User {
-       return &User{
-               ID:        -1,
-               Name:      "Ghost",
-               LowerName: "ghost",
-       }
-}
-
-// NewReplaceUser creates and returns a fake user for external user
-func NewReplaceUser(name string) *User {
-       return &User{
-               ID:        -1,
-               Name:      name,
-               LowerName: strings.ToLower(name),
-       }
-}
-
-// IsGhost check if user is fake user for a deleted account
-func (u *User) IsGhost() bool {
-       if u == nil {
-               return false
-       }
-       return u.ID == -1 && u.Name == "Ghost"
-}
-
-var (
-       reservedUsernames = []string{
-               ".",
-               "..",
-               ".well-known",
-               "admin",
-               "api",
-               "assets",
-               "attachments",
-               "avatars",
-               "captcha",
-               "commits",
-               "debug",
-               "error",
-               "explore",
-               "favicon.ico",
-               "ghost",
-               "help",
-               "install",
-               "issues",
-               "less",
-               "login",
-               "manifest.json",
-               "metrics",
-               "milestones",
-               "new",
-               "notifications",
-               "org",
-               "plugins",
-               "pulls",
-               "raw",
-               "repo",
-               "robots.txt",
-               "search",
-               "serviceworker.js",
-               "stars",
-               "template",
-               "user",
-       }
-
-       reservedUserPatterns = []string{"*.keys", "*.gpg", "*.rss", "*.atom"}
-)
-
-// isUsableName checks if name is reserved or pattern of name is not allowed
-// based on given reserved names and patterns.
-// Names are exact match, patterns can be prefix or suffix match with placeholder '*'.
-func isUsableName(names, patterns []string, name string) error {
-       name = strings.TrimSpace(strings.ToLower(name))
-       if utf8.RuneCountInString(name) == 0 {
-               return ErrNameEmpty
-       }
-
-       for i := range names {
-               if name == names[i] {
-                       return ErrNameReserved{name}
-               }
-       }
-
-       for _, pat := range patterns {
-               if pat[0] == '*' && strings.HasSuffix(name, pat[1:]) ||
-                       (pat[len(pat)-1] == '*' && strings.HasPrefix(name, pat[:len(pat)-1])) {
-                       return ErrNamePatternNotAllowed{pat}
-               }
-       }
-
-       return nil
-}
-
-// IsUsableUsername returns an error when a username is reserved
-func IsUsableUsername(name string) error {
-       // Validate username make sure it satisfies requirement.
-       if alphaDashDotPattern.MatchString(name) {
-               // Note: usually this error is normally caught up earlier in the UI
-               return ErrNameCharsNotAllowed{Name: name}
-       }
-       return isUsableName(reservedUsernames, reservedUserPatterns, name)
-}
-
-// CreateUserOverwriteOptions are an optional options who overwrite system defaults on user creation
-type CreateUserOverwriteOptions struct {
-       Visibility structs.VisibleType
-}
-
-// CreateUser creates record of a new user.
-func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err error) {
-       if err = IsUsableUsername(u.Name); err != nil {
-               return err
-       }
-
-       // set system defaults
-       u.KeepEmailPrivate = setting.Service.DefaultKeepEmailPrivate
-       u.Visibility = setting.Service.DefaultUserVisibilityMode
-       u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization && !setting.Admin.DisableRegularOrgCreation
-       u.EmailNotificationsPreference = setting.Admin.DefaultEmailNotification
-       u.MaxRepoCreation = -1
-       u.Theme = setting.UI.DefaultTheme
-
-       // overwrite defaults if set
-       if len(overwriteDefault) != 0 && overwriteDefault[0] != nil {
-               u.Visibility = overwriteDefault[0].Visibility
-       }
-
-       ctx, committer, err := db.TxContext()
-       if err != nil {
-               return err
-       }
-       defer committer.Close()
-
-       sess := db.GetEngine(ctx)
-
-       // validate data
-       if err := validateUser(u); err != nil {
-               return err
-       }
-
-       isExist, err := isUserExist(sess, 0, u.Name)
-       if err != nil {
-               return err
-       } else if isExist {
-               return ErrUserAlreadyExist{u.Name}
-       }
-
-       isExist, err = user_model.IsEmailUsed(ctx, u.Email)
-       if err != nil {
-               return err
-       } else if isExist {
-               return user_model.ErrEmailAlreadyUsed{
-                       Email: u.Email,
-               }
-       }
-
-       // prepare for database
-
-       u.LowerName = strings.ToLower(u.Name)
-       u.AvatarEmail = u.Email
-       if u.Rands, err = GetUserSalt(); err != nil {
-               return err
-       }
-       if err = u.SetPassword(u.Passwd); err != nil {
-               return err
-       }
-
-       // save changes to database
-
-       if err = user_model.DeleteUserRedirect(ctx, u.Name); err != nil {
-               return err
-       }
-
-       if err = db.Insert(ctx, u); err != nil {
-               return err
-       }
-
-       // insert email address
-       if err := db.Insert(ctx, &user_model.EmailAddress{
-               UID:         u.ID,
-               Email:       u.Email,
-               LowerEmail:  strings.ToLower(u.Email),
-               IsActivated: u.IsActive,
-               IsPrimary:   true,
-       }); err != nil {
-               return err
-       }
-
-       return committer.Commit()
-}
-
-func countUsers(e db.Engine) int64 {
-       count, _ := e.
-               Where("type=0").
-               Count(new(User))
-       return count
-}
-
-// CountUsers returns number of users.
-func CountUsers() int64 {
-       return countUsers(db.GetEngine(db.DefaultContext))
-}
-
-// get user by verify code
-func getVerifyUser(code string) (user *User) {
-       if len(code) <= base.TimeLimitCodeLength {
-               return nil
-       }
-
-       // use tail hex username query user
-       hexStr := code[base.TimeLimitCodeLength:]
-       if b, err := hex.DecodeString(hexStr); err == nil {
-               if user, err = GetUserByName(string(b)); user != nil {
-                       return user
-               }
-               log.Error("user.getVerifyUser: %v", err)
-       }
-
-       return nil
-}
-
-// VerifyUserActiveCode verifies active code when active account
-func VerifyUserActiveCode(code string) (user *User) {
-       minutes := setting.Service.ActiveCodeLives
-
-       if user = getVerifyUser(code); user != nil {
-               // time limit code
-               prefix := code[:base.TimeLimitCodeLength]
-               data := fmt.Sprintf("%d%s%s%s%s", user.ID, user.Email, user.LowerName, user.Passwd, user.Rands)
-
-               if base.VerifyTimeLimitCode(data, minutes, prefix) {
-                       return user
-               }
-       }
-       return nil
-}
-
-// ChangeUserName changes all corresponding setting from old user name to new one.
-func ChangeUserName(u *User, newUserName string) (err error) {
-       oldUserName := u.Name
-       if err = IsUsableUsername(newUserName); err != nil {
-               return err
-       }
-
-       ctx, committer, err := db.TxContext()
-       if err != nil {
-               return err
-       }
-       defer committer.Close()
-       sess := db.GetEngine(ctx)
-
-       isExist, err := isUserExist(sess, 0, newUserName)
-       if err != nil {
-               return err
-       } else if isExist {
-               return ErrUserAlreadyExist{newUserName}
-       }
-
-       if _, err = sess.Exec("UPDATE `repository` SET owner_name=? WHERE owner_name=?", newUserName, oldUserName); err != nil {
-               return fmt.Errorf("Change repo owner name: %v", err)
-       }
+// Caller shall check that units is not globally disabled
+func GetActiveRepositoryIDs(u *user_model.User, units ...unit.Type) ([]int64, error) {
+       var ids []int64
 
-       // Do not fail if directory does not exist
-       if err = util.Rename(UserPath(oldUserName), UserPath(newUserName)); err != nil && !os.IsNotExist(err) {
-               return fmt.Errorf("Rename user directory: %v", err)
-       }
+       sess := db.GetEngine(db.DefaultContext).Table("repository").Cols("repository.id")
 
-       if err = user_model.NewUserRedirect(ctx, u.ID, oldUserName, newUserName); err != nil {
-               return err
+       if len(units) > 0 {
+               sess = sess.Join("INNER", "repo_unit", "repository.id = repo_unit.repo_id")
+               sess = sess.In("repo_unit.type", units)
        }
 
-       if err = committer.Commit(); err != nil {
-               if err2 := util.Rename(UserPath(newUserName), UserPath(oldUserName)); err2 != nil && !os.IsNotExist(err2) {
-                       log.Critical("Unable to rollback directory change during failed username change from: %s to: %s. DB Error: %v. Filesystem Error: %v", oldUserName, newUserName, err, err2)
-                       return fmt.Errorf("failed to rollback directory change during failed username change from: %s to: %s. DB Error: %w. Filesystem Error: %v", oldUserName, newUserName, err, err2)
-               }
-               return err
-       }
+       sess.Where(builder.Eq{"is_archived": false})
 
-       return nil
+       return ids, sess.Where("owner_id = ?", u.ID).GroupBy("repository.id").Find(&ids)
 }
 
-// checkDupEmail checks whether there are the same email with the user
-func checkDupEmail(e db.Engine, u *User) error {
-       u.Email = strings.ToLower(u.Email)
-       has, err := e.
-               Where("id!=?", u.ID).
-               And("type=?", u.Type).
-               And("email=?", u.Email).
-               Get(new(User))
-       if err != nil {
-               return err
-       } else if has {
-               return user_model.ErrEmailAlreadyUsed{
-                       Email: u.Email,
-               }
-       }
-       return nil
-}
+// GetOrgRepositoryIDs returns repositories IDs where user's team owned and has unittypes
+// Caller shall check that units is not globally disabled
+func GetOrgRepositoryIDs(u *user_model.User, units ...unit.Type) ([]int64, error) {
+       var ids []int64
 
-// validateUser check if user is valid to insert / update into database
-func validateUser(u *User) error {
-       if !setting.Service.AllowedUserVisibilityModesSlice.IsAllowedVisibility(u.Visibility) && !u.IsOrganization() {
-               return fmt.Errorf("visibility Mode not allowed: %s", u.Visibility.String())
+       if err := db.GetEngine(db.DefaultContext).Table("repository").
+               Cols("repository.id").
+               Join("INNER", "team_user", "repository.owner_id = team_user.org_id").
+               Join("INNER", "team_repo", "(? != ? and repository.is_private != ?) OR (team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id)", true, u.IsRestricted, true).
+               Where("team_user.uid = ?", u.ID).
+               GroupBy("repository.id").Find(&ids); err != nil {
+               return nil, err
        }
 
-       u.Email = strings.ToLower(u.Email)
-       return user_model.ValidateEmail(u.Email)
-}
-
-func updateUser(e db.Engine, u *User) error {
-       if err := validateUser(u); err != nil {
-               return err
+       if len(units) > 0 {
+               return FilterOutRepoIdsWithoutUnitAccess(u, ids, units...)
        }
 
-       _, err := e.ID(u.ID).AllCols().Update(u)
-       return err
+       return ids, nil
 }
 
-// UpdateUser updates user's information.
-func UpdateUser(u *User) error {
-       return updateUser(db.GetEngine(db.DefaultContext), u)
-}
+// GetActiveOrgRepositoryIDs returns non-archived repositories IDs where user's team owned and has unittypes
+// Caller shall check that units is not globally disabled
+func GetActiveOrgRepositoryIDs(u *user_model.User, units ...unit.Type) ([]int64, error) {
+       var ids []int64
 
-// UpdateUserCols update user according special columns
-func UpdateUserCols(ctx context.Context, u *User, cols ...string) error {
-       return updateUserCols(db.GetEngine(ctx), u, cols...)
-}
+       if err := db.GetEngine(db.DefaultContext).Table("repository").
+               Cols("repository.id").
+               Join("INNER", "team_user", "repository.owner_id = team_user.org_id").
+               Join("INNER", "team_repo", "(? != ? and repository.is_private != ?) OR (team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id)", true, u.IsRestricted, true).
+               Where("team_user.uid = ?", u.ID).
+               Where(builder.Eq{"is_archived": false}).
+               GroupBy("repository.id").Find(&ids); err != nil {
+               return nil, err
+       }
 
-func updateUserCols(e db.Engine, u *User, cols ...string) error {
-       if err := validateUser(u); err != nil {
-               return err
+       if len(units) > 0 {
+               return FilterOutRepoIdsWithoutUnitAccess(u, ids, units...)
        }
 
-       _, err := e.ID(u.ID).Cols(cols...).Update(u)
-       return err
+       return ids, nil
 }
 
-// UpdateUserSetting updates user's settings.
-func UpdateUserSetting(u *User) (err error) {
-       ctx, committer, err := db.TxContext()
+// GetAccessRepoIDs returns all repositories IDs where user's or user is a team member organizations
+// Caller shall check that units is not globally disabled
+func GetAccessRepoIDs(u *user_model.User, units ...unit.Type) ([]int64, error) {
+       ids, err := GetRepositoryIDs(u, units...)
+       if err != nil {
+               return nil, err
+       }
+       ids2, err := GetOrgRepositoryIDs(u, units...)
        if err != nil {
-               return err
+               return nil, err
        }
-       defer committer.Close()
-       sess := db.GetEngine(ctx)
+       return append(ids, ids2...), nil
+}
 
-       if !u.IsOrganization() {
-               if err = checkDupEmail(sess, u); err != nil {
-                       return err
-               }
+// GetActiveAccessRepoIDs returns all non-archived repositories IDs where user's or user is a team member organizations
+// Caller shall check that units is not globally disabled
+func GetActiveAccessRepoIDs(u *user_model.User, units ...unit.Type) ([]int64, error) {
+       ids, err := GetActiveRepositoryIDs(u, units...)
+       if err != nil {
+               return nil, err
        }
-       if err = updateUser(sess, u); err != nil {
-               return err
+       ids2, err := GetActiveOrgRepositoryIDs(u, units...)
+       if err != nil {
+               return nil, err
        }
-       return committer.Commit()
+       return append(ids, ids2...), nil
 }
 
 // deleteBeans deletes all given beans, beans should contain delete conditions.
@@ -1060,7 +142,7 @@ func deleteBeans(e db.Engine, beans ...interface{}) (err error) {
 }
 
 // DeleteUser deletes models associated to an user.
-func DeleteUser(ctx context.Context, u *User) (err error) {
+func DeleteUser(ctx context.Context, u *user_model.User) (err error) {
        e := db.GetEngine(ctx)
 
        // ***** START: Watch *****
@@ -1089,7 +171,7 @@ func DeleteUser(ctx context.Context, u *User) (err error) {
        if err = e.Table("follow").Cols("follow.follow_id").
                Where("follow.user_id = ?", u.ID).Find(&followeeIDs); err != nil {
                return fmt.Errorf("get all followees: %v", err)
-       } else if _, err = e.Decr("num_followers").In("id", followeeIDs).Update(new(User)); err != nil {
+       } else if _, err = e.Decr("num_followers").In("id", followeeIDs).Update(new(user_model.User)); err != nil {
                return fmt.Errorf("decrease user num_followers: %v", err)
        }
 
@@ -1097,7 +179,7 @@ func DeleteUser(ctx context.Context, u *User) (err error) {
        if err = e.Table("follow").Cols("follow.user_id").
                Where("follow.follow_id = ?", u.ID).Find(&followerIDs); err != nil {
                return fmt.Errorf("get all followers: %v", err)
-       } else if _, err = e.Decr("num_following").In("id", followerIDs).Update(new(User)); err != nil {
+       } else if _, err = e.Decr("num_following").In("id", followerIDs).Update(new(user_model.User)); err != nil {
                return fmt.Errorf("decrease user num_following: %v", err)
        }
        // ***** END: Follow *****
@@ -1183,386 +265,13 @@ func DeleteUser(ctx context.Context, u *User) (err error) {
        }
        // ***** END: ExternalLoginUser *****
 
-       if _, err = e.ID(u.ID).Delete(new(User)); err != nil {
+       if _, err = e.ID(u.ID).Delete(new(user_model.User)); err != nil {
                return fmt.Errorf("Delete: %v", err)
        }
 
        return nil
 }
 
-// GetInactiveUsers gets all inactive users
-func GetInactiveUsers(ctx context.Context, olderThan time.Duration) ([]*User, error) {
-       var cond builder.Cond = builder.Eq{"is_active": false}
-
-       if olderThan > 0 {
-               cond = cond.And(builder.Lt{"created_unix": time.Now().Add(-olderThan).Unix()})
-       }
-
-       users := make([]*User, 0, 10)
-       return users, db.GetEngine(ctx).
-               Where(cond).
-               Find(&users)
-}
-
-// UserPath returns the path absolute path of user repositories.
-func UserPath(userName string) string {
-       return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
-}
-
-func getUserByID(e db.Engine, id int64) (*User, error) {
-       u := new(User)
-       has, err := e.ID(id).Get(u)
-       if err != nil {
-               return nil, err
-       } else if !has {
-               return nil, ErrUserNotExist{id, "", 0}
-       }
-       return u, nil
-}
-
-// GetUserByID returns the user object by given ID if exists.
-func GetUserByID(id int64) (*User, error) {
-       return GetUserByIDCtx(db.DefaultContext, id)
-}
-
-// GetUserByIDCtx returns the user object by given ID if exists.
-func GetUserByIDCtx(ctx context.Context, id int64) (*User, error) {
-       return getUserByID(db.GetEngine(ctx), id)
-}
-
-// GetUserByName returns user by given name.
-func GetUserByName(name string) (*User, error) {
-       return getUserByName(db.GetEngine(db.DefaultContext), name)
-}
-
-func getUserByName(e db.Engine, name string) (*User, error) {
-       if len(name) == 0 {
-               return nil, ErrUserNotExist{0, name, 0}
-       }
-       u := &User{LowerName: strings.ToLower(name)}
-       has, err := e.Get(u)
-       if err != nil {
-               return nil, err
-       } else if !has {
-               return nil, ErrUserNotExist{0, name, 0}
-       }
-       return u, nil
-}
-
-// GetUserEmailsByNames returns a list of e-mails corresponds to names of users
-// that have their email notifications set to enabled or onmention.
-func GetUserEmailsByNames(names []string) []string {
-       return getUserEmailsByNames(db.GetEngine(db.DefaultContext), names)
-}
-
-func getUserEmailsByNames(e db.Engine, names []string) []string {
-       mails := make([]string, 0, len(names))
-       for _, name := range names {
-               u, err := getUserByName(e, name)
-               if err != nil {
-                       continue
-               }
-               if u.IsMailable() && u.EmailNotifications() != EmailNotificationsDisabled {
-                       mails = append(mails, u.Email)
-               }
-       }
-       return mails
-}
-
-// GetMaileableUsersByIDs gets users from ids, but only if they can receive mails
-func GetMaileableUsersByIDs(ids []int64, isMention bool) ([]*User, error) {
-       if len(ids) == 0 {
-               return nil, nil
-       }
-       ous := make([]*User, 0, len(ids))
-
-       if isMention {
-               return ous, db.GetEngine(db.DefaultContext).In("id", ids).
-                       Where("`type` = ?", UserTypeIndividual).
-                       And("`prohibit_login` = ?", false).
-                       And("`is_active` = ?", true).
-                       And("`email_notifications_preference` IN ( ?, ?)", EmailNotificationsEnabled, EmailNotificationsOnMention).
-                       Find(&ous)
-       }
-
-       return ous, db.GetEngine(db.DefaultContext).In("id", ids).
-               Where("`type` = ?", UserTypeIndividual).
-               And("`prohibit_login` = ?", false).
-               And("`is_active` = ?", true).
-               And("`email_notifications_preference` = ?", EmailNotificationsEnabled).
-               Find(&ous)
-}
-
-// GetUserNamesByIDs returns usernames for all resolved users from a list of Ids.
-func GetUserNamesByIDs(ids []int64) ([]string, error) {
-       unames := make([]string, 0, len(ids))
-       err := db.GetEngine(db.DefaultContext).In("id", ids).
-               Table("user").
-               Asc("name").
-               Cols("name").
-               Find(&unames)
-       return unames, err
-}
-
-// GetUsersByIDs returns all resolved users from a list of Ids.
-func GetUsersByIDs(ids []int64) (UserList, error) {
-       ous := make([]*User, 0, len(ids))
-       if len(ids) == 0 {
-               return ous, nil
-       }
-       err := db.GetEngine(db.DefaultContext).In("id", ids).
-               Asc("name").
-               Find(&ous)
-       return ous, err
-}
-
-// GetUserIDsByNames returns a slice of ids corresponds to names.
-func GetUserIDsByNames(names []string, ignoreNonExistent bool) ([]int64, error) {
-       ids := make([]int64, 0, len(names))
-       for _, name := range names {
-               u, err := GetUserByName(name)
-               if err != nil {
-                       if ignoreNonExistent {
-                               continue
-                       } else {
-                               return nil, err
-                       }
-               }
-               ids = append(ids, u.ID)
-       }
-       return ids, nil
-}
-
-// GetUsersBySource returns a list of Users for a login source
-func GetUsersBySource(s *login.Source) ([]*User, error) {
-       var users []*User
-       err := db.GetEngine(db.DefaultContext).Where("login_type = ? AND login_source = ?", s.Type, s.ID).Find(&users)
-       return users, err
-}
-
-// UserCommit represents a commit with validation of user.
-type UserCommit struct {
-       User *User
-       *git.Commit
-}
-
-// ValidateCommitWithEmail check if author's e-mail of commit is corresponding to a user.
-func ValidateCommitWithEmail(c *git.Commit) *User {
-       if c.Author == nil {
-               return nil
-       }
-       u, err := GetUserByEmail(c.Author.Email)
-       if err != nil {
-               return nil
-       }
-       return u
-}
-
-// ValidateCommitsWithEmails checks if authors' e-mails of commits are corresponding to users.
-func ValidateCommitsWithEmails(oldCommits []*git.Commit) []*UserCommit {
-       var (
-               emails     = make(map[string]*User)
-               newCommits = make([]*UserCommit, 0, len(oldCommits))
-       )
-       for _, c := range oldCommits {
-               var u *User
-               if c.Author != nil {
-                       if v, ok := emails[c.Author.Email]; !ok {
-                               u, _ = GetUserByEmail(c.Author.Email)
-                               emails[c.Author.Email] = u
-                       } else {
-                               u = v
-                       }
-               }
-
-               newCommits = append(newCommits, &UserCommit{
-                       User:   u,
-                       Commit: c,
-               })
-       }
-       return newCommits
-}
-
-// GetUserByEmail returns the user object by given e-mail if exists.
-func GetUserByEmail(email string) (*User, error) {
-       return GetUserByEmailContext(db.DefaultContext, email)
-}
-
-// GetUserByEmailContext returns the user object by given e-mail if exists with db context
-func GetUserByEmailContext(ctx context.Context, email string) (*User, error) {
-       if len(email) == 0 {
-               return nil, ErrUserNotExist{0, email, 0}
-       }
-
-       email = strings.ToLower(email)
-       // First try to find the user by primary email
-       user := &User{Email: email}
-       has, err := db.GetEngine(ctx).Get(user)
-       if err != nil {
-               return nil, err
-       }
-       if has {
-               return user, nil
-       }
-
-       // Otherwise, check in alternative list for activated email addresses
-       emailAddress := &user_model.EmailAddress{Email: email, IsActivated: true}
-       has, err = db.GetEngine(ctx).Get(emailAddress)
-       if err != nil {
-               return nil, err
-       }
-       if has {
-               return GetUserByIDCtx(ctx, emailAddress.UID)
-       }
-
-       // Finally, if email address is the protected email address:
-       if strings.HasSuffix(email, fmt.Sprintf("@%s", setting.Service.NoReplyAddress)) {
-               username := strings.TrimSuffix(email, fmt.Sprintf("@%s", setting.Service.NoReplyAddress))
-               user := &User{}
-               has, err := db.GetEngine(ctx).Where("lower_name=?", username).Get(user)
-               if err != nil {
-                       return nil, err
-               }
-               if has {
-                       return user, nil
-               }
-       }
-
-       return nil, ErrUserNotExist{0, email, 0}
-}
-
-// GetUser checks if a user already exists
-func GetUser(user *User) (bool, error) {
-       return db.GetEngine(db.DefaultContext).Get(user)
-}
-
-// SearchUserOptions contains the options for searching
-type SearchUserOptions struct {
-       db.ListOptions
-       Keyword       string
-       Type          UserType
-       UID           int64
-       OrderBy       SearchOrderBy
-       Visible       []structs.VisibleType
-       Actor         *User // The user doing the search
-       SearchByEmail bool  // Search by email as well as username/full name
-
-       IsActive           util.OptionalBool
-       IsAdmin            util.OptionalBool
-       IsRestricted       util.OptionalBool
-       IsTwoFactorEnabled util.OptionalBool
-       IsProhibitLogin    util.OptionalBool
-}
-
-func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
-       var cond builder.Cond = builder.Eq{"type": opts.Type}
-       if len(opts.Keyword) > 0 {
-               lowerKeyword := strings.ToLower(opts.Keyword)
-               keywordCond := builder.Or(
-                       builder.Like{"lower_name", lowerKeyword},
-                       builder.Like{"LOWER(full_name)", lowerKeyword},
-               )
-               if opts.SearchByEmail {
-                       keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword})
-               }
-
-               cond = cond.And(keywordCond)
-       }
-
-       // If visibility filtered
-       if len(opts.Visible) > 0 {
-               cond = cond.And(builder.In("visibility", opts.Visible))
-       }
-
-       if opts.Actor != nil {
-               var exprCond builder.Cond = builder.Expr("org_user.org_id = `user`.id")
-
-               // If Admin - they see all users!
-               if !opts.Actor.IsAdmin {
-                       // Force visibility for privacy
-                       var accessCond builder.Cond
-                       if !opts.Actor.IsRestricted {
-                               accessCond = builder.Or(
-                                       builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.Actor.ID}, builder.Eq{"visibility": structs.VisibleTypePrivate}))),
-                                       builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))
-                       } else {
-                               // restricted users only see orgs they are a member of
-                               accessCond = builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.Actor.ID})))
-                       }
-                       // Don't forget about self
-                       accessCond = accessCond.Or(builder.Eq{"id": opts.Actor.ID})
-                       cond = cond.And(accessCond)
-               }
-
-       } else {
-               // Force visibility for privacy
-               // Not logged in - only public users
-               cond = cond.And(builder.In("visibility", structs.VisibleTypePublic))
-       }
-
-       if opts.UID > 0 {
-               cond = cond.And(builder.Eq{"id": opts.UID})
-       }
-
-       if !opts.IsActive.IsNone() {
-               cond = cond.And(builder.Eq{"is_active": opts.IsActive.IsTrue()})
-       }
-
-       if !opts.IsAdmin.IsNone() {
-               cond = cond.And(builder.Eq{"is_admin": opts.IsAdmin.IsTrue()})
-       }
-
-       if !opts.IsRestricted.IsNone() {
-               cond = cond.And(builder.Eq{"is_restricted": opts.IsRestricted.IsTrue()})
-       }
-
-       if !opts.IsProhibitLogin.IsNone() {
-               cond = cond.And(builder.Eq{"prohibit_login": opts.IsProhibitLogin.IsTrue()})
-       }
-
-       e := db.GetEngine(db.DefaultContext)
-       if opts.IsTwoFactorEnabled.IsNone() {
-               return e.Where(cond)
-       }
-
-       // 2fa filter uses LEFT JOIN to check whether a user has a 2fa record
-       // TODO: bad performance here, maybe there will be a column "is_2fa_enabled" in the future
-       if opts.IsTwoFactorEnabled.IsTrue() {
-               cond = cond.And(builder.Expr("two_factor.uid IS NOT NULL"))
-       } else {
-               cond = cond.And(builder.Expr("two_factor.uid IS NULL"))
-       }
-
-       return e.Join("LEFT OUTER", "two_factor", "two_factor.uid = `user`.id").
-               Where(cond)
-}
-
-// SearchUsers takes options i.e. keyword and part of user name to search,
-// it returns results in given range and number of total results.
-func SearchUsers(opts *SearchUserOptions) (users []*User, _ int64, _ error) {
-       sessCount := opts.toSearchQueryBase()
-       defer sessCount.Close()
-       count, err := sessCount.Count(new(User))
-       if err != nil {
-               return nil, 0, fmt.Errorf("Count: %v", err)
-       }
-
-       if len(opts.OrderBy) == 0 {
-               opts.OrderBy = SearchOrderByAlphabetically
-       }
-
-       sessQuery := opts.toSearchQueryBase().OrderBy(opts.OrderBy.String())
-       defer sessQuery.Close()
-       if opts.Page != 0 {
-               sessQuery = db.SetSessionPagination(sessQuery, opts)
-       }
-
-       // the sql may contain JOIN, so we must only select User related columns
-       sessQuery = sessQuery.Select("`user`.*")
-       users = make([]*User, 0, opts.PageSize)
-       return users, count, sessQuery.Find(&users)
-}
-
 // GetStarredRepos returns the repos starred by a particular user
 func GetStarredRepos(userID int64, private bool, listOptions db.ListOptions) ([]*Repository, error) {
        sess := db.GetEngine(db.DefaultContext).Where("star.uid=?", userID).
@@ -1604,63 +313,58 @@ func GetWatchedRepos(userID int64, private bool, listOptions db.ListOptions) ([]
        return repos, total, err
 }
 
-// IterateUser iterate users
-func IterateUser(f func(user *User) error) error {
-       var start int
-       batchSize := setting.Database.IterateBufferSize
-       for {
-               users := make([]*User, 0, batchSize)
-               if err := db.GetEngine(db.DefaultContext).Limit(batchSize, start).Find(&users); err != nil {
-                       return err
-               }
-               if len(users) == 0 {
-                       return nil
-               }
-               start += len(users)
-
-               for _, user := range users {
-                       if err := f(user); err != nil {
-                               return err
-                       }
-               }
-       }
+// IsUserVisibleToViewer check if viewer is able to see user profile
+func IsUserVisibleToViewer(u *user_model.User, viewer *user_model.User) bool {
+       return isUserVisibleToViewer(db.GetEngine(db.DefaultContext), u, viewer)
 }
 
-// GetUserByOpenID returns the user object by given OpenID if exists.
-func GetUserByOpenID(uri string) (*User, error) {
-       if len(uri) == 0 {
-               return nil, ErrUserNotExist{0, uri, 0}
+func isUserVisibleToViewer(e db.Engine, u *user_model.User, viewer *user_model.User) bool {
+       if viewer != nil && viewer.IsAdmin {
+               return true
        }
 
-       uri, err := openid.Normalize(uri)
-       if err != nil {
-               return nil, err
-       }
+       switch u.Visibility {
+       case structs.VisibleTypePublic:
+               return true
+       case structs.VisibleTypeLimited:
+               if viewer == nil || viewer.IsRestricted {
+                       return false
+               }
+               return true
+       case structs.VisibleTypePrivate:
+               if viewer == nil || viewer.IsRestricted {
+                       return false
+               }
 
-       log.Trace("Normalized OpenID URI: " + uri)
+               // If they follow - they see each over
+               follower := user_model.IsFollowing(u.ID, viewer.ID)
+               if follower {
+                       return true
+               }
 
-       // Otherwise, check in openid table
-       oid := &user_model.UserOpenID{}
-       has, err := db.GetEngine(db.DefaultContext).Where("uri=?", uri).Get(oid)
-       if err != nil {
-               return nil, err
-       }
-       if has {
-               return GetUserByID(oid.UID)
-       }
+               // Now we need to check if they in some organization together
+               count, err := e.Table("team_user").
+                       Where(
+                               builder.And(
+                                       builder.Eq{"uid": viewer.ID},
+                                       builder.Or(
+                                               builder.Eq{"org_id": u.ID},
+                                               builder.In("org_id",
+                                                       builder.Select("org_id").
+                                                               From("team_user", "t2").
+                                                               Where(builder.Eq{"uid": u.ID}))))).
+                       Count(new(TeamUser))
+               if err != nil {
+                       return false
+               }
 
-       return nil, ErrUserNotExist{0, uri, 0}
-}
+               if count < 0 {
+                       // No common organization
+                       return false
+               }
 
-// GetAdminUser returns the first administrator
-func GetAdminUser() (*User, error) {
-       var admin User
-       has, err := db.GetEngine(db.DefaultContext).Where("is_admin=?", true).Get(&admin)
-       if err != nil {
-               return nil, err
-       } else if !has {
-               return nil, ErrUserNotExist{}
+               // they are in an organization together
+               return true
        }
-
-       return &admin, nil
+       return false
 }
diff --git a/models/user/avatar.go b/models/user/avatar.go
new file mode 100644 (file)
index 0000000..c881642
--- /dev/null
@@ -0,0 +1,113 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package user
+
+import (
+       "context"
+       "crypto/md5"
+       "fmt"
+       "image/png"
+       "io"
+       "strings"
+
+       "code.gitea.io/gitea/models/avatars"
+       "code.gitea.io/gitea/models/db"
+       "code.gitea.io/gitea/modules/avatar"
+       "code.gitea.io/gitea/modules/log"
+       "code.gitea.io/gitea/modules/setting"
+       "code.gitea.io/gitea/modules/storage"
+)
+
+// CustomAvatarRelativePath returns user custom avatar relative path.
+func (u *User) CustomAvatarRelativePath() string {
+       return u.Avatar
+}
+
+// GenerateRandomAvatar generates a random avatar for user.
+func GenerateRandomAvatar(u *User) error {
+       return GenerateRandomAvatarCtx(db.DefaultContext, u)
+}
+
+// GenerateRandomAvatarCtx generates a random avatar for user.
+func GenerateRandomAvatarCtx(ctx context.Context, u *User) error {
+       seed := u.Email
+       if len(seed) == 0 {
+               seed = u.Name
+       }
+
+       img, err := avatar.RandomImage([]byte(seed))
+       if err != nil {
+               return fmt.Errorf("RandomImage: %v", err)
+       }
+
+       u.Avatar = avatars.HashEmail(seed)
+
+       // Don't share the images so that we can delete them easily
+       if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {
+               if err := png.Encode(w, img); err != nil {
+                       log.Error("Encode: %v", err)
+               }
+               return err
+       }); err != nil {
+               return fmt.Errorf("Failed to create dir %s: %v", u.CustomAvatarRelativePath(), err)
+       }
+
+       if _, err := db.GetEngine(ctx).ID(u.ID).Cols("avatar").Update(u); err != nil {
+               return err
+       }
+
+       log.Info("New random avatar created: %d", u.ID)
+       return nil
+}
+
+// AvatarLinkWithSize returns a link to the user's avatar with size. size <= 0 means default size
+func (u *User) AvatarLinkWithSize(size int) string {
+       if u.ID == -1 {
+               // ghost user
+               return avatars.DefaultAvatarLink()
+       }
+
+       useLocalAvatar := false
+       autoGenerateAvatar := false
+
+       switch {
+       case u.UseCustomAvatar:
+               useLocalAvatar = true
+       case setting.DisableGravatar, setting.OfflineMode:
+               useLocalAvatar = true
+               autoGenerateAvatar = true
+       }
+
+       if useLocalAvatar {
+               if u.Avatar == "" && autoGenerateAvatar {
+                       if err := GenerateRandomAvatar(u); err != nil {
+                               log.Error("GenerateRandomAvatar: %v", err)
+                       }
+               }
+               if u.Avatar == "" {
+                       return avatars.DefaultAvatarLink()
+               }
+               return avatars.GenerateUserAvatarImageLink(u.Avatar, size)
+       }
+       return avatars.GenerateEmailAvatarFastLink(u.AvatarEmail, size)
+}
+
+// AvatarLink returns the full avatar link with http host
+func (u *User) AvatarLink() string {
+       link := u.AvatarLinkWithSize(0)
+       if !strings.HasPrefix(link, "//") && !strings.Contains(link, "://") {
+               return setting.AppURL + strings.TrimPrefix(link, setting.AppSubURL+"/")
+       }
+       return link
+}
+
+// IsUploadAvatarChanged returns true if the current user's avatar would be changed with the provided data
+func (u *User) IsUploadAvatarChanged(data []byte) bool {
+       if !u.UseCustomAvatar || len(u.Avatar) == 0 {
+               return true
+       }
+       avatarID := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
+       return u.Avatar != avatarID
+}
diff --git a/models/user/error.go b/models/user/error.go
new file mode 100644 (file)
index 0000000..25e0d8e
--- /dev/null
@@ -0,0 +1,80 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package user
+
+import (
+       "fmt"
+)
+
+//  ____ ___
+// |    |   \______ ___________
+// |    |   /  ___// __ \_  __ \
+// |    |  /\___ \\  ___/|  | \/
+// |______//____  >\___  >__|
+//              \/     \/
+
+// ErrUserAlreadyExist represents a "user already exists" error.
+type ErrUserAlreadyExist struct {
+       Name string
+}
+
+// IsErrUserAlreadyExist checks if an error is a ErrUserAlreadyExists.
+func IsErrUserAlreadyExist(err error) bool {
+       _, ok := err.(ErrUserAlreadyExist)
+       return ok
+}
+
+func (err ErrUserAlreadyExist) Error() string {
+       return fmt.Sprintf("user already exists [name: %s]", err.Name)
+}
+
+// ErrUserNotExist represents a "UserNotExist" kind of error.
+type ErrUserNotExist struct {
+       UID   int64
+       Name  string
+       KeyID int64
+}
+
+// IsErrUserNotExist checks if an error is a ErrUserNotExist.
+func IsErrUserNotExist(err error) bool {
+       _, ok := err.(ErrUserNotExist)
+       return ok
+}
+
+func (err ErrUserNotExist) Error() string {
+       return fmt.Sprintf("user does not exist [uid: %d, name: %s, keyid: %d]", err.UID, err.Name, err.KeyID)
+}
+
+// ErrUserProhibitLogin represents a "ErrUserProhibitLogin" kind of error.
+type ErrUserProhibitLogin struct {
+       UID  int64
+       Name string
+}
+
+// IsErrUserProhibitLogin checks if an error is a ErrUserProhibitLogin
+func IsErrUserProhibitLogin(err error) bool {
+       _, ok := err.(ErrUserProhibitLogin)
+       return ok
+}
+
+func (err ErrUserProhibitLogin) Error() string {
+       return fmt.Sprintf("user is not allowed login [uid: %d, name: %s]", err.UID, err.Name)
+}
+
+// ErrUserInactive represents a "ErrUserInactive" kind of error.
+type ErrUserInactive struct {
+       UID  int64
+       Name string
+}
+
+// IsErrUserInactive checks if an error is a ErrUserInactive
+func IsErrUserInactive(err error) bool {
+       _, ok := err.(ErrUserInactive)
+       return ok
+}
+
+func (err ErrUserInactive) Error() string {
+       return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
+}
index 925af0e8b2907d5d6fb1e1f144c1cde1b6bdb6c8..55e5f9341cd97601056e4375edce3a66e99bc476 100644 (file)
@@ -17,5 +17,8 @@ func TestMain(m *testing.M) {
                "user_redirect.yml",
                "follow.yml",
                "user_open_id.yml",
+               "two_factor.yml",
+               "oauth2_application.yml",
+               "user.yml",
        )
 }
diff --git a/models/user/search.go b/models/user/search.go
new file mode 100644 (file)
index 0000000..5c37bb9
--- /dev/null
@@ -0,0 +1,167 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package user
+
+import (
+       "fmt"
+       "strings"
+
+       "code.gitea.io/gitea/models/db"
+       "code.gitea.io/gitea/modules/setting"
+       "code.gitea.io/gitea/modules/structs"
+       "code.gitea.io/gitea/modules/util"
+
+       "xorm.io/builder"
+       "xorm.io/xorm"
+)
+
+// SearchUserOptions contains the options for searching
+type SearchUserOptions struct {
+       db.ListOptions
+       Keyword       string
+       Type          UserType
+       UID           int64
+       OrderBy       db.SearchOrderBy
+       Visible       []structs.VisibleType
+       Actor         *User // The user doing the search
+       SearchByEmail bool  // Search by email as well as username/full name
+
+       IsActive           util.OptionalBool
+       IsAdmin            util.OptionalBool
+       IsRestricted       util.OptionalBool
+       IsTwoFactorEnabled util.OptionalBool
+       IsProhibitLogin    util.OptionalBool
+}
+
+func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
+       var cond builder.Cond = builder.Eq{"type": opts.Type}
+       if len(opts.Keyword) > 0 {
+               lowerKeyword := strings.ToLower(opts.Keyword)
+               keywordCond := builder.Or(
+                       builder.Like{"lower_name", lowerKeyword},
+                       builder.Like{"LOWER(full_name)", lowerKeyword},
+               )
+               if opts.SearchByEmail {
+                       keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword})
+               }
+
+               cond = cond.And(keywordCond)
+       }
+
+       // If visibility filtered
+       if len(opts.Visible) > 0 {
+               cond = cond.And(builder.In("visibility", opts.Visible))
+       }
+
+       if opts.Actor != nil {
+               var exprCond builder.Cond = builder.Expr("org_user.org_id = `user`.id")
+
+               // If Admin - they see all users!
+               if !opts.Actor.IsAdmin {
+                       // Force visibility for privacy
+                       var accessCond builder.Cond
+                       if !opts.Actor.IsRestricted {
+                               accessCond = builder.Or(
+                                       builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.Actor.ID}, builder.Eq{"visibility": structs.VisibleTypePrivate}))),
+                                       builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))
+                       } else {
+                               // restricted users only see orgs they are a member of
+                               accessCond = builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.Actor.ID})))
+                       }
+                       // Don't forget about self
+                       accessCond = accessCond.Or(builder.Eq{"id": opts.Actor.ID})
+                       cond = cond.And(accessCond)
+               }
+
+       } else {
+               // Force visibility for privacy
+               // Not logged in - only public users
+               cond = cond.And(builder.In("visibility", structs.VisibleTypePublic))
+       }
+
+       if opts.UID > 0 {
+               cond = cond.And(builder.Eq{"id": opts.UID})
+       }
+
+       if !opts.IsActive.IsNone() {
+               cond = cond.And(builder.Eq{"is_active": opts.IsActive.IsTrue()})
+       }
+
+       if !opts.IsAdmin.IsNone() {
+               cond = cond.And(builder.Eq{"is_admin": opts.IsAdmin.IsTrue()})
+       }
+
+       if !opts.IsRestricted.IsNone() {
+               cond = cond.And(builder.Eq{"is_restricted": opts.IsRestricted.IsTrue()})
+       }
+
+       if !opts.IsProhibitLogin.IsNone() {
+               cond = cond.And(builder.Eq{"prohibit_login": opts.IsProhibitLogin.IsTrue()})
+       }
+
+       e := db.GetEngine(db.DefaultContext)
+       if opts.IsTwoFactorEnabled.IsNone() {
+               return e.Where(cond)
+       }
+
+       // 2fa filter uses LEFT JOIN to check whether a user has a 2fa record
+       // TODO: bad performance here, maybe there will be a column "is_2fa_enabled" in the future
+       if opts.IsTwoFactorEnabled.IsTrue() {
+               cond = cond.And(builder.Expr("two_factor.uid IS NOT NULL"))
+       } else {
+               cond = cond.And(builder.Expr("two_factor.uid IS NULL"))
+       }
+
+       return e.Join("LEFT OUTER", "two_factor", "two_factor.uid = `user`.id").
+               Where(cond)
+}
+
+// SearchUsers takes options i.e. keyword and part of user name to search,
+// it returns results in given range and number of total results.
+func SearchUsers(opts *SearchUserOptions) (users []*User, _ int64, _ error) {
+       sessCount := opts.toSearchQueryBase()
+       defer sessCount.Close()
+       count, err := sessCount.Count(new(User))
+       if err != nil {
+               return nil, 0, fmt.Errorf("Count: %v", err)
+       }
+
+       if len(opts.OrderBy) == 0 {
+               opts.OrderBy = db.SearchOrderByAlphabetically
+       }
+
+       sessQuery := opts.toSearchQueryBase().OrderBy(opts.OrderBy.String())
+       defer sessQuery.Close()
+       if opts.Page != 0 {
+               sessQuery = db.SetSessionPagination(sessQuery, opts)
+       }
+
+       // the sql may contain JOIN, so we must only select User related columns
+       sessQuery = sessQuery.Select("`user`.*")
+       users = make([]*User, 0, opts.PageSize)
+       return users, count, sessQuery.Find(&users)
+}
+
+// IterateUser iterate users
+func IterateUser(f func(user *User) error) error {
+       var start int
+       batchSize := setting.Database.IterateBufferSize
+       for {
+               users := make([]*User, 0, batchSize)
+               if err := db.GetEngine(db.DefaultContext).Limit(batchSize, start).Find(&users); err != nil {
+                       return err
+               }
+               if len(users) == 0 {
+                       return nil
+               }
+               start += len(users)
+
+               for _, user := range users {
+                       if err := f(user); err != nil {
+                               return err
+                       }
+               }
+       }
+}
diff --git a/models/user/user.go b/models/user/user.go
new file mode 100644 (file)
index 0000000..f8ccee0
--- /dev/null
@@ -0,0 +1,1125 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package user
+
+import (
+       "context"
+       "crypto/sha256"
+       "crypto/subtle"
+       "encoding/hex"
+       "errors"
+       "fmt"
+       "net/url"
+       "os"
+       "path/filepath"
+       "strings"
+       "time"
+
+       _ "image/jpeg" // Needed for jpeg support
+
+       "code.gitea.io/gitea/models/db"
+       "code.gitea.io/gitea/models/login"
+       "code.gitea.io/gitea/modules/auth/openid"
+       "code.gitea.io/gitea/modules/base"
+       "code.gitea.io/gitea/modules/git"
+       "code.gitea.io/gitea/modules/log"
+       "code.gitea.io/gitea/modules/setting"
+       "code.gitea.io/gitea/modules/structs"
+       "code.gitea.io/gitea/modules/timeutil"
+       "code.gitea.io/gitea/modules/util"
+
+       "golang.org/x/crypto/argon2"
+       "golang.org/x/crypto/bcrypt"
+       "golang.org/x/crypto/pbkdf2"
+       "golang.org/x/crypto/scrypt"
+       "xorm.io/builder"
+)
+
+// UserType defines the user type
+type UserType int //revive:disable-line:exported
+
+const (
+       // UserTypeIndividual defines an individual user
+       UserTypeIndividual UserType = iota // Historic reason to make it starts at 0.
+
+       // UserTypeOrganization defines an organization
+       UserTypeOrganization
+)
+
+const (
+       algoBcrypt = "bcrypt"
+       algoScrypt = "scrypt"
+       algoArgon2 = "argon2"
+       algoPbkdf2 = "pbkdf2"
+)
+
+// AvailableHashAlgorithms represents the available password hashing algorithms
+var AvailableHashAlgorithms = []string{
+       algoPbkdf2,
+       algoArgon2,
+       algoScrypt,
+       algoBcrypt,
+}
+
+const (
+       // EmailNotificationsEnabled indicates that the user would like to receive all email notifications
+       EmailNotificationsEnabled = "enabled"
+       // EmailNotificationsOnMention indicates that the user would like to be notified via email when mentioned.
+       EmailNotificationsOnMention = "onmention"
+       // EmailNotificationsDisabled indicates that the user would not like to be notified via email.
+       EmailNotificationsDisabled = "disabled"
+)
+
+var (
+       // ErrUserNameIllegal user name contains illegal characters error
+       ErrUserNameIllegal = errors.New("User name contains illegal characters")
+)
+
+// User represents the object of individual and member of organization.
+type User struct {
+       ID        int64  `xorm:"pk autoincr"`
+       LowerName string `xorm:"UNIQUE NOT NULL"`
+       Name      string `xorm:"UNIQUE NOT NULL"`
+       FullName  string
+       // Email is the primary email address (to be used for communication)
+       Email                        string `xorm:"NOT NULL"`
+       KeepEmailPrivate             bool
+       EmailNotificationsPreference string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'enabled'"`
+       Passwd                       string `xorm:"NOT NULL"`
+       PasswdHashAlgo               string `xorm:"NOT NULL DEFAULT 'argon2'"`
+
+       // MustChangePassword is an attribute that determines if a user
+       // is to change his/her password after registration.
+       MustChangePassword bool `xorm:"NOT NULL DEFAULT false"`
+
+       LoginType   login.Type
+       LoginSource int64 `xorm:"NOT NULL DEFAULT 0"`
+       LoginName   string
+       Type        UserType
+       Location    string
+       Website     string
+       Rands       string `xorm:"VARCHAR(10)"`
+       Salt        string `xorm:"VARCHAR(10)"`
+       Language    string `xorm:"VARCHAR(5)"`
+       Description string
+
+       CreatedUnix   timeutil.TimeStamp `xorm:"INDEX created"`
+       UpdatedUnix   timeutil.TimeStamp `xorm:"INDEX updated"`
+       LastLoginUnix timeutil.TimeStamp `xorm:"INDEX"`
+
+       // Remember visibility choice for convenience, true for private
+       LastRepoVisibility bool
+       // Maximum repository creation limit, -1 means use global default
+       MaxRepoCreation int `xorm:"NOT NULL DEFAULT -1"`
+
+       // IsActive true: primary email is activated, user can access Web UI and Git SSH.
+       // false: an inactive user can only log in Web UI for account operations (ex: activate the account by email), no other access.
+       IsActive bool `xorm:"INDEX"`
+       // the user is a Gitea admin, who can access all repositories and the admin pages.
+       IsAdmin bool
+       // true: the user is only allowed to see organizations/repositories that they has explicit rights to.
+       // (ex: in private Gitea instances user won't be allowed to see even organizations/repositories that are set as public)
+       IsRestricted bool `xorm:"NOT NULL DEFAULT false"`
+
+       AllowGitHook            bool
+       AllowImportLocal        bool // Allow migrate repository by local path
+       AllowCreateOrganization bool `xorm:"DEFAULT true"`
+
+       // true: the user is not allowed to log in Web UI. Git/SSH access could still be allowed (please refer to Git/SSH access related code/documents)
+       ProhibitLogin bool `xorm:"NOT NULL DEFAULT false"`
+
+       // Avatar
+       Avatar          string `xorm:"VARCHAR(2048) NOT NULL"`
+       AvatarEmail     string `xorm:"NOT NULL"`
+       UseCustomAvatar bool
+
+       // Counters
+       NumFollowers int
+       NumFollowing int `xorm:"NOT NULL DEFAULT 0"`
+       NumStars     int
+       NumRepos     int
+
+       // For organization
+       NumTeams                  int
+       NumMembers                int
+       Visibility                structs.VisibleType `xorm:"NOT NULL DEFAULT 0"`
+       RepoAdminChangeTeamAccess bool                `xorm:"NOT NULL DEFAULT false"`
+
+       // Preferences
+       DiffViewStyle       string `xorm:"NOT NULL DEFAULT ''"`
+       Theme               string `xorm:"NOT NULL DEFAULT ''"`
+       KeepActivityPrivate bool   `xorm:"NOT NULL DEFAULT false"`
+}
+
+func init() {
+       db.RegisterModel(new(User))
+}
+
+// SearchOrganizationsOptions options to filter organizations
+type SearchOrganizationsOptions struct {
+       db.ListOptions
+       All bool
+}
+
+// ColorFormat writes a colored string to identify this struct
+func (u *User) ColorFormat(s fmt.State) {
+       log.ColorFprintf(s, "%d:%s",
+               log.NewColoredIDValue(u.ID),
+               log.NewColoredValue(u.Name))
+}
+
+// BeforeUpdate is invoked from XORM before updating this object.
+func (u *User) BeforeUpdate() {
+       if u.MaxRepoCreation < -1 {
+               u.MaxRepoCreation = -1
+       }
+
+       // Organization does not need email
+       u.Email = strings.ToLower(u.Email)
+       if !u.IsOrganization() {
+               if len(u.AvatarEmail) == 0 {
+                       u.AvatarEmail = u.Email
+               }
+       }
+
+       u.LowerName = strings.ToLower(u.Name)
+       u.Location = base.TruncateString(u.Location, 255)
+       u.Website = base.TruncateString(u.Website, 255)
+       u.Description = base.TruncateString(u.Description, 255)
+}
+
+// AfterLoad is invoked from XORM after filling all the fields of this object.
+func (u *User) AfterLoad() {
+       if u.Theme == "" {
+               u.Theme = setting.UI.DefaultTheme
+       }
+}
+
+// SetLastLogin set time to last login
+func (u *User) SetLastLogin() {
+       u.LastLoginUnix = timeutil.TimeStampNow()
+}
+
+// UpdateUserDiffViewStyle updates the users diff view style
+func UpdateUserDiffViewStyle(u *User, style string) error {
+       u.DiffViewStyle = style
+       return UpdateUserCols(db.DefaultContext, u, "diff_view_style")
+}
+
+// UpdateUserTheme updates a users' theme irrespective of the site wide theme
+func UpdateUserTheme(u *User, themeName string) error {
+       u.Theme = themeName
+       return UpdateUserCols(db.DefaultContext, u, "theme")
+}
+
+// GetEmail returns an noreply email, if the user has set to keep his
+// email address private, otherwise the primary email address.
+func (u *User) GetEmail() string {
+       if u.KeepEmailPrivate {
+               return fmt.Sprintf("%s@%s", u.LowerName, setting.Service.NoReplyAddress)
+       }
+       return u.Email
+}
+
+// GetAllUsers returns a slice of all individual users found in DB.
+func GetAllUsers() ([]*User, error) {
+       users := make([]*User, 0)
+       return users, db.GetEngine(db.DefaultContext).OrderBy("id").Where("type = ?", UserTypeIndividual).Find(&users)
+}
+
+// IsLocal returns true if user login type is LoginPlain.
+func (u *User) IsLocal() bool {
+       return u.LoginType <= login.Plain
+}
+
+// IsOAuth2 returns true if user login type is LoginOAuth2.
+func (u *User) IsOAuth2() bool {
+       return u.LoginType == login.OAuth2
+}
+
+// MaxCreationLimit returns the number of repositories a user is allowed to create
+func (u *User) MaxCreationLimit() int {
+       if u.MaxRepoCreation <= -1 {
+               return setting.Repository.MaxCreationLimit
+       }
+       return u.MaxRepoCreation
+}
+
+// CanCreateRepo returns if user login can create a repository
+// NOTE: functions calling this assume a failure due to repository count limit; if new checks are added, those functions should be revised
+func (u *User) CanCreateRepo() bool {
+       if u.IsAdmin {
+               return true
+       }
+       if u.MaxRepoCreation <= -1 {
+               if setting.Repository.MaxCreationLimit <= -1 {
+                       return true
+               }
+               return u.NumRepos < setting.Repository.MaxCreationLimit
+       }
+       return u.NumRepos < u.MaxRepoCreation
+}
+
+// CanCreateOrganization returns true if user can create organisation.
+func (u *User) CanCreateOrganization() bool {
+       return u.IsAdmin || (u.AllowCreateOrganization && !setting.Admin.DisableRegularOrgCreation)
+}
+
+// CanEditGitHook returns true if user can edit Git hooks.
+func (u *User) CanEditGitHook() bool {
+       return !setting.DisableGitHooks && (u.IsAdmin || u.AllowGitHook)
+}
+
+// CanImportLocal returns true if user can migrate repository by local path.
+func (u *User) CanImportLocal() bool {
+       if !setting.ImportLocalPaths || u == nil {
+               return false
+       }
+       return u.IsAdmin || u.AllowImportLocal
+}
+
+// DashboardLink returns the user dashboard page link.
+func (u *User) DashboardLink() string {
+       if u.IsOrganization() {
+               return u.OrganisationLink() + "/dashboard"
+       }
+       return setting.AppSubURL + "/"
+}
+
+// HomeLink returns the user or organization home page link.
+func (u *User) HomeLink() string {
+       return setting.AppSubURL + "/" + url.PathEscape(u.Name)
+}
+
+// HTMLURL returns the user or organization's full link.
+func (u *User) HTMLURL() string {
+       return setting.AppURL + url.PathEscape(u.Name)
+}
+
+// OrganisationLink returns the organization sub page link.
+func (u *User) OrganisationLink() string {
+       return setting.AppSubURL + "/org/" + url.PathEscape(u.Name)
+}
+
+// GenerateEmailActivateCode generates an activate code based on user information and given e-mail.
+func (u *User) GenerateEmailActivateCode(email string) string {
+       code := base.CreateTimeLimitCode(
+               fmt.Sprintf("%d%s%s%s%s", u.ID, email, u.LowerName, u.Passwd, u.Rands),
+               setting.Service.ActiveCodeLives, nil)
+
+       // Add tail hex username
+       code += hex.EncodeToString([]byte(u.LowerName))
+       return code
+}
+
+// GetUserFollowers returns range of user's followers.
+func GetUserFollowers(u *User, listOptions db.ListOptions) ([]*User, error) {
+       sess := db.GetEngine(db.DefaultContext).
+               Where("follow.follow_id=?", u.ID).
+               Join("LEFT", "follow", "`user`.id=follow.user_id")
+
+       if listOptions.Page != 0 {
+               sess = db.SetSessionPagination(sess, &listOptions)
+
+               users := make([]*User, 0, listOptions.PageSize)
+               return users, sess.Find(&users)
+       }
+
+       users := make([]*User, 0, 8)
+       return users, sess.Find(&users)
+}
+
+// GetUserFollowing returns range of user's following.
+func GetUserFollowing(u *User, listOptions db.ListOptions) ([]*User, error) {
+       sess := db.GetEngine(db.DefaultContext).
+               Where("follow.user_id=?", u.ID).
+               Join("LEFT", "follow", "`user`.id=follow.follow_id")
+
+       if listOptions.Page != 0 {
+               sess = db.SetSessionPagination(sess, &listOptions)
+
+               users := make([]*User, 0, listOptions.PageSize)
+               return users, sess.Find(&users)
+       }
+
+       users := make([]*User, 0, 8)
+       return users, sess.Find(&users)
+}
+
+// NewGitSig generates and returns the signature of given user.
+func (u *User) NewGitSig() *git.Signature {
+       return &git.Signature{
+               Name:  u.GitName(),
+               Email: u.GetEmail(),
+               When:  time.Now(),
+       }
+}
+
+func hashPassword(passwd, salt, algo string) string {
+       var tempPasswd []byte
+
+       switch algo {
+       case algoBcrypt:
+               tempPasswd, _ = bcrypt.GenerateFromPassword([]byte(passwd), bcrypt.DefaultCost)
+               return string(tempPasswd)
+       case algoScrypt:
+               tempPasswd, _ = scrypt.Key([]byte(passwd), []byte(salt), 65536, 16, 2, 50)
+       case algoArgon2:
+               tempPasswd = argon2.IDKey([]byte(passwd), []byte(salt), 2, 65536, 8, 50)
+       case algoPbkdf2:
+               fallthrough
+       default:
+               tempPasswd = pbkdf2.Key([]byte(passwd), []byte(salt), 10000, 50, sha256.New)
+       }
+
+       return fmt.Sprintf("%x", tempPasswd)
+}
+
+// SetPassword hashes a password using the algorithm defined in the config value of PASSWORD_HASH_ALGO
+// change passwd, salt and passwd_hash_algo fields
+func (u *User) SetPassword(passwd string) (err error) {
+       if len(passwd) == 0 {
+               u.Passwd = ""
+               u.Salt = ""
+               u.PasswdHashAlgo = ""
+               return nil
+       }
+
+       if u.Salt, err = GetUserSalt(); err != nil {
+               return err
+       }
+       u.PasswdHashAlgo = setting.PasswordHashAlgo
+       u.Passwd = hashPassword(passwd, u.Salt, setting.PasswordHashAlgo)
+
+       return nil
+}
+
+// ValidatePassword checks if given password matches the one belongs to the user.
+func (u *User) ValidatePassword(passwd string) bool {
+       tempHash := hashPassword(passwd, u.Salt, u.PasswdHashAlgo)
+
+       if u.PasswdHashAlgo != algoBcrypt && subtle.ConstantTimeCompare([]byte(u.Passwd), []byte(tempHash)) == 1 {
+               return true
+       }
+       if u.PasswdHashAlgo == algoBcrypt && bcrypt.CompareHashAndPassword([]byte(u.Passwd), []byte(passwd)) == nil {
+               return true
+       }
+       return false
+}
+
+// IsPasswordSet checks if the password is set or left empty
+func (u *User) IsPasswordSet() bool {
+       return len(u.Passwd) != 0
+}
+
+// IsOrganization returns true if user is actually a organization.
+func (u *User) IsOrganization() bool {
+       return u.Type == UserTypeOrganization
+}
+
+// DisplayName returns full name if it's not empty,
+// returns username otherwise.
+func (u *User) DisplayName() string {
+       trimmed := strings.TrimSpace(u.FullName)
+       if len(trimmed) > 0 {
+               return trimmed
+       }
+       return u.Name
+}
+
+// GetDisplayName returns full name if it's not empty and DEFAULT_SHOW_FULL_NAME is set,
+// returns username otherwise.
+func (u *User) GetDisplayName() string {
+       if setting.UI.DefaultShowFullName {
+               trimmed := strings.TrimSpace(u.FullName)
+               if len(trimmed) > 0 {
+                       return trimmed
+               }
+       }
+       return u.Name
+}
+
+func gitSafeName(name string) string {
+       return strings.TrimSpace(strings.NewReplacer("\n", "", "<", "", ">", "").Replace(name))
+}
+
+// GitName returns a git safe name
+func (u *User) GitName() string {
+       gitName := gitSafeName(u.FullName)
+       if len(gitName) > 0 {
+               return gitName
+       }
+       // Although u.Name should be safe if created in our system
+       // LDAP users may have bad names
+       gitName = gitSafeName(u.Name)
+       if len(gitName) > 0 {
+               return gitName
+       }
+       // Totally pathological name so it's got to be:
+       return fmt.Sprintf("user-%d", u.ID)
+}
+
+// ShortName ellipses username to length
+func (u *User) ShortName(length int) string {
+       return base.EllipsisString(u.Name, length)
+}
+
+// IsMailable checks if a user is eligible
+// to receive emails.
+func (u *User) IsMailable() bool {
+       return u.IsActive
+}
+
+// EmailNotifications returns the User's email notification preference
+func (u *User) EmailNotifications() string {
+       return u.EmailNotificationsPreference
+}
+
+// SetEmailNotifications sets the user's email notification preference
+func SetEmailNotifications(u *User, set string) error {
+       u.EmailNotificationsPreference = set
+       if err := UpdateUserCols(db.DefaultContext, u, "email_notifications_preference"); err != nil {
+               log.Error("SetEmailNotifications: %v", err)
+               return err
+       }
+       return nil
+}
+
+func isUserExist(e db.Engine, uid int64, name string) (bool, error) {
+       if len(name) == 0 {
+               return false, nil
+       }
+       return e.
+               Where("id!=?", uid).
+               Get(&User{LowerName: strings.ToLower(name)})
+}
+
+// IsUserExist checks if given user name exist,
+// the user name should be noncased unique.
+// If uid is presented, then check will rule out that one,
+// it is used when update a user name in settings page.
+func IsUserExist(uid int64, name string) (bool, error) {
+       return isUserExist(db.GetEngine(db.DefaultContext), uid, name)
+}
+
+// GetUserSalt returns a random user salt token.
+func GetUserSalt() (string, error) {
+       return util.RandomString(10)
+}
+
+// NewGhostUser creates and returns a fake user for someone has deleted his/her account.
+func NewGhostUser() *User {
+       return &User{
+               ID:        -1,
+               Name:      "Ghost",
+               LowerName: "ghost",
+       }
+}
+
+// NewReplaceUser creates and returns a fake user for external user
+func NewReplaceUser(name string) *User {
+       return &User{
+               ID:        -1,
+               Name:      name,
+               LowerName: strings.ToLower(name),
+       }
+}
+
+// IsGhost check if user is fake user for a deleted account
+func (u *User) IsGhost() bool {
+       if u == nil {
+               return false
+       }
+       return u.ID == -1 && u.Name == "Ghost"
+}
+
+var (
+       reservedUsernames = []string{
+               ".",
+               "..",
+               ".well-known",
+               "admin",
+               "api",
+               "assets",
+               "attachments",
+               "avatars",
+               "captcha",
+               "commits",
+               "debug",
+               "error",
+               "explore",
+               "favicon.ico",
+               "ghost",
+               "help",
+               "install",
+               "issues",
+               "less",
+               "login",
+               "manifest.json",
+               "metrics",
+               "milestones",
+               "new",
+               "notifications",
+               "org",
+               "plugins",
+               "pulls",
+               "raw",
+               "repo",
+               "robots.txt",
+               "search",
+               "serviceworker.js",
+               "stars",
+               "template",
+               "user",
+       }
+
+       reservedUserPatterns = []string{"*.keys", "*.gpg", "*.rss", "*.atom"}
+)
+
+// IsUsableUsername returns an error when a username is reserved
+func IsUsableUsername(name string) error {
+       // Validate username make sure it satisfies requirement.
+       if db.AlphaDashDotPattern.MatchString(name) {
+               // Note: usually this error is normally caught up earlier in the UI
+               return db.ErrNameCharsNotAllowed{Name: name}
+       }
+       return db.IsUsableName(reservedUsernames, reservedUserPatterns, name)
+}
+
+// CreateUserOverwriteOptions are an optional options who overwrite system defaults on user creation
+type CreateUserOverwriteOptions struct {
+       Visibility structs.VisibleType
+}
+
+// CreateUser creates record of a new user.
+func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err error) {
+       if err = IsUsableUsername(u.Name); err != nil {
+               return err
+       }
+
+       // set system defaults
+       u.KeepEmailPrivate = setting.Service.DefaultKeepEmailPrivate
+       u.Visibility = setting.Service.DefaultUserVisibilityMode
+       u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization && !setting.Admin.DisableRegularOrgCreation
+       u.EmailNotificationsPreference = setting.Admin.DefaultEmailNotification
+       u.MaxRepoCreation = -1
+       u.Theme = setting.UI.DefaultTheme
+
+       // overwrite defaults if set
+       if len(overwriteDefault) != 0 && overwriteDefault[0] != nil {
+               u.Visibility = overwriteDefault[0].Visibility
+       }
+
+       ctx, committer, err := db.TxContext()
+       if err != nil {
+               return err
+       }
+       defer committer.Close()
+
+       sess := db.GetEngine(ctx)
+
+       // validate data
+       if err := validateUser(u); err != nil {
+               return err
+       }
+
+       isExist, err := isUserExist(sess, 0, u.Name)
+       if err != nil {
+               return err
+       } else if isExist {
+               return ErrUserAlreadyExist{u.Name}
+       }
+
+       isExist, err = IsEmailUsed(ctx, u.Email)
+       if err != nil {
+               return err
+       } else if isExist {
+               return ErrEmailAlreadyUsed{
+                       Email: u.Email,
+               }
+       }
+
+       // prepare for database
+
+       u.LowerName = strings.ToLower(u.Name)
+       u.AvatarEmail = u.Email
+       if u.Rands, err = GetUserSalt(); err != nil {
+               return err
+       }
+       if err = u.SetPassword(u.Passwd); err != nil {
+               return err
+       }
+
+       // save changes to database
+
+       if err = DeleteUserRedirect(ctx, u.Name); err != nil {
+               return err
+       }
+
+       if err = db.Insert(ctx, u); err != nil {
+               return err
+       }
+
+       // insert email address
+       if err := db.Insert(ctx, &EmailAddress{
+               UID:         u.ID,
+               Email:       u.Email,
+               LowerEmail:  strings.ToLower(u.Email),
+               IsActivated: u.IsActive,
+               IsPrimary:   true,
+       }); err != nil {
+               return err
+       }
+
+       return committer.Commit()
+}
+
+func countUsers(e db.Engine) int64 {
+       count, _ := e.
+               Where("type=0").
+               Count(new(User))
+       return count
+}
+
+// CountUsers returns number of users.
+func CountUsers() int64 {
+       return countUsers(db.GetEngine(db.DefaultContext))
+}
+
+// GetVerifyUser get user by verify code
+func GetVerifyUser(code string) (user *User) {
+       if len(code) <= base.TimeLimitCodeLength {
+               return nil
+       }
+
+       // use tail hex username query user
+       hexStr := code[base.TimeLimitCodeLength:]
+       if b, err := hex.DecodeString(hexStr); err == nil {
+               if user, err = GetUserByName(string(b)); user != nil {
+                       return user
+               }
+               log.Error("user.getVerifyUser: %v", err)
+       }
+
+       return nil
+}
+
+// VerifyUserActiveCode verifies active code when active account
+func VerifyUserActiveCode(code string) (user *User) {
+       minutes := setting.Service.ActiveCodeLives
+
+       if user = GetVerifyUser(code); user != nil {
+               // time limit code
+               prefix := code[:base.TimeLimitCodeLength]
+               data := fmt.Sprintf("%d%s%s%s%s", user.ID, user.Email, user.LowerName, user.Passwd, user.Rands)
+
+               if base.VerifyTimeLimitCode(data, minutes, prefix) {
+                       return user
+               }
+       }
+       return nil
+}
+
+// ChangeUserName changes all corresponding setting from old user name to new one.
+func ChangeUserName(u *User, newUserName string) (err error) {
+       oldUserName := u.Name
+       if err = IsUsableUsername(newUserName); err != nil {
+               return err
+       }
+
+       ctx, committer, err := db.TxContext()
+       if err != nil {
+               return err
+       }
+       defer committer.Close()
+       sess := db.GetEngine(ctx)
+
+       isExist, err := isUserExist(sess, 0, newUserName)
+       if err != nil {
+               return err
+       } else if isExist {
+               return ErrUserAlreadyExist{newUserName}
+       }
+
+       if _, err = sess.Exec("UPDATE `repository` SET owner_name=? WHERE owner_name=?", newUserName, oldUserName); err != nil {
+               return fmt.Errorf("Change repo owner name: %v", err)
+       }
+
+       // Do not fail if directory does not exist
+       if err = util.Rename(UserPath(oldUserName), UserPath(newUserName)); err != nil && !os.IsNotExist(err) {
+               return fmt.Errorf("Rename user directory: %v", err)
+       }
+
+       if err = NewUserRedirect(ctx, u.ID, oldUserName, newUserName); err != nil {
+               return err
+       }
+
+       if err = committer.Commit(); err != nil {
+               if err2 := util.Rename(UserPath(newUserName), UserPath(oldUserName)); err2 != nil && !os.IsNotExist(err2) {
+                       log.Critical("Unable to rollback directory change during failed username change from: %s to: %s. DB Error: %v. Filesystem Error: %v", oldUserName, newUserName, err, err2)
+                       return fmt.Errorf("failed to rollback directory change during failed username change from: %s to: %s. DB Error: %w. Filesystem Error: %v", oldUserName, newUserName, err, err2)
+               }
+               return err
+       }
+
+       return nil
+}
+
+// checkDupEmail checks whether there are the same email with the user
+func checkDupEmail(e db.Engine, u *User) error {
+       u.Email = strings.ToLower(u.Email)
+       has, err := e.
+               Where("id!=?", u.ID).
+               And("type=?", u.Type).
+               And("email=?", u.Email).
+               Get(new(User))
+       if err != nil {
+               return err
+       } else if has {
+               return ErrEmailAlreadyUsed{
+                       Email: u.Email,
+               }
+       }
+       return nil
+}
+
+// validateUser check if user is valid to insert / update into database
+func validateUser(u *User) error {
+       if !setting.Service.AllowedUserVisibilityModesSlice.IsAllowedVisibility(u.Visibility) && !u.IsOrganization() {
+               return fmt.Errorf("visibility Mode not allowed: %s", u.Visibility.String())
+       }
+
+       u.Email = strings.ToLower(u.Email)
+       return ValidateEmail(u.Email)
+}
+
+func updateUser(e db.Engine, u *User) error {
+       if err := validateUser(u); err != nil {
+               return err
+       }
+
+       _, err := e.ID(u.ID).AllCols().Update(u)
+       return err
+}
+
+// UpdateUser updates user's information.
+func UpdateUser(u *User) error {
+       return updateUser(db.GetEngine(db.DefaultContext), u)
+}
+
+// UpdateUserCols update user according special columns
+func UpdateUserCols(ctx context.Context, u *User, cols ...string) error {
+       return updateUserCols(db.GetEngine(ctx), u, cols...)
+}
+
+// UpdateUserColsEngine update user according special columns
+func UpdateUserColsEngine(e db.Engine, u *User, cols ...string) error {
+       return updateUserCols(e, u, cols...)
+}
+
+func updateUserCols(e db.Engine, u *User, cols ...string) error {
+       if err := validateUser(u); err != nil {
+               return err
+       }
+
+       _, err := e.ID(u.ID).Cols(cols...).Update(u)
+       return err
+}
+
+// UpdateUserSetting updates user's settings.
+func UpdateUserSetting(u *User) (err error) {
+       ctx, committer, err := db.TxContext()
+       if err != nil {
+               return err
+       }
+       defer committer.Close()
+       sess := db.GetEngine(ctx)
+
+       if !u.IsOrganization() {
+               if err = checkDupEmail(sess, u); err != nil {
+                       return err
+               }
+       }
+       if err = updateUser(sess, u); err != nil {
+               return err
+       }
+       return committer.Commit()
+}
+
+// GetInactiveUsers gets all inactive users
+func GetInactiveUsers(ctx context.Context, olderThan time.Duration) ([]*User, error) {
+       var cond builder.Cond = builder.Eq{"is_active": false}
+
+       if olderThan > 0 {
+               cond = cond.And(builder.Lt{"created_unix": time.Now().Add(-olderThan).Unix()})
+       }
+
+       users := make([]*User, 0, 10)
+       return users, db.GetEngine(ctx).
+               Where(cond).
+               Find(&users)
+}
+
+// UserPath returns the path absolute path of user repositories.
+func UserPath(userName string) string { //revive:disable-line:exported
+       return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
+}
+
+// GetUserByIDEngine returns the user object by given ID if exists.
+func GetUserByIDEngine(e db.Engine, id int64) (*User, error) {
+       u := new(User)
+       has, err := e.ID(id).Get(u)
+       if err != nil {
+               return nil, err
+       } else if !has {
+               return nil, ErrUserNotExist{id, "", 0}
+       }
+       return u, nil
+}
+
+// GetUserByID returns the user object by given ID if exists.
+func GetUserByID(id int64) (*User, error) {
+       return GetUserByIDCtx(db.DefaultContext, id)
+}
+
+// GetUserByIDCtx returns the user object by given ID if exists.
+func GetUserByIDCtx(ctx context.Context, id int64) (*User, error) {
+       return GetUserByIDEngine(db.GetEngine(ctx), id)
+}
+
+// GetUserByName returns user by given name.
+func GetUserByName(name string) (*User, error) {
+       return GetUserByNameCtx(db.DefaultContext, name)
+}
+
+// GetUserByNameCtx returns user by given name.
+func GetUserByNameCtx(ctx context.Context, name string) (*User, error) {
+       if len(name) == 0 {
+               return nil, ErrUserNotExist{0, name, 0}
+       }
+       u := &User{LowerName: strings.ToLower(name)}
+       has, err := db.GetEngine(ctx).Get(u)
+       if err != nil {
+               return nil, err
+       } else if !has {
+               return nil, ErrUserNotExist{0, name, 0}
+       }
+       return u, nil
+}
+
+// GetUserEmailsByNames returns a list of e-mails corresponds to names of users
+// that have their email notifications set to enabled or onmention.
+func GetUserEmailsByNames(names []string) []string {
+       return getUserEmailsByNames(db.DefaultContext, names)
+}
+
+func getUserEmailsByNames(ctx context.Context, names []string) []string {
+       mails := make([]string, 0, len(names))
+       for _, name := range names {
+               u, err := GetUserByNameCtx(ctx, name)
+               if err != nil {
+                       continue
+               }
+               if u.IsMailable() && u.EmailNotifications() != EmailNotificationsDisabled {
+                       mails = append(mails, u.Email)
+               }
+       }
+       return mails
+}
+
+// GetMaileableUsersByIDs gets users from ids, but only if they can receive mails
+func GetMaileableUsersByIDs(ids []int64, isMention bool) ([]*User, error) {
+       if len(ids) == 0 {
+               return nil, nil
+       }
+       ous := make([]*User, 0, len(ids))
+
+       if isMention {
+               return ous, db.GetEngine(db.DefaultContext).In("id", ids).
+                       Where("`type` = ?", UserTypeIndividual).
+                       And("`prohibit_login` = ?", false).
+                       And("`is_active` = ?", true).
+                       And("`email_notifications_preference` IN ( ?, ?)", EmailNotificationsEnabled, EmailNotificationsOnMention).
+                       Find(&ous)
+       }
+
+       return ous, db.GetEngine(db.DefaultContext).In("id", ids).
+               Where("`type` = ?", UserTypeIndividual).
+               And("`prohibit_login` = ?", false).
+               And("`is_active` = ?", true).
+               And("`email_notifications_preference` = ?", EmailNotificationsEnabled).
+               Find(&ous)
+}
+
+// GetUserNamesByIDs returns usernames for all resolved users from a list of Ids.
+func GetUserNamesByIDs(ids []int64) ([]string, error) {
+       unames := make([]string, 0, len(ids))
+       err := db.GetEngine(db.DefaultContext).In("id", ids).
+               Table("user").
+               Asc("name").
+               Cols("name").
+               Find(&unames)
+       return unames, err
+}
+
+// GetUserIDsByNames returns a slice of ids corresponds to names.
+func GetUserIDsByNames(names []string, ignoreNonExistent bool) ([]int64, error) {
+       ids := make([]int64, 0, len(names))
+       for _, name := range names {
+               u, err := GetUserByName(name)
+               if err != nil {
+                       if ignoreNonExistent {
+                               continue
+                       } else {
+                               return nil, err
+                       }
+               }
+               ids = append(ids, u.ID)
+       }
+       return ids, nil
+}
+
+// GetUsersBySource returns a list of Users for a login source
+func GetUsersBySource(s *login.Source) ([]*User, error) {
+       var users []*User
+       err := db.GetEngine(db.DefaultContext).Where("login_type = ? AND login_source = ?", s.Type, s.ID).Find(&users)
+       return users, err
+}
+
+// UserCommit represents a commit with validation of user.
+type UserCommit struct { //revive:disable-line:exported
+       User *User
+       *git.Commit
+}
+
+// ValidateCommitWithEmail check if author's e-mail of commit is corresponding to a user.
+func ValidateCommitWithEmail(c *git.Commit) *User {
+       if c.Author == nil {
+               return nil
+       }
+       u, err := GetUserByEmail(c.Author.Email)
+       if err != nil {
+               return nil
+       }
+       return u
+}
+
+// ValidateCommitsWithEmails checks if authors' e-mails of commits are corresponding to users.
+func ValidateCommitsWithEmails(oldCommits []*git.Commit) []*UserCommit {
+       var (
+               emails     = make(map[string]*User)
+               newCommits = make([]*UserCommit, 0, len(oldCommits))
+       )
+       for _, c := range oldCommits {
+               var u *User
+               if c.Author != nil {
+                       if v, ok := emails[c.Author.Email]; !ok {
+                               u, _ = GetUserByEmail(c.Author.Email)
+                               emails[c.Author.Email] = u
+                       } else {
+                               u = v
+                       }
+               }
+
+               newCommits = append(newCommits, &UserCommit{
+                       User:   u,
+                       Commit: c,
+               })
+       }
+       return newCommits
+}
+
+// GetUserByEmail returns the user object by given e-mail if exists.
+func GetUserByEmail(email string) (*User, error) {
+       return GetUserByEmailContext(db.DefaultContext, email)
+}
+
+// GetUserByEmailContext returns the user object by given e-mail if exists with db context
+func GetUserByEmailContext(ctx context.Context, email string) (*User, error) {
+       if len(email) == 0 {
+               return nil, ErrUserNotExist{0, email, 0}
+       }
+
+       email = strings.ToLower(email)
+       // First try to find the user by primary email
+       user := &User{Email: email}
+       has, err := db.GetEngine(ctx).Get(user)
+       if err != nil {
+               return nil, err
+       }
+       if has {
+               return user, nil
+       }
+
+       // Otherwise, check in alternative list for activated email addresses
+       emailAddress := &EmailAddress{Email: email, IsActivated: true}
+       has, err = db.GetEngine(ctx).Get(emailAddress)
+       if err != nil {
+               return nil, err
+       }
+       if has {
+               return GetUserByIDCtx(ctx, emailAddress.UID)
+       }
+
+       // Finally, if email address is the protected email address:
+       if strings.HasSuffix(email, fmt.Sprintf("@%s", setting.Service.NoReplyAddress)) {
+               username := strings.TrimSuffix(email, fmt.Sprintf("@%s", setting.Service.NoReplyAddress))
+               user := &User{}
+               has, err := db.GetEngine(ctx).Where("lower_name=?", username).Get(user)
+               if err != nil {
+                       return nil, err
+               }
+               if has {
+                       return user, nil
+               }
+       }
+
+       return nil, ErrUserNotExist{0, email, 0}
+}
+
+// GetUser checks if a user already exists
+func GetUser(user *User) (bool, error) {
+       return db.GetEngine(db.DefaultContext).Get(user)
+}
+
+// GetUserByOpenID returns the user object by given OpenID if exists.
+func GetUserByOpenID(uri string) (*User, error) {
+       if len(uri) == 0 {
+               return nil, ErrUserNotExist{0, uri, 0}
+       }
+
+       uri, err := openid.Normalize(uri)
+       if err != nil {
+               return nil, err
+       }
+
+       log.Trace("Normalized OpenID URI: " + uri)
+
+       // Otherwise, check in openid table
+       oid := &UserOpenID{}
+       has, err := db.GetEngine(db.DefaultContext).Where("uri=?", uri).Get(oid)
+       if err != nil {
+               return nil, err
+       }
+       if has {
+               return GetUserByID(oid.UID)
+       }
+
+       return nil, ErrUserNotExist{0, uri, 0}
+}
+
+// GetAdminUser returns the first administrator
+func GetAdminUser() (*User, error) {
+       var admin User
+       has, err := db.GetEngine(db.DefaultContext).Where("is_admin=?", true).Get(&admin)
+       if err != nil {
+               return nil, err
+       } else if !has {
+               return nil, ErrUserNotExist{}
+       }
+
+       return &admin, nil
+}
diff --git a/models/user/user_test.go b/models/user/user_test.go
new file mode 100644 (file)
index 0000000..ac49852
--- /dev/null
@@ -0,0 +1,355 @@
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package user
+
+import (
+       "math/rand"
+       "strings"
+       "testing"
+
+       "code.gitea.io/gitea/models/db"
+       "code.gitea.io/gitea/models/login"
+       "code.gitea.io/gitea/models/unittest"
+       "code.gitea.io/gitea/modules/setting"
+       "code.gitea.io/gitea/modules/structs"
+       "code.gitea.io/gitea/modules/util"
+
+       "github.com/stretchr/testify/assert"
+)
+
+func TestOAuth2Application_LoadUser(t *testing.T) {
+       assert.NoError(t, unittest.PrepareTestDatabase())
+       app := unittest.AssertExistsAndLoadBean(t, &login.OAuth2Application{ID: 1}).(*login.OAuth2Application)
+       user, err := GetUserByID(app.UID)
+       assert.NoError(t, err)
+       assert.NotNil(t, user)
+}
+
+func TestGetUserEmailsByNames(t *testing.T) {
+       assert.NoError(t, unittest.PrepareTestDatabase())
+
+       // ignore none active user email
+       assert.Equal(t, []string{"user8@example.com"}, GetUserEmailsByNames([]string{"user8", "user9"}))
+       assert.Equal(t, []string{"user8@example.com", "user5@example.com"}, GetUserEmailsByNames([]string{"user8", "user5"}))
+
+       assert.Equal(t, []string{"user8@example.com"}, GetUserEmailsByNames([]string{"user8", "user7"}))
+}
+
+func TestCanCreateOrganization(t *testing.T) {
+       assert.NoError(t, unittest.PrepareTestDatabase())
+
+       admin := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       assert.True(t, admin.CanCreateOrganization())
+
+       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       assert.True(t, user.CanCreateOrganization())
+       // Disable user create organization permission.
+       user.AllowCreateOrganization = false
+       assert.False(t, user.CanCreateOrganization())
+
+       setting.Admin.DisableRegularOrgCreation = true
+       user.AllowCreateOrganization = true
+       assert.True(t, admin.CanCreateOrganization())
+       assert.False(t, user.CanCreateOrganization())
+}
+
+func TestSearchUsers(t *testing.T) {
+       assert.NoError(t, unittest.PrepareTestDatabase())
+       testSuccess := func(opts *SearchUserOptions, expectedUserOrOrgIDs []int64) {
+               users, _, err := SearchUsers(opts)
+               assert.NoError(t, err)
+               if assert.Len(t, users, len(expectedUserOrOrgIDs), opts) {
+                       for i, expectedID := range expectedUserOrOrgIDs {
+                               assert.EqualValues(t, expectedID, users[i].ID)
+                       }
+               }
+       }
+
+       // test orgs
+       testOrgSuccess := func(opts *SearchUserOptions, expectedOrgIDs []int64) {
+               opts.Type = UserTypeOrganization
+               testSuccess(opts, expectedOrgIDs)
+       }
+
+       testOrgSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1, PageSize: 2}},
+               []int64{3, 6})
+
+       testOrgSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 2, PageSize: 2}},
+               []int64{7, 17})
+
+       testOrgSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 3, PageSize: 2}},
+               []int64{19, 25})
+
+       testOrgSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 4, PageSize: 2}},
+               []int64{26})
+
+       testOrgSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 5, PageSize: 2}},
+               []int64{})
+
+       // test users
+       testUserSuccess := func(opts *SearchUserOptions, expectedUserIDs []int64) {
+               opts.Type = UserTypeIndividual
+               testSuccess(opts, expectedUserIDs)
+       }
+
+       testUserSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}},
+               []int64{1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32})
+
+       testUserSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolFalse},
+               []int64{9})
+
+       testUserSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue},
+               []int64{1, 2, 4, 5, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 28, 29, 30, 32})
+
+       testUserSuccess(&SearchUserOptions{Keyword: "user1", OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue},
+               []int64{1, 10, 11, 12, 13, 14, 15, 16, 18})
+
+       // order by name asc default
+       testUserSuccess(&SearchUserOptions{Keyword: "user1", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue},
+               []int64{1, 10, 11, 12, 13, 14, 15, 16, 18})
+
+       testUserSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsAdmin: util.OptionalBoolTrue},
+               []int64{1})
+
+       testUserSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsRestricted: util.OptionalBoolTrue},
+               []int64{29, 30})
+
+       testUserSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsProhibitLogin: util.OptionalBoolTrue},
+               []int64{30})
+
+       testUserSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsTwoFactorEnabled: util.OptionalBoolTrue},
+               []int64{24})
+}
+
+func TestEmailNotificationPreferences(t *testing.T) {
+       assert.NoError(t, unittest.PrepareTestDatabase())
+
+       for _, test := range []struct {
+               expected string
+               userID   int64
+       }{
+               {EmailNotificationsEnabled, 1},
+               {EmailNotificationsEnabled, 2},
+               {EmailNotificationsOnMention, 3},
+               {EmailNotificationsOnMention, 4},
+               {EmailNotificationsEnabled, 5},
+               {EmailNotificationsEnabled, 6},
+               {EmailNotificationsDisabled, 7},
+               {EmailNotificationsEnabled, 8},
+               {EmailNotificationsOnMention, 9},
+       } {
+               user := unittest.AssertExistsAndLoadBean(t, &User{ID: test.userID}).(*User)
+               assert.Equal(t, test.expected, user.EmailNotifications())
+
+               // Try all possible settings
+               assert.NoError(t, SetEmailNotifications(user, EmailNotificationsEnabled))
+               assert.Equal(t, EmailNotificationsEnabled, user.EmailNotifications())
+
+               assert.NoError(t, SetEmailNotifications(user, EmailNotificationsOnMention))
+               assert.Equal(t, EmailNotificationsOnMention, user.EmailNotifications())
+
+               assert.NoError(t, SetEmailNotifications(user, EmailNotificationsDisabled))
+               assert.Equal(t, EmailNotificationsDisabled, user.EmailNotifications())
+       }
+}
+
+func TestHashPasswordDeterministic(t *testing.T) {
+       b := make([]byte, 16)
+       u := &User{}
+       algos := []string{"argon2", "pbkdf2", "scrypt", "bcrypt"}
+       for j := 0; j < len(algos); j++ {
+               u.PasswdHashAlgo = algos[j]
+               for i := 0; i < 50; i++ {
+                       // generate a random password
+                       rand.Read(b)
+                       pass := string(b)
+
+                       // save the current password in the user - hash it and store the result
+                       u.SetPassword(pass)
+                       r1 := u.Passwd
+
+                       // run again
+                       u.SetPassword(pass)
+                       r2 := u.Passwd
+
+                       assert.NotEqual(t, r1, r2)
+                       assert.True(t, u.ValidatePassword(pass))
+               }
+       }
+}
+
+func BenchmarkHashPassword(b *testing.B) {
+       // BenchmarkHashPassword ensures that it takes a reasonable amount of time
+       // to hash a password - in order to protect from brute-force attacks.
+       pass := "password1337"
+       u := &User{Passwd: pass}
+       b.ResetTimer()
+       for i := 0; i < b.N; i++ {
+               u.SetPassword(pass)
+       }
+}
+
+func TestNewGitSig(t *testing.T) {
+       users := make([]*User, 0, 20)
+       err := db.GetEngine(db.DefaultContext).Find(&users)
+       assert.NoError(t, err)
+
+       for _, user := range users {
+               sig := user.NewGitSig()
+               assert.NotContains(t, sig.Name, "<")
+               assert.NotContains(t, sig.Name, ">")
+               assert.NotContains(t, sig.Name, "\n")
+               assert.NotEqual(t, len(strings.TrimSpace(sig.Name)), 0)
+       }
+}
+
+func TestDisplayName(t *testing.T) {
+       users := make([]*User, 0, 20)
+       err := db.GetEngine(db.DefaultContext).Find(&users)
+       assert.NoError(t, err)
+
+       for _, user := range users {
+               displayName := user.DisplayName()
+               assert.Equal(t, strings.TrimSpace(displayName), displayName)
+               if len(strings.TrimSpace(user.FullName)) == 0 {
+                       assert.Equal(t, user.Name, displayName)
+               }
+               assert.NotEqual(t, len(strings.TrimSpace(displayName)), 0)
+       }
+}
+
+func TestCreateUserInvalidEmail(t *testing.T) {
+       user := &User{
+               Name:               "GiteaBot",
+               Email:              "GiteaBot@gitea.io\r\n",
+               Passwd:             ";p['////..-++']",
+               IsAdmin:            false,
+               Theme:              setting.UI.DefaultTheme,
+               MustChangePassword: false,
+       }
+
+       err := CreateUser(user)
+       assert.Error(t, err)
+       assert.True(t, IsErrEmailInvalid(err))
+}
+
+func TestGetUserIDsByNames(t *testing.T) {
+       assert.NoError(t, unittest.PrepareTestDatabase())
+
+       // ignore non existing
+       IDs, err := GetUserIDsByNames([]string{"user1", "user2", "none_existing_user"}, true)
+       assert.NoError(t, err)
+       assert.Equal(t, []int64{1, 2}, IDs)
+
+       // ignore non existing
+       IDs, err = GetUserIDsByNames([]string{"user1", "do_not_exist"}, false)
+       assert.Error(t, err)
+       assert.Equal(t, []int64(nil), IDs)
+}
+
+func TestGetMaileableUsersByIDs(t *testing.T) {
+       assert.NoError(t, unittest.PrepareTestDatabase())
+
+       results, err := GetMaileableUsersByIDs([]int64{1, 4}, false)
+       assert.NoError(t, err)
+       assert.Len(t, results, 1)
+       if len(results) > 1 {
+               assert.Equal(t, results[0].ID, 1)
+       }
+
+       results, err = GetMaileableUsersByIDs([]int64{1, 4}, true)
+       assert.NoError(t, err)
+       assert.Len(t, results, 2)
+       if len(results) > 2 {
+               assert.Equal(t, results[0].ID, 1)
+               assert.Equal(t, results[1].ID, 4)
+       }
+}
+
+func TestUpdateUser(t *testing.T) {
+       assert.NoError(t, unittest.PrepareTestDatabase())
+       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+
+       user.KeepActivityPrivate = true
+       assert.NoError(t, UpdateUser(user))
+       user = unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       assert.True(t, user.KeepActivityPrivate)
+
+       setting.Service.AllowedUserVisibilityModesSlice = []bool{true, false, false}
+       user.KeepActivityPrivate = false
+       user.Visibility = structs.VisibleTypePrivate
+       assert.Error(t, UpdateUser(user))
+       user = unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       assert.True(t, user.KeepActivityPrivate)
+
+       user.Email = "no mail@mail.org"
+       assert.Error(t, UpdateUser(user))
+}
+
+func TestNewUserRedirect(t *testing.T) {
+       // redirect to a completely new name
+       assert.NoError(t, unittest.PrepareTestDatabase())
+
+       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       assert.NoError(t, NewUserRedirect(db.DefaultContext, user.ID, user.Name, "newusername"))
+
+       unittest.AssertExistsAndLoadBean(t, &Redirect{
+               LowerName:      user.LowerName,
+               RedirectUserID: user.ID,
+       })
+       unittest.AssertExistsAndLoadBean(t, &Redirect{
+               LowerName:      "olduser1",
+               RedirectUserID: user.ID,
+       })
+}
+
+func TestNewUserRedirect2(t *testing.T) {
+       // redirect to previously used name
+       assert.NoError(t, unittest.PrepareTestDatabase())
+
+       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+       assert.NoError(t, NewUserRedirect(db.DefaultContext, user.ID, user.Name, "olduser1"))
+
+       unittest.AssertExistsAndLoadBean(t, &Redirect{
+               LowerName:      user.LowerName,
+               RedirectUserID: user.ID,
+       })
+       unittest.AssertNotExistsBean(t, &Redirect{
+               LowerName:      "olduser1",
+               RedirectUserID: user.ID,
+       })
+}
+
+func TestNewUserRedirect3(t *testing.T) {
+       // redirect for a previously-unredirected user
+       assert.NoError(t, unittest.PrepareTestDatabase())
+
+       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       assert.NoError(t, NewUserRedirect(db.DefaultContext, user.ID, user.Name, "newusername"))
+
+       unittest.AssertExistsAndLoadBean(t, &Redirect{
+               LowerName:      user.LowerName,
+               RedirectUserID: user.ID,
+       })
+}
+
+func TestGetUserByOpenID(t *testing.T) {
+       assert.NoError(t, unittest.PrepareTestDatabase())
+
+       _, err := GetUserByOpenID("https://unknown")
+       if assert.Error(t, err) {
+               assert.True(t, IsErrUserNotExist(err))
+       }
+
+       user, err := GetUserByOpenID("https://user1.domain1.tld")
+       if assert.NoError(t, err) {
+               assert.Equal(t, int64(1), user.ID)
+       }
+
+       user, err = GetUserByOpenID("https://domain1.tld/user2/")
+       if assert.NoError(t, err) {
+               assert.Equal(t, int64(2), user.ID)
+       }
+}
diff --git a/models/user_avatar.go b/models/user_avatar.go
deleted file mode 100644 (file)
index ae4cd1e..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2020 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package models
-
-import (
-       "crypto/md5"
-       "fmt"
-       "image/png"
-       "io"
-       "strings"
-
-       "code.gitea.io/gitea/models/avatars"
-       "code.gitea.io/gitea/models/db"
-       "code.gitea.io/gitea/modules/avatar"
-       "code.gitea.io/gitea/modules/log"
-       "code.gitea.io/gitea/modules/setting"
-       "code.gitea.io/gitea/modules/storage"
-)
-
-// CustomAvatarRelativePath returns user custom avatar relative path.
-func (u *User) CustomAvatarRelativePath() string {
-       return u.Avatar
-}
-
-// GenerateRandomAvatar generates a random avatar for user.
-func GenerateRandomAvatar(u *User) error {
-       return generateRandomAvatar(db.GetEngine(db.DefaultContext), u)
-}
-
-func generateRandomAvatar(e db.Engine, u *User) error {
-       seed := u.Email
-       if len(seed) == 0 {
-               seed = u.Name
-       }
-
-       img, err := avatar.RandomImage([]byte(seed))
-       if err != nil {
-               return fmt.Errorf("RandomImage: %v", err)
-       }
-
-       u.Avatar = avatars.HashEmail(seed)
-
-       // Don't share the images so that we can delete them easily
-       if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {
-               if err := png.Encode(w, img); err != nil {
-                       log.Error("Encode: %v", err)
-               }
-               return err
-       }); err != nil {
-               return fmt.Errorf("Failed to create dir %s: %v", u.CustomAvatarRelativePath(), err)
-       }
-
-       if _, err := e.ID(u.ID).Cols("avatar").Update(u); err != nil {
-               return err
-       }
-
-       log.Info("New random avatar created: %d", u.ID)
-       return nil
-}
-
-// AvatarLinkWithSize returns a link to the user's avatar with size. size <= 0 means default size
-func (u *User) AvatarLinkWithSize(size int) string {
-       if u.ID == -1 {
-               // ghost user
-               return avatars.DefaultAvatarLink()
-       }
-
-       useLocalAvatar := false
-       autoGenerateAvatar := false
-
-       switch {
-       case u.UseCustomAvatar:
-               useLocalAvatar = true
-       case setting.DisableGravatar, setting.OfflineMode:
-               useLocalAvatar = true
-               autoGenerateAvatar = true
-       }
-
-       if useLocalAvatar {
-               if u.Avatar == "" && autoGenerateAvatar {
-                       if err := GenerateRandomAvatar(u); err != nil {
-                               log.Error("GenerateRandomAvatar: %v", err)
-                       }
-               }
-               if u.Avatar == "" {
-                       return avatars.DefaultAvatarLink()
-               }
-               return avatars.GenerateUserAvatarImageLink(u.Avatar, size)
-       }
-       return avatars.GenerateEmailAvatarFastLink(u.AvatarEmail, size)
-}
-
-// AvatarLink returns the full avatar link with http host
-func (u *User) AvatarLink() string {
-       link := u.AvatarLinkWithSize(0)
-       if !strings.HasPrefix(link, "//") && !strings.Contains(link, "://") {
-               return setting.AppURL + strings.TrimPrefix(link, setting.AppSubURL+"/")
-       }
-       return link
-}
-
-// IsUploadAvatarChanged returns true if the current user's avatar would be changed with the provided data
-func (u *User) IsUploadAvatarChanged(data []byte) bool {
-       if !u.UseCustomAvatar || len(u.Avatar) == 0 {
-               return true
-       }
-       avatarID := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
-       return u.Avatar != avatarID
-}
index 8c5fbf6d6aeb35c67d3121480c6a02f678ef61e9..528ebb0540282626b0312777e832e33fb0acafe3 100644 (file)
@@ -31,18 +31,18 @@ func ActivateEmail(email *user_model.EmailAddress) error {
 }
 
 func updateActivation(e db.Engine, email *user_model.EmailAddress, activate bool) error {
-       user, err := getUserByID(e, email.UID)
+       user, err := user_model.GetUserByIDEngine(e, email.UID)
        if err != nil {
                return err
        }
-       if user.Rands, err = GetUserSalt(); err != nil {
+       if user.Rands, err = user_model.GetUserSalt(); err != nil {
                return err
        }
        email.IsActivated = activate
        if _, err := e.ID(email.ID).Cols("is_activated").Update(email); err != nil {
                return err
        }
-       return updateUserCols(e, user, "rands")
+       return user_model.UpdateUserColsEngine(e, user, "rands")
 }
 
 // MakeEmailPrimary sets primary email address of given user.
@@ -58,12 +58,16 @@ func MakeEmailPrimary(email *user_model.EmailAddress) error {
                return user_model.ErrEmailNotActivated
        }
 
-       user := &User{}
+       user := &user_model.User{}
        has, err = db.GetEngine(db.DefaultContext).ID(email.UID).Get(user)
        if err != nil {
                return err
        } else if !has {
-               return ErrUserNotExist{email.UID, "", 0}
+               return user_model.ErrUserNotExist{
+                       UID:   email.UID,
+                       Name:  "",
+                       KeyID: 0,
+               }
        }
 
        ctx, committer, err := db.TxContext()
@@ -99,7 +103,7 @@ func MakeEmailPrimary(email *user_model.EmailAddress) error {
 func VerifyActiveEmailCode(code, email string) *user_model.EmailAddress {
        minutes := setting.Service.ActiveCodeLives
 
-       if user := getVerifyUser(code); user != nil {
+       if user := user_model.GetVerifyUser(code); user != nil {
                // time limit code
                prefix := code[:base.TimeLimitCodeLength]
                data := fmt.Sprintf("%d%s%s%s%s", user.ID, email, user.LowerName, user.Passwd, user.Rands)
@@ -152,7 +156,7 @@ type SearchEmailResult struct {
 // SearchEmails takes options i.e. keyword and part of email name to search,
 // it returns results in given range and number of total results.
 func SearchEmails(opts *SearchEmailOptions) ([]*SearchEmailResult, int64, error) {
-       var cond builder.Cond = builder.Eq{"`user`.`type`": UserTypeIndividual}
+       var cond builder.Cond = builder.Eq{"`user`.`type`": user_model.UserTypeIndividual}
        if len(opts.Keyword) > 0 {
                likeStr := "%" + strings.ToLower(opts.Keyword) + "%"
                cond = cond.And(builder.Or(
@@ -236,7 +240,7 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) {
 
        // Activate/deactivate a user's primary email address and account
        if addr.IsPrimary {
-               user := User{ID: userID, Email: email}
+               user := user_model.User{ID: userID, Email: email}
                if has, err := sess.Get(&user); err != nil {
                        return err
                } else if !has {
@@ -245,10 +249,10 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) {
                // The user's activation state should be synchronized with the primary email
                if user.IsActive != activate {
                        user.IsActive = activate
-                       if user.Rands, err = GetUserSalt(); err != nil {
+                       if user.Rands, err = user_model.GetUserSalt(); err != nil {
                                return fmt.Errorf("unable to generate salt: %v", err)
                        }
-                       if err = updateUserCols(sess, &user, "is_active", "rands"); err != nil {
+                       if err = user_model.UpdateUserColsEngine(sess, &user, "is_active", "rands"); err != nil {
                                return fmt.Errorf("unable to updateUserCols() for user ID: %d: %v", userID, err)
                        }
                }
index bed6a188673047140f53b68dc2bceeee547d5e0d..a91e24d363730141f06749f319e6d2aac0a3eb12 100644 (file)
@@ -37,7 +37,7 @@ func TestMakeEmailPrimary(t *testing.T) {
        }
        err = MakeEmailPrimary(email)
        assert.Error(t, err)
-       assert.True(t, IsErrUserNotExist(err))
+       assert.True(t, user_model.IsErrUserNotExist(err))
 
        email = &user_model.EmailAddress{
                Email: "user101@example.com",
@@ -45,7 +45,7 @@ func TestMakeEmailPrimary(t *testing.T) {
        err = MakeEmailPrimary(email)
        assert.NoError(t, err)
 
-       user, _ := GetUserByID(int64(10))
+       user, _ := user_model.GetUserByID(int64(10))
        assert.Equal(t, "user101@example.com", user.Email)
 }
 
index 3e94a6f9b7031dd894c0e96e6055a9fdfd8086e7..f331a0c16b81243f408d83c0f976219d902882b3 100644 (file)
@@ -6,6 +6,7 @@ package models
 
 import (
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/timeutil"
 )
@@ -17,16 +18,16 @@ type UserHeatmapData struct {
 }
 
 // GetUserHeatmapDataByUser returns an array of UserHeatmapData
-func GetUserHeatmapDataByUser(user, doer *User) ([]*UserHeatmapData, error) {
+func GetUserHeatmapDataByUser(user, doer *user_model.User) ([]*UserHeatmapData, error) {
        return getUserHeatmapData(user, nil, doer)
 }
 
 // GetUserHeatmapDataByUserTeam returns an array of UserHeatmapData
-func GetUserHeatmapDataByUserTeam(user *User, team *Team, doer *User) ([]*UserHeatmapData, error) {
+func GetUserHeatmapDataByUserTeam(user *user_model.User, team *Team, doer *user_model.User) ([]*UserHeatmapData, error) {
        return getUserHeatmapData(user, team, doer)
 }
 
-func getUserHeatmapData(user *User, team *Team, doer *User) ([]*UserHeatmapData, error) {
+func getUserHeatmapData(user *user_model.User, team *Team, doer *user_model.User) ([]*UserHeatmapData, error) {
        hdata := make([]*UserHeatmapData, 0)
 
        if !activityReadable(user, doer) {
index 2abbbfc6f33607a555512e33b9cd6e50c9c20d46..7d2997648df4a0f7b8af9edd623a43538c3df657 100644 (file)
@@ -10,6 +10,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/json"
        "code.gitea.io/gitea/modules/timeutil"
 
@@ -46,9 +47,9 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
        defer timeutil.Unset()
 
        for i, tc := range testCases {
-               user := unittest.AssertExistsAndLoadBean(t, &User{ID: tc.userID}).(*User)
+               user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: tc.userID}).(*user_model.User)
 
-               doer := &User{ID: tc.doerID}
+               doer := &user_model.User{ID: tc.doerID}
                _, err := unittest.LoadBeanIfExists(doer)
                assert.NoError(t, err)
                if tc.doerID == 0 {
index cfbd84964096a6dc70929c0bd8f2947f302d989b..d3c7718d69a314af4e56b317d0082fbaa6c05ff2 100644 (file)
@@ -6,27 +6,42 @@ package models
 
 import (
        "fmt"
-       "math/rand"
-       "strings"
        "testing"
 
-       "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/login"
        "code.gitea.io/gitea/models/unittest"
        user_model "code.gitea.io/gitea/models/user"
-       "code.gitea.io/gitea/modules/setting"
-       "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/modules/util"
 
        "github.com/stretchr/testify/assert"
 )
 
-func TestOAuth2Application_LoadUser(t *testing.T) {
+func TestFollowUser(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       app := unittest.AssertExistsAndLoadBean(t, &login.OAuth2Application{ID: 1}).(*login.OAuth2Application)
-       user, err := GetUserByID(app.UID)
-       assert.NoError(t, err)
-       assert.NotNil(t, user)
+
+       testSuccess := func(followerID, followedID int64) {
+               assert.NoError(t, user_model.FollowUser(followerID, followedID))
+               unittest.AssertExistsAndLoadBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
+       }
+       testSuccess(4, 2)
+       testSuccess(5, 2)
+
+       assert.NoError(t, user_model.FollowUser(2, 2))
+
+       unittest.CheckConsistencyFor(t, &user_model.User{})
+}
+
+func TestUnfollowUser(t *testing.T) {
+       assert.NoError(t, unittest.PrepareTestDatabase())
+
+       testSuccess := func(followerID, followedID int64) {
+               assert.NoError(t, user_model.UnfollowUser(followerID, followedID))
+               unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
+       }
+       testSuccess(4, 2)
+       testSuccess(5, 2)
+       testSuccess(2, 2)
+
+       unittest.CheckConsistencyFor(t, &user_model.User{})
 }
 
 func TestUserIsPublicMember(t *testing.T) {
@@ -50,7 +65,7 @@ func TestUserIsPublicMember(t *testing.T) {
 }
 
 func testUserIsPublicMember(t *testing.T, uid, orgID int64, expected bool) {
-       user, err := GetUserByID(uid)
+       user, err := user_model.GetUserByID(uid)
        assert.NoError(t, err)
        is, err := IsPublicMembership(orgID, user.ID)
        assert.NoError(t, err)
@@ -78,280 +93,39 @@ func TestIsUserOrgOwner(t *testing.T) {
 }
 
 func testIsUserOrgOwner(t *testing.T, uid, orgID int64, expected bool) {
-       user, err := GetUserByID(uid)
+       user, err := user_model.GetUserByID(uid)
        assert.NoError(t, err)
        is, err := IsOrganizationOwner(orgID, user.ID)
        assert.NoError(t, err)
        assert.Equal(t, expected, is)
 }
 
-func TestGetUserEmailsByNames(t *testing.T) {
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       // ignore none active user email
-       assert.Equal(t, []string{"user8@example.com"}, GetUserEmailsByNames([]string{"user8", "user9"}))
-       assert.Equal(t, []string{"user8@example.com", "user5@example.com"}, GetUserEmailsByNames([]string{"user8", "user5"}))
-
-       assert.Equal(t, []string{"user8@example.com"}, GetUserEmailsByNames([]string{"user8", "user7"}))
-}
-
-func TestCanCreateOrganization(t *testing.T) {
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       admin := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
-       assert.True(t, admin.CanCreateOrganization())
-
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       assert.True(t, user.CanCreateOrganization())
-       // Disable user create organization permission.
-       user.AllowCreateOrganization = false
-       assert.False(t, user.CanCreateOrganization())
-
-       setting.Admin.DisableRegularOrgCreation = true
-       user.AllowCreateOrganization = true
-       assert.True(t, admin.CanCreateOrganization())
-       assert.False(t, user.CanCreateOrganization())
-}
-
-func TestSearchUsers(t *testing.T) {
-       assert.NoError(t, unittest.PrepareTestDatabase())
-       testSuccess := func(opts *SearchUserOptions, expectedUserOrOrgIDs []int64) {
-               users, _, err := SearchUsers(opts)
-               assert.NoError(t, err)
-               if assert.Len(t, users, len(expectedUserOrOrgIDs)) {
-                       for i, expectedID := range expectedUserOrOrgIDs {
-                               assert.EqualValues(t, expectedID, users[i].ID)
-                       }
-               }
-       }
-
-       // test orgs
-       testOrgSuccess := func(opts *SearchUserOptions, expectedOrgIDs []int64) {
-               opts.Type = UserTypeOrganization
-               testSuccess(opts, expectedOrgIDs)
-       }
-
-       testOrgSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1, PageSize: 2}},
-               []int64{3, 6})
-
-       testOrgSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 2, PageSize: 2}},
-               []int64{7, 17})
-
-       testOrgSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 3, PageSize: 2}},
-               []int64{19, 25})
-
-       testOrgSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 4, PageSize: 2}},
-               []int64{26})
-
-       testOrgSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 5, PageSize: 2}},
-               []int64{})
-
-       // test users
-       testUserSuccess := func(opts *SearchUserOptions, expectedUserIDs []int64) {
-               opts.Type = UserTypeIndividual
-               testSuccess(opts, expectedUserIDs)
-       }
-
-       testUserSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}},
-               []int64{1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32})
-
-       testUserSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolFalse},
-               []int64{9})
-
-       testUserSuccess(&SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue},
-               []int64{1, 2, 4, 5, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 28, 29, 30, 32})
-
-       testUserSuccess(&SearchUserOptions{Keyword: "user1", OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue},
-               []int64{1, 10, 11, 12, 13, 14, 15, 16, 18})
-
-       // order by name asc default
-       testUserSuccess(&SearchUserOptions{Keyword: "user1", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue},
-               []int64{1, 10, 11, 12, 13, 14, 15, 16, 18})
-
-       testUserSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsAdmin: util.OptionalBoolTrue},
-               []int64{1})
-
-       testUserSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsRestricted: util.OptionalBoolTrue},
-               []int64{29, 30})
-
-       testUserSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsProhibitLogin: util.OptionalBoolTrue},
-               []int64{30})
-
-       testUserSuccess(&SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsTwoFactorEnabled: util.OptionalBoolTrue},
-               []int64{24})
-}
-
-func TestEmailNotificationPreferences(t *testing.T) {
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       for _, test := range []struct {
-               expected string
-               userID   int64
-       }{
-               {EmailNotificationsEnabled, 1},
-               {EmailNotificationsEnabled, 2},
-               {EmailNotificationsOnMention, 3},
-               {EmailNotificationsOnMention, 4},
-               {EmailNotificationsEnabled, 5},
-               {EmailNotificationsEnabled, 6},
-               {EmailNotificationsDisabled, 7},
-               {EmailNotificationsEnabled, 8},
-               {EmailNotificationsOnMention, 9},
-       } {
-               user := unittest.AssertExistsAndLoadBean(t, &User{ID: test.userID}).(*User)
-               assert.Equal(t, test.expected, user.EmailNotifications())
-
-               // Try all possible settings
-               assert.NoError(t, SetEmailNotifications(user, EmailNotificationsEnabled))
-               assert.Equal(t, EmailNotificationsEnabled, user.EmailNotifications())
-
-               assert.NoError(t, SetEmailNotifications(user, EmailNotificationsOnMention))
-               assert.Equal(t, EmailNotificationsOnMention, user.EmailNotifications())
-
-               assert.NoError(t, SetEmailNotifications(user, EmailNotificationsDisabled))
-               assert.Equal(t, EmailNotificationsDisabled, user.EmailNotifications())
-       }
-}
-
-func TestHashPasswordDeterministic(t *testing.T) {
-       b := make([]byte, 16)
-       u := &User{}
-       algos := []string{"argon2", "pbkdf2", "scrypt", "bcrypt"}
-       for j := 0; j < len(algos); j++ {
-               u.PasswdHashAlgo = algos[j]
-               for i := 0; i < 50; i++ {
-                       // generate a random password
-                       rand.Read(b)
-                       pass := string(b)
-
-                       // save the current password in the user - hash it and store the result
-                       u.SetPassword(pass)
-                       r1 := u.Passwd
-
-                       // run again
-                       u.SetPassword(pass)
-                       r2 := u.Passwd
-
-                       assert.NotEqual(t, r1, r2)
-                       assert.True(t, u.ValidatePassword(pass))
-               }
-       }
-}
-
-func BenchmarkHashPassword(b *testing.B) {
-       // BenchmarkHashPassword ensures that it takes a reasonable amount of time
-       // to hash a password - in order to protect from brute-force attacks.
-       pass := "password1337"
-       u := &User{Passwd: pass}
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
-               u.SetPassword(pass)
-       }
-}
-
 func TestGetOrgRepositoryIDs(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       user4 := unittest.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
-       user5 := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+       user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
+       user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
 
-       accessibleRepos, err := user2.GetOrgRepositoryIDs()
+       accessibleRepos, err := GetOrgRepositoryIDs(user2)
        assert.NoError(t, err)
        // User 2's team has access to private repos 3, 5, repo 32 is a public repo of the organization
        assert.Equal(t, []int64{3, 5, 23, 24, 32}, accessibleRepos)
 
-       accessibleRepos, err = user4.GetOrgRepositoryIDs()
+       accessibleRepos, err = GetOrgRepositoryIDs(user4)
        assert.NoError(t, err)
        // User 4's team has access to private repo 3, repo 32 is a public repo of the organization
        assert.Equal(t, []int64{3, 32}, accessibleRepos)
 
-       accessibleRepos, err = user5.GetOrgRepositoryIDs()
+       accessibleRepos, err = GetOrgRepositoryIDs(user5)
        assert.NoError(t, err)
        // User 5's team has no access to any repo
        assert.Len(t, accessibleRepos, 0)
 }
 
-func TestNewGitSig(t *testing.T) {
-       users := make([]*User, 0, 20)
-       err := db.GetEngine(db.DefaultContext).Find(&users)
-       assert.NoError(t, err)
-
-       for _, user := range users {
-               sig := user.NewGitSig()
-               assert.NotContains(t, sig.Name, "<")
-               assert.NotContains(t, sig.Name, ">")
-               assert.NotContains(t, sig.Name, "\n")
-               assert.NotEqual(t, len(strings.TrimSpace(sig.Name)), 0)
-       }
-}
-
-func TestDisplayName(t *testing.T) {
-       users := make([]*User, 0, 20)
-       err := db.GetEngine(db.DefaultContext).Find(&users)
-       assert.NoError(t, err)
-
-       for _, user := range users {
-               displayName := user.DisplayName()
-               assert.Equal(t, strings.TrimSpace(displayName), displayName)
-               if len(strings.TrimSpace(user.FullName)) == 0 {
-                       assert.Equal(t, user.Name, displayName)
-               }
-               assert.NotEqual(t, len(strings.TrimSpace(displayName)), 0)
-       }
-}
-
-func TestCreateUserInvalidEmail(t *testing.T) {
-       user := &User{
-               Name:               "GiteaBot",
-               Email:              "GiteaBot@gitea.io\r\n",
-               Passwd:             ";p['////..-++']",
-               IsAdmin:            false,
-               Theme:              setting.UI.DefaultTheme,
-               MustChangePassword: false,
-       }
-
-       err := CreateUser(user)
-       assert.Error(t, err)
-       assert.True(t, user_model.IsErrEmailInvalid(err))
-}
-
-func TestGetUserIDsByNames(t *testing.T) {
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       // ignore non existing
-       IDs, err := GetUserIDsByNames([]string{"user1", "user2", "none_existing_user"}, true)
-       assert.NoError(t, err)
-       assert.Equal(t, []int64{1, 2}, IDs)
-
-       // ignore non existing
-       IDs, err = GetUserIDsByNames([]string{"user1", "do_not_exist"}, false)
-       assert.Error(t, err)
-       assert.Equal(t, []int64(nil), IDs)
-}
-
-func TestGetMaileableUsersByIDs(t *testing.T) {
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       results, err := GetMaileableUsersByIDs([]int64{1, 4}, false)
-       assert.NoError(t, err)
-       assert.Len(t, results, 1)
-       if len(results) > 1 {
-               assert.Equal(t, results[0].ID, 1)
-       }
-
-       results, err = GetMaileableUsersByIDs([]int64{1, 4}, true)
-       assert.NoError(t, err)
-       assert.Len(t, results, 2)
-       if len(results) > 2 {
-               assert.Equal(t, results[0].ID, 1)
-               assert.Equal(t, results[1].ID, 4)
-       }
-}
-
 func TestAddLdapSSHPublicKeys(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        s := &login.Source{ID: 1}
 
        testCases := []struct {
@@ -415,118 +189,3 @@ ssh-dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x/DZuYAz3ib
                }
        }
 }
-
-func TestUpdateUser(t *testing.T) {
-       assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-
-       user.KeepActivityPrivate = true
-       assert.NoError(t, UpdateUser(user))
-       user = unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       assert.True(t, user.KeepActivityPrivate)
-
-       setting.Service.AllowedUserVisibilityModesSlice = []bool{true, false, false}
-       user.KeepActivityPrivate = false
-       user.Visibility = structs.VisibleTypePrivate
-       assert.Error(t, UpdateUser(user))
-       user = unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       assert.True(t, user.KeepActivityPrivate)
-
-       user.Email = "no mail@mail.org"
-       assert.Error(t, UpdateUser(user))
-}
-
-func TestNewUserRedirect(t *testing.T) {
-       // redirect to a completely new name
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
-       assert.NoError(t, user_model.NewUserRedirect(db.DefaultContext, user.ID, user.Name, "newusername"))
-
-       unittest.AssertExistsAndLoadBean(t, &user_model.Redirect{
-               LowerName:      user.LowerName,
-               RedirectUserID: user.ID,
-       })
-       unittest.AssertExistsAndLoadBean(t, &user_model.Redirect{
-               LowerName:      "olduser1",
-               RedirectUserID: user.ID,
-       })
-}
-
-func TestNewUserRedirect2(t *testing.T) {
-       // redirect to previously used name
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
-       assert.NoError(t, user_model.NewUserRedirect(db.DefaultContext, user.ID, user.Name, "olduser1"))
-
-       unittest.AssertExistsAndLoadBean(t, &user_model.Redirect{
-               LowerName:      user.LowerName,
-               RedirectUserID: user.ID,
-       })
-       unittest.AssertNotExistsBean(t, &user_model.Redirect{
-               LowerName:      "olduser1",
-               RedirectUserID: user.ID,
-       })
-}
-
-func TestNewUserRedirect3(t *testing.T) {
-       // redirect for a previously-unredirected user
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-       assert.NoError(t, user_model.NewUserRedirect(db.DefaultContext, user.ID, user.Name, "newusername"))
-
-       unittest.AssertExistsAndLoadBean(t, &user_model.Redirect{
-               LowerName:      user.LowerName,
-               RedirectUserID: user.ID,
-       })
-}
-
-func TestFollowUser(t *testing.T) {
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       testSuccess := func(followerID, followedID int64) {
-               assert.NoError(t, user_model.FollowUser(followerID, followedID))
-               unittest.AssertExistsAndLoadBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
-       }
-       testSuccess(4, 2)
-       testSuccess(5, 2)
-
-       assert.NoError(t, user_model.FollowUser(2, 2))
-
-       unittest.CheckConsistencyFor(t, &User{})
-}
-
-func TestUnfollowUser(t *testing.T) {
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       testSuccess := func(followerID, followedID int64) {
-               assert.NoError(t, user_model.UnfollowUser(followerID, followedID))
-               unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
-       }
-       testSuccess(4, 2)
-       testSuccess(5, 2)
-       testSuccess(2, 2)
-
-       unittest.CheckConsistencyFor(t, &User{})
-}
-
-func TestGetUserByOpenID(t *testing.T) {
-       assert.NoError(t, unittest.PrepareTestDatabase())
-
-       _, err := GetUserByOpenID("https://unknown")
-       if assert.Error(t, err) {
-               assert.True(t, IsErrUserNotExist(err))
-       }
-
-       user, err := GetUserByOpenID("https://user1.domain1.tld")
-       if assert.NoError(t, err) {
-               assert.Equal(t, int64(1), user.ID)
-       }
-
-       user, err = GetUserByOpenID("https://domain1.tld/user2/")
-       if assert.NoError(t, err) {
-               assert.Equal(t, int64(2), user.ID)
-       }
-}
index aebdb4f48c253455f737d90d062ccc97529b9c36..ae39de3da42fa06f85eddcb8eb91bccdd0e020ba 100644 (file)
@@ -9,12 +9,13 @@ import (
 
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/login"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
 )
 
 // UserList is a list of user.
 // This type provide valuable methods to retrieve information for a group of users efficiently.
-type UserList []*User
+type UserList []*user_model.User
 
 func (users UserList) getUserIDs() []int64 {
        userIDs := make([]int64, len(users))
@@ -95,3 +96,15 @@ func (users UserList) loadTwoFactorStatus(e db.Engine) (map[int64]*login.TwoFact
        }
        return tokenMaps, nil
 }
+
+// GetUsersByIDs returns all resolved users from a list of Ids.
+func GetUsersByIDs(ids []int64) (UserList, error) {
+       ous := make([]*user_model.User, 0, len(ids))
+       if len(ids) == 0 {
+               return ous, nil
+       }
+       err := db.GetEngine(db.DefaultContext).In("id", ids).
+               Asc("name").
+               Find(&ous)
+       return ous, err
+}
index beab48d45ada7facc4c2ea6547040943296cfd16..f80696542e60650f97f5feb5961e5ef0a0977ea5 100644 (file)
@@ -9,6 +9,7 @@ import (
        "path/filepath"
        "strings"
 
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/util"
 )
@@ -20,7 +21,7 @@ func (repo *Repository) WikiCloneLink() *CloneLink {
 
 // WikiPath returns wiki data path by given user and repository name.
 func WikiPath(userName, repoName string) string {
-       return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".wiki.git")
+       return filepath.Join(user_model.UserPath(userName), strings.ToLower(repoName)+".wiki.git")
 }
 
 // WikiPath returns wiki data path for given repository.
index 6fc4c7261ae92dc1aade2df92fc146876f2ffcf7..5a37f8b0bf2a90c35b3f49889797badc425c3f5e 100644 (file)
@@ -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
        }
index d4159a32a7abc3b27f55f6cce8e8ee31308dfbcf..2a3ebdd1e732140786e40290826f75f788089096 100644 (file)
@@ -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) {
index 1f1a035267e107636dd453f39ee802915e86619b..7feaad4ccd52010421f23c031a44a4e76df76e0c 100644 (file)
@@ -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
index 4229e6cc7d8cb584e59b0a0f3f835b775ec29fb2..f08a62588ee6ffc570e028e021d01d254f765ffe 100644 (file)
@@ -33,7 +33,7 @@ func ToEmail(email *user_model.EmailAddress) *api.Email {
 }
 
 // ToBranch convert a git.Commit and git.Branch to an api.Branch
-func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *models.User, isRepoAdmin bool) (*api.Branch, error) {
+func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) {
        if bp == nil {
                var hasPerm bool
                var err error
@@ -83,15 +83,15 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.
 
 // ToBranchProtection convert a ProtectedBranch to api.BranchProtection
 func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection {
-       pushWhitelistUsernames, err := models.GetUserNamesByIDs(bp.WhitelistUserIDs)
+       pushWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.WhitelistUserIDs)
        if err != nil {
                log.Error("GetUserNamesByIDs (WhitelistUserIDs): %v", err)
        }
-       mergeWhitelistUsernames, err := models.GetUserNamesByIDs(bp.MergeWhitelistUserIDs)
+       mergeWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.MergeWhitelistUserIDs)
        if err != nil {
                log.Error("GetUserNamesByIDs (MergeWhitelistUserIDs): %v", err)
        }
-       approvalsWhitelistUsernames, err := models.GetUserNamesByIDs(bp.ApprovalsWhitelistUserIDs)
+       approvalsWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.ApprovalsWhitelistUserIDs)
        if err != nil {
                log.Error("GetUserNamesByIDs (ApprovalsWhitelistUserIDs): %v", err)
        }
@@ -276,7 +276,7 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
        }
 }
 
-// ToOrganization convert models.User to api.Organization
+// ToOrganization convert user_model.User to api.Organization
 func ToOrganization(org *models.Organization) *api.Organization {
        return &api.Organization{
                ID:                        org.ID,
@@ -355,12 +355,16 @@ func ToOAuth2Application(app *login.OAuth2Application) *api.OAuth2Application {
 
 // ToLFSLock convert a LFSLock to api.LFSLock
 func ToLFSLock(l *models.LFSLock) *api.LFSLock {
+       u, err := user_model.GetUserByID(l.OwnerID)
+       if err != nil {
+               return nil
+       }
        return &api.LFSLock{
                ID:       strconv.FormatInt(l.ID, 10),
                Path:     l.Path,
                LockedAt: l.Created.Round(time.Second),
                Owner: &api.LFSLockOwner{
-                       Name: l.Owner.DisplayName(),
+                       Name: u.DisplayName(),
                },
        }
 }
index 9905b51fe4532b8d16b3e3ab96e5c6afad29e0d4..3148d880ff4eb8d83bf2d4f95b677c7f14a3a8ac 100644 (file)
@@ -9,6 +9,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        api "code.gitea.io/gitea/modules/structs"
@@ -38,16 +39,16 @@ func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta {
 // ToPayloadCommit convert a git.Commit to api.PayloadCommit
 func ToPayloadCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit {
        authorUsername := ""
-       if author, err := models.GetUserByEmail(c.Author.Email); err == nil {
+       if author, err := user_model.GetUserByEmail(c.Author.Email); err == nil {
                authorUsername = author.Name
-       } else if !models.IsErrUserNotExist(err) {
+       } else if !user_model.IsErrUserNotExist(err) {
                log.Error("GetUserByEmail: %v", err)
        }
 
        committerUsername := ""
-       if committer, err := models.GetUserByEmail(c.Committer.Email); err == nil {
+       if committer, err := user_model.GetUserByEmail(c.Committer.Email); err == nil {
                committerUsername = committer.Name
-       } else if !models.IsErrUserNotExist(err) {
+       } else if !user_model.IsErrUserNotExist(err) {
                log.Error("GetUserByEmail: %v", err)
        }
 
@@ -71,16 +72,16 @@ func ToPayloadCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit
 }
 
 // ToCommit convert a git.Commit to api.Commit
-func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]*models.User) (*api.Commit, error) {
+func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]*user_model.User) (*api.Commit, error) {
 
        var apiAuthor, apiCommitter *api.User
 
        // Retrieve author and committer information
 
-       var cacheAuthor *models.User
+       var cacheAuthor *user_model.User
        var ok bool
        if userCache == nil {
-               cacheAuthor = (*models.User)(nil)
+               cacheAuthor = (*user_model.User)(nil)
                ok = false
        } else {
                cacheAuthor, ok = userCache[commit.Author.Email]
@@ -89,8 +90,8 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
        if ok {
                apiAuthor = ToUser(cacheAuthor, nil)
        } else {
-               author, err := models.GetUserByEmail(commit.Author.Email)
-               if err != nil && !models.IsErrUserNotExist(err) {
+               author, err := user_model.GetUserByEmail(commit.Author.Email)
+               if err != nil && !user_model.IsErrUserNotExist(err) {
                        return nil, err
                } else if err == nil {
                        apiAuthor = ToUser(author, nil)
@@ -100,9 +101,9 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
                }
        }
 
-       var cacheCommitter *models.User
+       var cacheCommitter *user_model.User
        if userCache == nil {
-               cacheCommitter = (*models.User)(nil)
+               cacheCommitter = (*user_model.User)(nil)
                ok = false
        } else {
                cacheCommitter, ok = userCache[commit.Committer.Email]
@@ -111,8 +112,8 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
        if ok {
                apiCommitter = ToUser(cacheCommitter, nil)
        } else {
-               committer, err := models.GetUserByEmail(commit.Committer.Email)
-               if err != nil && !models.IsErrUserNotExist(err) {
+               committer, err := user_model.GetUserByEmail(commit.Committer.Email)
+               if err != nil && !user_model.IsErrUserNotExist(err) {
                        return nil, err
                } else if err == nil {
                        apiCommitter = ToUser(committer, nil)
index 7363cfb8fb8924dc9fcc4bffce63ab4b7ddb1dc8..c67ff5427f92c5d9fbfe328c7b6afb552911f3c4 100644 (file)
@@ -10,6 +10,7 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
@@ -175,7 +176,7 @@ func ToTrackedTimeList(tl models.TrackedTimeList) api.TrackedTimeList {
 }
 
 // ToLabel converts Label to API format
-func ToLabel(label *models.Label, repo *models.Repository, org *models.User) *api.Label {
+func ToLabel(label *models.Label, repo *models.Repository, org *user_model.User) *api.Label {
        result := &api.Label{
                ID:          label.ID,
                Name:        label.Name,
@@ -202,7 +203,7 @@ func ToLabel(label *models.Label, repo *models.Repository, org *models.User) *ap
 }
 
 // ToLabelList converts list of Label to API format
-func ToLabelList(labels []*models.Label, repo *models.Repository, org *models.User) []*api.Label {
+func ToLabelList(labels []*models.Label, repo *models.Repository, org *user_model.User) []*api.Label {
        result := make([]*api.Label, len(labels))
        for i := range labels {
                result[i] = ToLabel(labels[i], repo, org)
index 0f2b5af1b41f20f7962fad3e95e9d11856af7d5e..f892107f4b0ee5ae43b2a5e757df15273acc6568 100644 (file)
@@ -8,6 +8,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        api "code.gitea.io/gitea/modules/structs"
@@ -16,7 +17,7 @@ import (
 // ToAPIPullRequest assumes following fields have been assigned with valid values:
 // Required - Issue
 // Optional - Merger
-func ToAPIPullRequest(pr *models.PullRequest, doer *models.User) *api.PullRequest {
+func ToAPIPullRequest(pr *models.PullRequest, doer *user_model.User) *api.PullRequest {
        var (
                baseBranch *git.Branch
                headBranch *git.Branch
index b461b27b5abb07f9d8e481f2e9b9cce8c28c50f0..b99d7bead6ccd5e3df5ed4c2940b32a59c3eeca0 100644 (file)
@@ -8,16 +8,17 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 )
 
 // ToPullReview convert a review to api format
-func ToPullReview(r *models.Review, doer *models.User) (*api.PullReview, error) {
+func ToPullReview(r *models.Review, doer *user_model.User) (*api.PullReview, error) {
        if err := r.LoadAttributes(); err != nil {
-               if !models.IsErrUserNotExist(err) {
+               if !user_model.IsErrUserNotExist(err) {
                        return nil, err
                }
-               r.Reviewer = models.NewGhostUser()
+               r.Reviewer = user_model.NewGhostUser()
        }
 
        result := &api.PullReview{
@@ -53,7 +54,7 @@ func ToPullReview(r *models.Review, doer *models.User) (*api.PullReview, error)
 }
 
 // ToPullReviewList convert a list of review to it's api format
-func ToPullReviewList(rl []*models.Review, doer *models.User) ([]*api.PullReview, error) {
+func ToPullReviewList(rl []*models.Review, doer *user_model.User) ([]*api.PullReview, error) {
        result := make([]*api.PullReview, 0, len(rl))
        for i := range rl {
                // show pending reviews only for the user who created them
@@ -70,12 +71,12 @@ func ToPullReviewList(rl []*models.Review, doer *models.User) ([]*api.PullReview
 }
 
 // ToPullReviewCommentList convert the CodeComments of an review to it's api format
-func ToPullReviewCommentList(review *models.Review, doer *models.User) ([]*api.PullReviewComment, error) {
+func ToPullReviewCommentList(review *models.Review, doer *user_model.User) ([]*api.PullReviewComment, error) {
        if err := review.LoadAttributes(); err != nil {
-               if !models.IsErrUserNotExist(err) {
+               if !user_model.IsErrUserNotExist(err) {
                        return nil, err
                }
-               review.Reviewer = models.NewGhostUser()
+               review.Reviewer = user_model.NewGhostUser()
        }
 
        apiComments := make([]*api.PullReviewComment, 0, len(review.CodeComments))
index bb2f964fe441d6bd520109c966f4bacf178bf7cc..eb77c14dab33f4b1e8194706c900175e7dd2531f 100644 (file)
@@ -6,6 +6,7 @@ package convert
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 )
 
@@ -23,7 +24,7 @@ func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus {
        }
 
        if status.CreatorID != 0 {
-               creator, _ := models.GetUserByID(status.CreatorID)
+               creator, _ := user_model.GetUserByID(status.CreatorID)
                apiStatus.Creator = ToUser(creator, nil)
        }
 
index 3f17ae4b4d5d27d2f7be21168b8b0873eb881939..ebe2f06460566020c844e975d581b70d30a4169c 100644 (file)
@@ -6,12 +6,13 @@ package convert
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 )
 
-// ToUser convert models.User to api.User
+// ToUser convert user_model.User to api.User
 // if doer is set, private information is added if the doer has the permission to see it
-func ToUser(user, doer *models.User) *api.User {
+func ToUser(user, doer *user_model.User) *api.User {
        if user == nil {
                return nil
        }
@@ -24,8 +25,8 @@ func ToUser(user, doer *models.User) *api.User {
        return toUser(user, signed, authed)
 }
 
-// ToUsers convert list of models.User to list of api.User
-func ToUsers(doer *models.User, users []*models.User) []*api.User {
+// ToUsers convert list of user_model.User to list of api.User
+func ToUsers(doer *user_model.User, users []*user_model.User) []*api.User {
        result := make([]*api.User, len(users))
        for i := range users {
                result[i] = ToUser(users[i], doer)
@@ -33,18 +34,18 @@ func ToUsers(doer *models.User, users []*models.User) []*api.User {
        return result
 }
 
-// ToUserWithAccessMode convert models.User to api.User
+// ToUserWithAccessMode convert user_model.User to api.User
 // AccessMode is not none show add some more information
-func ToUserWithAccessMode(user *models.User, accessMode models.AccessMode) *api.User {
+func ToUserWithAccessMode(user *user_model.User, accessMode models.AccessMode) *api.User {
        if user == nil {
                return nil
        }
        return toUser(user, accessMode != models.AccessModeNone, false)
 }
 
-// toUser convert models.User to api.User
+// toUser convert user_model.User to api.User
 // signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself
-func toUser(user *models.User, signed, authed bool) *api.User {
+func toUser(user *user_model.User, signed, authed bool) *api.User {
        result := &api.User{
                ID:          user.ID,
                UserName:    user.Name,
@@ -81,7 +82,7 @@ func toUser(user *models.User, signed, authed bool) *api.User {
 }
 
 // User2UserSettings return UserSettings based on a user
-func User2UserSettings(user *models.User) api.UserSettings {
+func User2UserSettings(user *user_model.User) api.UserSettings {
        return api.UserSettings{
                FullName:      user.FullName,
                Website:       user.Website,
index ce174e30766d027368bb8ae758ac742f86f4613d..2ed962950fffa630fd8a1b2f974e527061c9278e 100644 (file)
@@ -7,8 +7,8 @@ package convert
 import (
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        api "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -17,13 +17,13 @@ import (
 func TestUser_ToUser(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user1 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
+       user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1, IsAdmin: true}).(*user_model.User)
 
        apiUser := toUser(user1, true, true)
        assert.True(t, apiUser.IsAdmin)
        assert.Contains(t, apiUser.AvatarURL, "://")
 
-       user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2, IsAdmin: false}).(*models.User)
+       user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2, IsAdmin: false}).(*user_model.User)
 
        apiUser = toUser(user2, true, true)
        assert.False(t, apiUser.IsAdmin)
@@ -32,7 +32,7 @@ func TestUser_ToUser(t *testing.T) {
        assert.False(t, apiUser.IsAdmin)
        assert.EqualValues(t, api.VisibleTypePublic.String(), apiUser.Visibility)
 
-       user31 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}).(*models.User)
+       user31 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}).(*user_model.User)
 
        apiUser = toUser(user31, true, true)
        assert.False(t, apiUser.IsAdmin)
index 2f748bcb718703aa70f6e8e9081bd36152eb5349..1cf8024b983b69a0ffeea8042e4d640bdf2f41b2 100644 (file)
@@ -13,6 +13,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/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/repository"
@@ -134,7 +135,7 @@ func checkDaemonExport(logger log.Logger, autofix bool) error {
                numRepos++
 
                if owner, has := cache.Get(repo.OwnerID); has {
-                       repo.Owner = owner.(*models.User)
+                       repo.Owner = owner.(*user_model.User)
                } else {
                        if err := repo.GetOwner(); err != nil {
                                return err
index 95f761742ea4e2f6b57b7eed1a069a621767111d..d7d198e01c7e7d17dff6100512a21b7c33835a7c 100644 (file)
@@ -11,6 +11,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/git"
        "code.gitea.io/gitea/modules/log"
 )
@@ -91,7 +92,7 @@ func (graph *Graph) LoadAndProcessCommits(repository *models.Repository, gitRepo
 
        var ok bool
 
-       emails := map[string]*models.User{}
+       emails := map[string]*user_model.User{}
        keyMap := map[string]bool{}
 
        for _, c := range graph.Commits {
@@ -106,7 +107,7 @@ func (graph *Graph) LoadAndProcessCommits(repository *models.Repository, gitRepo
                if c.Commit.Author != nil {
                        email := c.Commit.Author.Email
                        if c.User, ok = emails[email]; !ok {
-                               c.User, _ = models.GetUserByEmail(email)
+                               c.User, _ = user_model.GetUserByEmail(email)
                                emails[email] = c.User
                        }
                }
@@ -233,7 +234,7 @@ func newRefsFromRefNames(refNames []byte) []git.Reference {
 // Commit represents a commit at co-ordinate X, Y with the data
 type Commit struct {
        Commit       *git.Commit
-       User         *models.User
+       User         *user_model.User
        Verification *models.CommitVerification
        Status       *models.CommitStatus
        Flow         int64
index 4e133b4dd39310095956e70d9069a01760de3480..0b855460bd4eda35954d4e0d634a550244f54d46 100644 (file)
@@ -243,7 +243,7 @@ func populateIssueIndexer(ctx context.Context) {
                }
                repos, _, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
                        ListOptions: db.ListOptions{Page: page, PageSize: models.RepositoryListDefaultPageSize},
-                       OrderBy:     models.SearchOrderByID,
+                       OrderBy:     db.SearchOrderByID,
                        Private:     true,
                        Collaborate: util.OptionalBoolFalse,
                })
index 772e7be13705d67ac2569d49d6a823c9b366a6e0..80f97ad9932c946c1bb0034a0ec1d08d7cd3beb6 100644 (file)
@@ -10,6 +10,7 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/json"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/notification/base"
@@ -29,7 +30,7 @@ func NewNotifier() base.Notifier {
        return &actionNotifier{}
 }
 
-func (a *actionNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.User) {
+func (a *actionNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) {
        if err := issue.LoadPoster(); err != nil {
                log.Error("issue.LoadPoster: %v", err)
                return
@@ -54,7 +55,7 @@ func (a *actionNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.
 }
 
 // NotifyIssueChangeStatus notifies close or reopen issue to notifiers
-func (a *actionNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) {
+func (a *actionNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) {
        // Compose comment action, could be plain comment, close or reopen issue/pull request.
        // This object will be used to notify watchers in the end of function.
        act := &models.Action{
@@ -87,8 +88,8 @@ func (a *actionNotifier) NotifyIssueChangeStatus(doer *models.User, issue *model
 }
 
 // NotifyCreateIssueComment notifies comment on an issue to notifiers
-func (a *actionNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
-       issue *models.Issue, comment *models.Comment, mentions []*models.User) {
+func (a *actionNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository,
+       issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
        act := &models.Action{
                ActUserID: doer.ID,
                ActUser:   doer,
@@ -120,7 +121,7 @@ func (a *actionNotifier) NotifyCreateIssueComment(doer *models.User, repo *model
        }
 }
 
-func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions []*models.User) {
+func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions []*user_model.User) {
        if err := pull.LoadIssue(); err != nil {
                log.Error("pull.LoadIssue: %v", err)
                return
@@ -147,7 +148,7 @@ func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions
        }
 }
 
-func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) {
+func (a *actionNotifier) NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldRepoName string) {
        log.Trace("action.ChangeRepositoryName: %s/%s", doer.Name, repo.Name)
 
        if err := models.NotifyWatchers(&models.Action{
@@ -163,7 +164,7 @@ func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models.
        }
 }
 
-func (a *actionNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) {
+func (a *actionNotifier) NotifyTransferRepository(doer *user_model.User, repo *models.Repository, oldOwnerName string) {
        if err := models.NotifyWatchers(&models.Action{
                ActUserID: doer.ID,
                ActUser:   doer,
@@ -177,7 +178,7 @@ func (a *actionNotifier) NotifyTransferRepository(doer *models.User, repo *model
        }
 }
 
-func (a *actionNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
+func (a *actionNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) {
        if err := models.NotifyWatchers(&models.Action{
                ActUserID: doer.ID,
                ActUser:   doer,
@@ -190,7 +191,7 @@ func (a *actionNotifier) NotifyCreateRepository(doer *models.User, u *models.Use
        }
 }
 
-func (a *actionNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
+func (a *actionNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) {
        if err := models.NotifyWatchers(&models.Action{
                ActUserID: doer.ID,
                ActUser:   doer,
@@ -203,7 +204,7 @@ func (a *actionNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *
        }
 }
 
-func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*models.User) {
+func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*user_model.User) {
        if err := review.LoadReviewer(); err != nil {
                log.Error("LoadReviewer '%d/%d': %v", review.ID, review.ReviewerID, err)
                return
@@ -261,7 +262,7 @@ func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
        }
 }
 
-func (*actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
+func (*actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) {
        if err := models.NotifyWatchers(&models.Action{
                ActUserID: doer.ID,
                ActUser:   doer,
@@ -275,7 +276,7 @@ func (*actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mode
        }
 }
 
-func (*actionNotifier) NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) {
+func (*actionNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) {
        reviewerName := review.Reviewer.Name
        if len(review.OriginalAuthor) > 0 {
                reviewerName = review.OriginalAuthor
@@ -295,7 +296,7 @@ func (*actionNotifier) NotifyPullRevieweDismiss(doer *models.User, review *model
        }
 }
 
-func (a *actionNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (a *actionNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
        data, err := json.Marshal(commits)
        if err != nil {
                log.Error("Marshal: %v", err)
@@ -328,7 +329,7 @@ func (a *actionNotifier) NotifyPushCommits(pusher *models.User, repo *models.Rep
        }
 }
 
-func (a *actionNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
+func (a *actionNotifier) NotifyCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) {
        opType := models.ActionCommitRepo
        if refType == "tag" {
                // has sent same action in `NotifyPushCommits`, so skip it.
@@ -347,7 +348,7 @@ func (a *actionNotifier) NotifyCreateRef(doer *models.User, repo *models.Reposit
        }
 }
 
-func (a *actionNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
+func (a *actionNotifier) NotifyDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) {
        opType := models.ActionDeleteBranch
        if refType == "tag" {
                // has sent same action in `NotifyPushCommits`, so skip it.
@@ -366,7 +367,7 @@ func (a *actionNotifier) NotifyDeleteRef(doer *models.User, repo *models.Reposit
        }
 }
 
-func (a *actionNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (a *actionNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
        data, err := json.Marshal(commits)
        if err != nil {
                log.Error("json.Marshal: %v", err)
@@ -387,7 +388,7 @@ func (a *actionNotifier) NotifySyncPushCommits(pusher *models.User, repo *models
        }
 }
 
-func (a *actionNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
+func (a *actionNotifier) NotifySyncCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) {
        if err := models.NotifyWatchers(&models.Action{
                ActUserID: repo.OwnerID,
                ActUser:   repo.MustOwner(),
@@ -401,7 +402,7 @@ func (a *actionNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Rep
        }
 }
 
-func (a *actionNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
+func (a *actionNotifier) NotifySyncDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) {
        if err := models.NotifyWatchers(&models.Action{
                ActUserID: repo.OwnerID,
                ActUser:   repo.MustOwner(),
index 448242bcdfd37fd4cbe6afad793c5d55d41c011d..2218bd46cb2ca72a7c2fcfef3e13ef04a30795dc 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -22,7 +23,7 @@ func TestMain(m *testing.M) {
 func TestRenameRepoAction(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository)
        repo.Owner = user
 
index 8f8aa659b45d91e4de7ab661e586e5d34ba61d50..24f6375a69711f8cd6407f3b45f26d1858825faa 100644 (file)
@@ -6,6 +6,7 @@ package base
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/repository"
 )
 
@@ -13,50 +14,50 @@ import (
 type Notifier interface {
        Run()
 
-       NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository)
-       NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository)
-       NotifyDeleteRepository(doer *models.User, repo *models.Repository)
-       NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository)
-       NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string)
-       NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string)
-
-       NotifyNewIssue(issue *models.Issue, mentions []*models.User)
-       NotifyIssueChangeStatus(*models.User, *models.Issue, *models.Comment, bool)
-       NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64)
-       NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment)
-       NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment)
-       NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string)
-       NotifyIssueClearLabels(doer *models.User, issue *models.Issue)
-       NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string)
-       NotifyIssueChangeRef(doer *models.User, issue *models.Issue, oldRef string)
-       NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
+       NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository)
+       NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository)
+       NotifyDeleteRepository(doer *user_model.User, repo *models.Repository)
+       NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository)
+       NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldRepoName string)
+       NotifyTransferRepository(doer *user_model.User, repo *models.Repository, oldOwnerName string)
+
+       NotifyNewIssue(issue *models.Issue, mentions []*user_model.User)
+       NotifyIssueChangeStatus(*user_model.User, *models.Issue, *models.Comment, bool)
+       NotifyIssueChangeMilestone(doer *user_model.User, issue *models.Issue, oldMilestoneID int64)
+       NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment)
+       NotifyPullReviewRequest(doer *user_model.User, issue *models.Issue, reviewer *user_model.User, isRequest bool, comment *models.Comment)
+       NotifyIssueChangeContent(doer *user_model.User, issue *models.Issue, oldContent string)
+       NotifyIssueClearLabels(doer *user_model.User, issue *models.Issue)
+       NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string)
+       NotifyIssueChangeRef(doer *user_model.User, issue *models.Issue, oldRef string)
+       NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue,
                addedLabels []*models.Label, removedLabels []*models.Label)
 
-       NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User)
-       NotifyMergePullRequest(*models.PullRequest, *models.User)
-       NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest)
-       NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*models.User)
-       NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*models.User)
-       NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string)
-       NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment)
-       NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment)
+       NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User)
+       NotifyMergePullRequest(*models.PullRequest, *user_model.User)
+       NotifyPullRequestSynchronized(doer *user_model.User, pr *models.PullRequest)
+       NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*user_model.User)
+       NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*user_model.User)
+       NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *models.PullRequest, oldBranch string)
+       NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment)
+       NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment)
 
-       NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
-               issue *models.Issue, comment *models.Comment, mentions []*models.User)
-       NotifyUpdateComment(*models.User, *models.Comment, string)
-       NotifyDeleteComment(*models.User, *models.Comment)
+       NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository,
+               issue *models.Issue, comment *models.Comment, mentions []*user_model.User)
+       NotifyUpdateComment(*user_model.User, *models.Comment, string)
+       NotifyDeleteComment(*user_model.User, *models.Comment)
 
        NotifyNewRelease(rel *models.Release)
-       NotifyUpdateRelease(doer *models.User, rel *models.Release)
-       NotifyDeleteRelease(doer *models.User, rel *models.Release)
+       NotifyUpdateRelease(doer *user_model.User, rel *models.Release)
+       NotifyDeleteRelease(doer *user_model.User, rel *models.Release)
 
-       NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
-       NotifyCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string)
-       NotifyDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string)
+       NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
+       NotifyCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string)
+       NotifyDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string)
 
-       NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
-       NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string)
-       NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string)
+       NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
+       NotifySyncCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string)
+       NotifySyncDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string)
 
-       NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository)
+       NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository)
 }
index 32fe259bca8d792a0342326f5944124c315c1bc4..8a977e122bdd9b03246fda0cddc9f88cb409ec96 100644 (file)
@@ -6,6 +6,7 @@ package base
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/repository"
 )
 
@@ -22,56 +23,56 @@ func (*NullNotifier) Run() {
 }
 
 // NotifyCreateIssueComment places a place holder function
-func (*NullNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
-       issue *models.Issue, comment *models.Comment, mentions []*models.User) {
+func (*NullNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository,
+       issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
 }
 
 // NotifyNewIssue places a place holder function
-func (*NullNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.User) {
+func (*NullNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) {
 }
 
 // NotifyIssueChangeStatus places a place holder function
-func (*NullNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
+func (*NullNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
 }
 
 // NotifyNewPullRequest places a place holder function
-func (*NullNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) {
+func (*NullNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) {
 }
 
 // NotifyPullRequestReview places a place holder function
-func (*NullNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment, mentions []*models.User) {
+func (*NullNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment, mentions []*user_model.User) {
 }
 
 // NotifyPullRequestCodeComment places a place holder function
-func (*NullNotifier) NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*models.User) {
+func (*NullNotifier) NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*user_model.User) {
 }
 
 // NotifyMergePullRequest places a place holder function
-func (*NullNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
+func (*NullNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) {
 }
 
 // NotifyPullRequestSynchronized places a place holder function
-func (*NullNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {
+func (*NullNotifier) NotifyPullRequestSynchronized(doer *user_model.User, pr *models.PullRequest) {
 }
 
 // NotifyPullRequestChangeTargetBranch places a place holder function
-func (*NullNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) {
+func (*NullNotifier) NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *models.PullRequest, oldBranch string) {
 }
 
 // NotifyPullRequestPushCommits notifies when push commits to pull request's head branch
-func (*NullNotifier) NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) {
+func (*NullNotifier) NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment) {
 }
 
 // NotifyPullRevieweDismiss notifies when a review was dismissed by repo admin
-func (*NullNotifier) NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) {
+func (*NullNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) {
 }
 
 // NotifyUpdateComment places a place holder function
-func (*NullNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
+func (*NullNotifier) NotifyUpdateComment(doer *user_model.User, c *models.Comment, oldContent string) {
 }
 
 // NotifyDeleteComment places a place holder function
-func (*NullNotifier) NotifyDeleteComment(doer *models.User, c *models.Comment) {
+func (*NullNotifier) NotifyDeleteComment(doer *user_model.User, c *models.Comment) {
 }
 
 // NotifyNewRelease places a place holder function
@@ -79,94 +80,94 @@ func (*NullNotifier) NotifyNewRelease(rel *models.Release) {
 }
 
 // NotifyUpdateRelease places a place holder function
-func (*NullNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
+func (*NullNotifier) NotifyUpdateRelease(doer *user_model.User, rel *models.Release) {
 }
 
 // NotifyDeleteRelease places a place holder function
-func (*NullNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {
+func (*NullNotifier) NotifyDeleteRelease(doer *user_model.User, rel *models.Release) {
 }
 
 // NotifyIssueChangeMilestone places a place holder function
-func (*NullNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) {
+func (*NullNotifier) NotifyIssueChangeMilestone(doer *user_model.User, issue *models.Issue, oldMilestoneID int64) {
 }
 
 // NotifyIssueChangeContent places a place holder function
-func (*NullNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
+func (*NullNotifier) NotifyIssueChangeContent(doer *user_model.User, issue *models.Issue, oldContent string) {
 }
 
 // NotifyIssueChangeAssignee places a place holder function
-func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
+func (*NullNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) {
 }
 
 // NotifyPullReviewRequest places a place holder function
-func (*NullNotifier) NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) {
+func (*NullNotifier) NotifyPullReviewRequest(doer *user_model.User, issue *models.Issue, reviewer *user_model.User, isRequest bool, comment *models.Comment) {
 }
 
 // NotifyIssueClearLabels places a place holder function
-func (*NullNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
+func (*NullNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *models.Issue) {
 }
 
 // NotifyIssueChangeTitle places a place holder function
-func (*NullNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
+func (*NullNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) {
 }
 
 // NotifyIssueChangeRef places a place holder function
-func (*NullNotifier) NotifyIssueChangeRef(doer *models.User, issue *models.Issue, oldTitle string) {
+func (*NullNotifier) NotifyIssueChangeRef(doer *user_model.User, issue *models.Issue, oldTitle string) {
 }
 
 // NotifyIssueChangeLabels places a place holder function
-func (*NullNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
+func (*NullNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue,
        addedLabels []*models.Label, removedLabels []*models.Label) {
 }
 
 // NotifyCreateRepository places a place holder function
-func (*NullNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
+func (*NullNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) {
 }
 
 // NotifyDeleteRepository places a place holder function
-func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
+func (*NullNotifier) NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) {
 }
 
 // NotifyForkRepository places a place holder function
-func (*NullNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
+func (*NullNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) {
 }
 
 // NotifyMigrateRepository places a place holder function
-func (*NullNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
+func (*NullNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) {
 }
 
 // NotifyPushCommits notifies commits pushed to notifiers
-func (*NullNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (*NullNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
 }
 
 // NotifyCreateRef notifies branch or tag creation to notifiers
-func (*NullNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
+func (*NullNotifier) NotifyCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) {
 }
 
 // NotifyDeleteRef notifies branch or tag deletion to notifiers
-func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
+func (*NullNotifier) NotifyDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) {
 }
 
 // NotifyRenameRepository places a place holder function
-func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) {
+func (*NullNotifier) NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldRepoName string) {
 }
 
 // NotifyTransferRepository places a place holder function
-func (*NullNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) {
+func (*NullNotifier) NotifyTransferRepository(doer *user_model.User, repo *models.Repository, oldOwnerName string) {
 }
 
 // NotifySyncPushCommits places a place holder function
-func (*NullNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (*NullNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
 }
 
 // NotifySyncCreateRef places a place holder function
-func (*NullNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
+func (*NullNotifier) NotifySyncCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) {
 }
 
 // NotifySyncDeleteRef places a place holder function
-func (*NullNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
+func (*NullNotifier) NotifySyncDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) {
 }
 
 // NotifyRepoPendingTransfer places a place holder function
-func (*NullNotifier) NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) {
+func (*NullNotifier) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) {
 }
index 109eb1f62d815c7af89620d64cb010bf6f86323e..03914db03b7d11dddf5b0f6290efd578cbdef74f 100644 (file)
@@ -6,6 +6,7 @@ package indexer
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        code_indexer "code.gitea.io/gitea/modules/indexer/code"
        issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
@@ -29,8 +30,8 @@ func NewNotifier() base.Notifier {
        return &indexerNotifier{}
 }
 
-func (r *indexerNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
-       issue *models.Issue, comment *models.Comment, mentions []*models.User) {
+func (r *indexerNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository,
+       issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
        if comment.Type == models.CommentTypeComment {
                if issue.Comments == nil {
                        if err := issue.LoadDiscussComments(); err != nil {
@@ -45,15 +46,15 @@ func (r *indexerNotifier) NotifyCreateIssueComment(doer *models.User, repo *mode
        }
 }
 
-func (r *indexerNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.User) {
+func (r *indexerNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) {
        issue_indexer.UpdateIssueIndexer(issue)
 }
 
-func (r *indexerNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) {
+func (r *indexerNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) {
        issue_indexer.UpdateIssueIndexer(pr.Issue)
 }
 
-func (r *indexerNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
+func (r *indexerNotifier) NotifyUpdateComment(doer *user_model.User, c *models.Comment, oldContent string) {
        if c.Type == models.CommentTypeComment {
                var found bool
                if c.Issue.Comments != nil {
@@ -77,7 +78,7 @@ func (r *indexerNotifier) NotifyUpdateComment(doer *models.User, c *models.Comme
        }
 }
 
-func (r *indexerNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) {
+func (r *indexerNotifier) NotifyDeleteComment(doer *user_model.User, comment *models.Comment) {
        if comment.Type == models.CommentTypeComment {
                if err := comment.LoadIssue(); err != nil {
                        log.Error("LoadIssue: %v", err)
@@ -106,14 +107,14 @@ func (r *indexerNotifier) NotifyDeleteComment(doer *models.User, comment *models
        }
 }
 
-func (r *indexerNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
+func (r *indexerNotifier) NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) {
        issue_indexer.DeleteRepoIssueIndexer(repo)
        if setting.Indexer.RepoIndexerEnabled {
                code_indexer.UpdateRepoIndexer(repo)
        }
 }
 
-func (r *indexerNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
+func (r *indexerNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) {
        issue_indexer.UpdateRepoIndexer(repo)
        if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty {
                code_indexer.UpdateRepoIndexer(repo)
@@ -123,7 +124,7 @@ func (r *indexerNotifier) NotifyMigrateRepository(doer *models.User, u *models.U
        }
 }
 
-func (r *indexerNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (r *indexerNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
        if setting.Indexer.RepoIndexerEnabled && opts.RefFullName == git.BranchPrefix+repo.DefaultBranch {
                code_indexer.UpdateRepoIndexer(repo)
        }
@@ -132,7 +133,7 @@ func (r *indexerNotifier) NotifyPushCommits(pusher *models.User, repo *models.Re
        }
 }
 
-func (r *indexerNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (r *indexerNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
        if setting.Indexer.RepoIndexerEnabled && opts.RefFullName == git.BranchPrefix+repo.DefaultBranch {
                code_indexer.UpdateRepoIndexer(repo)
        }
@@ -141,14 +142,14 @@ func (r *indexerNotifier) NotifySyncPushCommits(pusher *models.User, repo *model
        }
 }
 
-func (r *indexerNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
+func (r *indexerNotifier) NotifyIssueChangeContent(doer *user_model.User, issue *models.Issue, oldContent string) {
        issue_indexer.UpdateIssueIndexer(issue)
 }
 
-func (r *indexerNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
+func (r *indexerNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) {
        issue_indexer.UpdateIssueIndexer(issue)
 }
 
-func (r *indexerNotifier) NotifyIssueChangeRef(doer *models.User, issue *models.Issue, oldRef string) {
+func (r *indexerNotifier) NotifyIssueChangeRef(doer *user_model.User, issue *models.Issue, oldRef string) {
        issue_indexer.UpdateIssueIndexer(issue)
 }
index 5bfb0b3ef8bb3a0bf83ca963c8d3a220f262e800..c1c9e9613558c880aabd40407d7ee7b81fe122ee 100644 (file)
@@ -8,6 +8,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/notification/base"
        "code.gitea.io/gitea/services/mailer"
@@ -26,8 +27,8 @@ func NewNotifier() base.Notifier {
        return &mailNotifier{}
 }
 
-func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
-       issue *models.Issue, comment *models.Comment, mentions []*models.User) {
+func (m *mailNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository,
+       issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
        var act models.ActionType
        if comment.Type == models.CommentTypeClose {
                act = models.ActionCloseIssue
@@ -46,13 +47,13 @@ func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.
        }
 }
 
-func (m *mailNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.User) {
+func (m *mailNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) {
        if err := mailer.MailParticipants(issue, issue.Poster, models.ActionCreateIssue, mentions); err != nil {
                log.Error("MailParticipants: %v", err)
        }
 }
 
-func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
+func (m *mailNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
        var actionType models.ActionType
        if issue.IsPull {
                if isClosed {
@@ -73,7 +74,7 @@ func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.
        }
 }
 
-func (m *mailNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
+func (m *mailNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) {
        if err := issue.LoadPullRequest(); err != nil {
                log.Error("issue.LoadPullRequest: %v", err)
                return
@@ -85,13 +86,13 @@ func (m *mailNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.I
        }
 }
 
-func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) {
+func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) {
        if err := mailer.MailParticipants(pr.Issue, pr.Issue.Poster, models.ActionCreatePullRequest, mentions); err != nil {
                log.Error("MailParticipants: %v", err)
        }
 }
 
-func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment, mentions []*models.User) {
+func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment, mentions []*user_model.User) {
        var act models.ActionType
        if comment.Type == models.CommentTypeClose {
                act = models.ActionCloseIssue
@@ -105,32 +106,32 @@ func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models
        }
 }
 
-func (m *mailNotifier) NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*models.User) {
+func (m *mailNotifier) NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*user_model.User) {
        if err := mailer.MailMentionsComment(pr, comment, mentions); err != nil {
                log.Error("MailMentionsComment: %v", err)
        }
 }
 
-func (m *mailNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
+func (m *mailNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) {
        // mail only sent to added assignees and not self-assignee
-       if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() == models.EmailNotificationsEnabled {
+       if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() == user_model.EmailNotificationsEnabled {
                ct := fmt.Sprintf("Assigned #%d.", issue.Index)
-               if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*models.User{assignee}); err != nil {
+               if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*user_model.User{assignee}); err != nil {
                        log.Error("Error in SendIssueAssignedMail for issue[%d] to assignee[%d]: %v", issue.ID, assignee.ID, err)
                }
        }
 }
 
-func (m *mailNotifier) NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) {
-       if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() == models.EmailNotificationsEnabled {
+func (m *mailNotifier) NotifyPullReviewRequest(doer *user_model.User, issue *models.Issue, reviewer *user_model.User, isRequest bool, comment *models.Comment) {
+       if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() == user_model.EmailNotificationsEnabled {
                ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL())
-               if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*models.User{reviewer}); err != nil {
+               if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*user_model.User{reviewer}); err != nil {
                        log.Error("Error in SendIssueAssignedMail for issue[%d] to reviewer[%d]: %v", issue.ID, reviewer.ID, err)
                }
        }
 }
 
-func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
+func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) {
        if err := pr.LoadIssue(); err != nil {
                log.Error("pr.LoadIssue: %v", err)
                return
@@ -140,7 +141,7 @@ func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mode
        }
 }
 
-func (m *mailNotifier) NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) {
+func (m *mailNotifier) NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment) {
        var err error
        if err = comment.LoadIssue(); err != nil {
                log.Error("comment.LoadIssue: %v", err)
@@ -164,7 +165,7 @@ func (m *mailNotifier) NotifyPullRequestPushCommits(doer *models.User, pr *model
        m.NotifyCreateIssueComment(doer, comment.Issue.Repo, comment.Issue, comment, nil)
 }
 
-func (m *mailNotifier) NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) {
+func (m *mailNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) {
        if err := mailer.MailParticipantsComment(comment, models.ActionPullReviewDismissed, review.Issue, nil); err != nil {
                log.Error("MailParticipantsComment: %v", err)
        }
@@ -183,7 +184,7 @@ func (m *mailNotifier) NotifyNewRelease(rel *models.Release) {
        mailer.MailNewRelease(rel)
 }
 
-func (m *mailNotifier) NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) {
+func (m *mailNotifier) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) {
        if err := mailer.SendRepoTransferNotifyMail(doer, newOwner, repo); err != nil {
                log.Error("NotifyRepoPendingTransfer: %v", err)
        }
index b574f3ccda22562f1a4629a15396c679aab76c2c..9bea38faf6e3e21f2f42e523a4f5c5de367380fa 100644 (file)
@@ -6,6 +6,7 @@ package notification
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/notification/action"
        "code.gitea.io/gitea/modules/notification/base"
        "code.gitea.io/gitea/modules/notification/indexer"
@@ -38,92 +39,92 @@ func NewContext() {
 }
 
 // NotifyCreateIssueComment notifies issue comment related message to notifiers
-func NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
-       issue *models.Issue, comment *models.Comment, mentions []*models.User) {
+func NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository,
+       issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
        for _, notifier := range notifiers {
                notifier.NotifyCreateIssueComment(doer, repo, issue, comment, mentions)
        }
 }
 
 // NotifyNewIssue notifies new issue to notifiers
-func NotifyNewIssue(issue *models.Issue, mentions []*models.User) {
+func NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) {
        for _, notifier := range notifiers {
                notifier.NotifyNewIssue(issue, mentions)
        }
 }
 
 // NotifyIssueChangeStatus notifies close or reopen issue to notifiers
-func NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) {
+func NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) {
        for _, notifier := range notifiers {
                notifier.NotifyIssueChangeStatus(doer, issue, actionComment, closeOrReopen)
        }
 }
 
 // NotifyMergePullRequest notifies merge pull request to notifiers
-func NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
+func NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) {
        for _, notifier := range notifiers {
                notifier.NotifyMergePullRequest(pr, doer)
        }
 }
 
 // NotifyNewPullRequest notifies new pull request to notifiers
-func NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) {
+func NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) {
        for _, notifier := range notifiers {
                notifier.NotifyNewPullRequest(pr, mentions)
        }
 }
 
 // NotifyPullRequestSynchronized notifies Synchronized pull request
-func NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {
+func NotifyPullRequestSynchronized(doer *user_model.User, pr *models.PullRequest) {
        for _, notifier := range notifiers {
                notifier.NotifyPullRequestSynchronized(doer, pr)
        }
 }
 
 // NotifyPullRequestReview notifies new pull request review
-func NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*models.User) {
+func NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*user_model.User) {
        for _, notifier := range notifiers {
                notifier.NotifyPullRequestReview(pr, review, comment, mentions)
        }
 }
 
 // NotifyPullRequestCodeComment notifies new pull request code comment
-func NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*models.User) {
+func NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*user_model.User) {
        for _, notifier := range notifiers {
                notifier.NotifyPullRequestCodeComment(pr, comment, mentions)
        }
 }
 
 // NotifyPullRequestChangeTargetBranch notifies when a pull request's target branch was changed
-func NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) {
+func NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *models.PullRequest, oldBranch string) {
        for _, notifier := range notifiers {
                notifier.NotifyPullRequestChangeTargetBranch(doer, pr, oldBranch)
        }
 }
 
 // NotifyPullRequestPushCommits notifies when push commits to pull request's head branch
-func NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) {
+func NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment) {
        for _, notifier := range notifiers {
                notifier.NotifyPullRequestPushCommits(doer, pr, comment)
        }
 }
 
 // NotifyPullRevieweDismiss notifies when a review was dismissed by repo admin
-func NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) {
+func NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) {
        for _, notifier := range notifiers {
                notifier.NotifyPullRevieweDismiss(doer, review, comment)
        }
 }
 
 // NotifyUpdateComment notifies update comment to notifiers
-func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
+func NotifyUpdateComment(doer *user_model.User, c *models.Comment, oldContent string) {
        for _, notifier := range notifiers {
                notifier.NotifyUpdateComment(doer, c, oldContent)
        }
 }
 
 // NotifyDeleteComment notifies delete comment to notifiers
-func NotifyDeleteComment(doer *models.User, c *models.Comment) {
+func NotifyDeleteComment(doer *user_model.User, c *models.Comment) {
        for _, notifier := range notifiers {
                notifier.NotifyDeleteComment(doer, c)
        }
@@ -137,70 +138,70 @@ func NotifyNewRelease(rel *models.Release) {
 }
 
 // NotifyUpdateRelease notifies update release to notifiers
-func NotifyUpdateRelease(doer *models.User, rel *models.Release) {
+func NotifyUpdateRelease(doer *user_model.User, rel *models.Release) {
        for _, notifier := range notifiers {
                notifier.NotifyUpdateRelease(doer, rel)
        }
 }
 
 // NotifyDeleteRelease notifies delete release to notifiers
-func NotifyDeleteRelease(doer *models.User, rel *models.Release) {
+func NotifyDeleteRelease(doer *user_model.User, rel *models.Release) {
        for _, notifier := range notifiers {
                notifier.NotifyDeleteRelease(doer, rel)
        }
 }
 
 // NotifyIssueChangeMilestone notifies change milestone to notifiers
-func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) {
+func NotifyIssueChangeMilestone(doer *user_model.User, issue *models.Issue, oldMilestoneID int64) {
        for _, notifier := range notifiers {
                notifier.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
        }
 }
 
 // NotifyIssueChangeContent notifies change content to notifiers
-func NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
+func NotifyIssueChangeContent(doer *user_model.User, issue *models.Issue, oldContent string) {
        for _, notifier := range notifiers {
                notifier.NotifyIssueChangeContent(doer, issue, oldContent)
        }
 }
 
 // NotifyIssueChangeAssignee notifies change content to notifiers
-func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
+func NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) {
        for _, notifier := range notifiers {
                notifier.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment)
        }
 }
 
 // NotifyPullReviewRequest notifies Request Review change
-func NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) {
+func NotifyPullReviewRequest(doer *user_model.User, issue *models.Issue, reviewer *user_model.User, isRequest bool, comment *models.Comment) {
        for _, notifier := range notifiers {
                notifier.NotifyPullReviewRequest(doer, issue, reviewer, isRequest, comment)
        }
 }
 
 // NotifyIssueClearLabels notifies clear labels to notifiers
-func NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
+func NotifyIssueClearLabels(doer *user_model.User, issue *models.Issue) {
        for _, notifier := range notifiers {
                notifier.NotifyIssueClearLabels(doer, issue)
        }
 }
 
 // NotifyIssueChangeTitle notifies change title to notifiers
-func NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
+func NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) {
        for _, notifier := range notifiers {
                notifier.NotifyIssueChangeTitle(doer, issue, oldTitle)
        }
 }
 
 // NotifyIssueChangeRef notifies change reference to notifiers
-func NotifyIssueChangeRef(doer *models.User, issue *models.Issue, oldRef string) {
+func NotifyIssueChangeRef(doer *user_model.User, issue *models.Issue, oldRef string) {
        for _, notifier := range notifiers {
                notifier.NotifyIssueChangeRef(doer, issue, oldRef)
        }
 }
 
 // NotifyIssueChangeLabels notifies change labels to notifiers
-func NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
+func NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue,
        addedLabels []*models.Label, removedLabels []*models.Label) {
        for _, notifier := range notifiers {
                notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels)
@@ -208,91 +209,91 @@ func NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
 }
 
 // NotifyCreateRepository notifies create repository to notifiers
-func NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
+func NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) {
        for _, notifier := range notifiers {
                notifier.NotifyCreateRepository(doer, u, repo)
        }
 }
 
 // NotifyMigrateRepository notifies create repository to notifiers
-func NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
+func NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) {
        for _, notifier := range notifiers {
                notifier.NotifyMigrateRepository(doer, u, repo)
        }
 }
 
 // NotifyTransferRepository notifies create repository to notifiers
-func NotifyTransferRepository(doer *models.User, repo *models.Repository, newOwnerName string) {
+func NotifyTransferRepository(doer *user_model.User, repo *models.Repository, newOwnerName string) {
        for _, notifier := range notifiers {
                notifier.NotifyTransferRepository(doer, repo, newOwnerName)
        }
 }
 
 // NotifyDeleteRepository notifies delete repository to notifiers
-func NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
+func NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) {
        for _, notifier := range notifiers {
                notifier.NotifyDeleteRepository(doer, repo)
        }
 }
 
 // NotifyForkRepository notifies fork repository to notifiers
-func NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
+func NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) {
        for _, notifier := range notifiers {
                notifier.NotifyForkRepository(doer, oldRepo, repo)
        }
 }
 
 // NotifyRenameRepository notifies repository renamed
-func NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
+func NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldName string) {
        for _, notifier := range notifiers {
                notifier.NotifyRenameRepository(doer, repo, oldName)
        }
 }
 
 // NotifyPushCommits notifies commits pushed to notifiers
-func NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
        for _, notifier := range notifiers {
                notifier.NotifyPushCommits(pusher, repo, opts, commits)
        }
 }
 
 // NotifyCreateRef notifies branch or tag creation to notifiers
-func NotifyCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
+func NotifyCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) {
        for _, notifier := range notifiers {
                notifier.NotifyCreateRef(pusher, repo, refType, refFullName)
        }
 }
 
 // NotifyDeleteRef notifies branch or tag deletion to notifiers
-func NotifyDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
+func NotifyDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) {
        for _, notifier := range notifiers {
                notifier.NotifyDeleteRef(pusher, repo, refType, refFullName)
        }
 }
 
 // NotifySyncPushCommits notifies commits pushed to notifiers
-func NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
        for _, notifier := range notifiers {
                notifier.NotifySyncPushCommits(pusher, repo, opts, commits)
        }
 }
 
 // NotifySyncCreateRef notifies branch or tag creation to notifiers
-func NotifySyncCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
+func NotifySyncCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) {
        for _, notifier := range notifiers {
                notifier.NotifySyncCreateRef(pusher, repo, refType, refFullName)
        }
 }
 
 // NotifySyncDeleteRef notifies branch or tag deletion to notifiers
-func NotifySyncDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
+func NotifySyncDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) {
        for _, notifier := range notifiers {
                notifier.NotifySyncDeleteRef(pusher, repo, refType, refFullName)
        }
 }
 
 // NotifyRepoPendingTransfer notifies creation of pending transfer to notifiers
-func NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) {
+func NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) {
        for _, notifier := range notifiers {
                notifier.NotifyRepoPendingTransfer(doer, newOwner, repo)
        }
index f372d6759ce2379cf1a01319f0e9622fd57699cb..04967fc5891573c9d4ae0b7916f379215ce9083c 100644 (file)
@@ -6,6 +6,7 @@ package ui
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/graceful"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/notification/base"
@@ -50,8 +51,8 @@ func (ns *notificationService) Run() {
        graceful.GetManager().RunWithShutdownFns(ns.issueQueue.Run)
 }
 
-func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
-       issue *models.Issue, comment *models.Comment, mentions []*models.User) {
+func (ns *notificationService) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository,
+       issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
        var opts = issueNotificationOpts{
                IssueID:              issue.ID,
                NotificationAuthorID: doer.ID,
@@ -73,7 +74,7 @@ func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo
        }
 }
 
-func (ns *notificationService) NotifyNewIssue(issue *models.Issue, mentions []*models.User) {
+func (ns *notificationService) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) {
        _ = ns.issueQueue.Push(issueNotificationOpts{
                IssueID:              issue.ID,
                NotificationAuthorID: issue.Poster.ID,
@@ -87,14 +88,14 @@ func (ns *notificationService) NotifyNewIssue(issue *models.Issue, mentions []*m
        }
 }
 
-func (ns *notificationService) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
+func (ns *notificationService) NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
        _ = ns.issueQueue.Push(issueNotificationOpts{
                IssueID:              issue.ID,
                NotificationAuthorID: doer.ID,
        })
 }
 
-func (ns *notificationService) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
+func (ns *notificationService) NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) {
        if err := issue.LoadPullRequest(); err != nil {
                log.Error("issue.LoadPullRequest: %v", err)
                return
@@ -107,14 +108,14 @@ func (ns *notificationService) NotifyIssueChangeTitle(doer *models.User, issue *
        }
 }
 
-func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
+func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) {
        _ = ns.issueQueue.Push(issueNotificationOpts{
                IssueID:              pr.Issue.ID,
                NotificationAuthorID: doer.ID,
        })
 }
 
-func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) {
+func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) {
        if err := pr.LoadIssue(); err != nil {
                log.Error("Unable to load issue: %d for pr: %d: Error: %v", pr.IssueID, pr.ID, err)
                return
@@ -149,7 +150,7 @@ func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest, ment
        }
 }
 
-func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment, mentions []*models.User) {
+func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment, mentions []*user_model.User) {
        var opts = issueNotificationOpts{
                IssueID:              pr.Issue.ID,
                NotificationAuthorID: r.Reviewer.ID,
@@ -171,7 +172,7 @@ func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r
        }
 }
 
-func (ns *notificationService) NotifyPullRequestCodeComment(pr *models.PullRequest, c *models.Comment, mentions []*models.User) {
+func (ns *notificationService) NotifyPullRequestCodeComment(pr *models.PullRequest, c *models.Comment, mentions []*user_model.User) {
        for _, mention := range mentions {
                _ = ns.issueQueue.Push(issueNotificationOpts{
                        IssueID:              pr.Issue.ID,
@@ -182,7 +183,7 @@ func (ns *notificationService) NotifyPullRequestCodeComment(pr *models.PullReque
        }
 }
 
-func (ns *notificationService) NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) {
+func (ns *notificationService) NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment) {
        var opts = issueNotificationOpts{
                IssueID:              pr.IssueID,
                NotificationAuthorID: doer.ID,
@@ -191,7 +192,7 @@ func (ns *notificationService) NotifyPullRequestPushCommits(doer *models.User, p
        _ = ns.issueQueue.Push(opts)
 }
 
-func (ns *notificationService) NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) {
+func (ns *notificationService) NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) {
        var opts = issueNotificationOpts{
                IssueID:              review.IssueID,
                NotificationAuthorID: doer.ID,
@@ -200,7 +201,7 @@ func (ns *notificationService) NotifyPullRevieweDismiss(doer *models.User, revie
        _ = ns.issueQueue.Push(opts)
 }
 
-func (ns *notificationService) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
+func (ns *notificationService) NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) {
        if !removed {
                var opts = issueNotificationOpts{
                        IssueID:              issue.ID,
@@ -216,7 +217,7 @@ func (ns *notificationService) NotifyIssueChangeAssignee(doer *models.User, issu
        }
 }
 
-func (ns *notificationService) NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) {
+func (ns *notificationService) NotifyPullReviewRequest(doer *user_model.User, issue *models.Issue, reviewer *user_model.User, isRequest bool, comment *models.Comment) {
        if isRequest {
                var opts = issueNotificationOpts{
                        IssueID:              issue.ID,
@@ -232,7 +233,7 @@ func (ns *notificationService) NotifyPullReviewRequest(doer *models.User, issue
        }
 }
 
-func (ns *notificationService) NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) {
+func (ns *notificationService) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) {
        if err := models.CreateRepoTransferNotification(doer, newOwner, repo); err != nil {
                log.Error("NotifyRepoPendingTransfer: %v", err)
        }
index d5a947d9ac166818efc5369f94a1664ea15c710a..8fe456e1c96a044f471964364b7c3d7dbf23ca1b 100644 (file)
@@ -7,6 +7,7 @@ package webhook
 import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/models/webhook"
        "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/git"
@@ -31,7 +32,7 @@ func NewNotifier() base.Notifier {
        return &webhookNotifier{}
 }
 
-func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
+func (m *webhookNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *models.Issue) {
        if err := issue.LoadPoster(); err != nil {
                log.Error("loadPoster: %v", err)
                return
@@ -71,7 +72,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *model
        }
 }
 
-func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
+func (m *webhookNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) {
        oldMode, _ := models.AccessLevel(doer, oldRepo)
        mode, _ := models.AccessLevel(doer, repo)
 
@@ -99,7 +100,7 @@ func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo
        }
 }
 
-func (m *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
+func (m *webhookNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) {
        // Add to hook queue for created repo after session commit.
        if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{
                Action:       api.HookRepoCreated,
@@ -111,7 +112,7 @@ func (m *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.Us
        }
 }
 
-func (m *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
+func (m *webhookNotifier) NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) {
        u := repo.MustOwner()
 
        if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{
@@ -124,7 +125,7 @@ func (m *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models
        }
 }
 
-func (m *webhookNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
+func (m *webhookNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) {
        // Add to hook queue for created repo after session commit.
        if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{
                Action:       api.HookRepoCreated,
@@ -136,7 +137,7 @@ func (m *webhookNotifier) NotifyMigrateRepository(doer *models.User, u *models.U
        }
 }
 
-func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
+func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) {
        if issue.IsPull {
                mode, _ := models.AccessLevelUnit(doer, issue.Repo, unit.TypePullRequests)
 
@@ -182,7 +183,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *mo
        }
 }
 
-func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
+func (m *webhookNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) {
        mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
        var err error
        if issue.IsPull {
@@ -223,7 +224,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *model
        }
 }
 
-func (m *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
+func (m *webhookNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
        mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
        var err error
        if issue.IsPull {
@@ -263,7 +264,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *mode
        }
 }
 
-func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.User) {
+func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) {
        if err := issue.LoadRepo(); err != nil {
                log.Error("issue.LoadRepo: %v", err)
                return
@@ -285,7 +286,7 @@ func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models
        }
 }
 
-func (m *webhookNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions []*models.User) {
+func (m *webhookNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions []*user_model.User) {
        if err := pull.LoadIssue(); err != nil {
                log.Error("pull.LoadIssue: %v", err)
                return
@@ -311,7 +312,7 @@ func (m *webhookNotifier) NotifyNewPullRequest(pull *models.PullRequest, mention
        }
 }
 
-func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
+func (m *webhookNotifier) NotifyIssueChangeContent(doer *user_model.User, issue *models.Issue, oldContent string) {
        mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
        var err error
        if issue.IsPull {
@@ -347,7 +348,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *mod
        }
 }
 
-func (m *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
+func (m *webhookNotifier) NotifyUpdateComment(doer *user_model.User, c *models.Comment, oldContent string) {
        var err error
 
        if err = c.LoadPoster(); err != nil {
@@ -400,8 +401,8 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comme
        }
 }
 
-func (m *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
-       issue *models.Issue, comment *models.Comment, mentions []*models.User) {
+func (m *webhookNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository,
+       issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
        mode, _ := models.AccessLevel(doer, repo)
 
        var err error
@@ -430,7 +431,7 @@ func (m *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *mode
        }
 }
 
-func (m *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) {
+func (m *webhookNotifier) NotifyDeleteComment(doer *user_model.User, comment *models.Comment) {
        var err error
 
        if err = comment.LoadPoster(); err != nil {
@@ -475,7 +476,7 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models
 
 }
 
-func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
+func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue,
        addedLabels []*models.Label, removedLabels []*models.Label) {
        var err error
 
@@ -520,7 +521,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *mode
        }
 }
 
-func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) {
+func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *user_model.User, issue *models.Issue, oldMilestoneID int64) {
        var hookAction api.HookIssueAction
        var err error
        if issue.MilestoneID > 0 {
@@ -562,7 +563,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *m
        }
 }
 
-func (m *webhookNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (m *webhookNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
        apiPusher := convert.ToUser(pusher, nil)
        apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
        if err != nil {
@@ -585,7 +586,7 @@ func (m *webhookNotifier) NotifyPushCommits(pusher *models.User, repo *models.Re
        }
 }
 
-func (*webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
+func (*webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) {
        // Reload pull request information.
        if err := pr.LoadAttributes(); err != nil {
                log.Error("LoadAttributes: %v", err)
@@ -623,7 +624,7 @@ func (*webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mod
        }
 }
 
-func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) {
+func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *models.PullRequest, oldBranch string) {
        issue := pr.Issue
        if !issue.IsPull {
                return
@@ -654,7 +655,7 @@ func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User,
        }
 }
 
-func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*models.User) {
+func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*user_model.User) {
        var reviewHookType webhook.HookEventType
 
        switch review.Type {
@@ -695,7 +696,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
        }
 }
 
-func (m *webhookNotifier) NotifyCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
+func (m *webhookNotifier) NotifyCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) {
        apiPusher := convert.ToUser(pusher, nil)
        apiRepo := convert.ToRepo(repo, models.AccessModeNone)
        refName := git.RefEndName(refFullName)
@@ -725,7 +726,7 @@ func (m *webhookNotifier) NotifyCreateRef(pusher *models.User, repo *models.Repo
        }
 }
 
-func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {
+func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *user_model.User, pr *models.PullRequest) {
        if err := pr.LoadIssue(); err != nil {
                log.Error("pr.LoadIssue: %v", err)
                return
@@ -746,7 +747,7 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *m
        }
 }
 
-func (m *webhookNotifier) NotifyDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
+func (m *webhookNotifier) NotifyDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) {
        apiPusher := convert.ToUser(pusher, nil)
        apiRepo := convert.ToRepo(repo, models.AccessModeNone)
        refName := git.RefEndName(refFullName)
@@ -762,7 +763,7 @@ func (m *webhookNotifier) NotifyDeleteRef(pusher *models.User, repo *models.Repo
        }
 }
 
-func sendReleaseHook(doer *models.User, rel *models.Release, action api.HookReleaseAction) {
+func sendReleaseHook(doer *user_model.User, rel *models.Release, action api.HookReleaseAction) {
        if err := rel.LoadAttributes(); err != nil {
                log.Error("LoadAttributes: %v", err)
                return
@@ -783,15 +784,15 @@ func (m *webhookNotifier) NotifyNewRelease(rel *models.Release) {
        sendReleaseHook(rel.Publisher, rel, api.HookReleasePublished)
 }
 
-func (m *webhookNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
+func (m *webhookNotifier) NotifyUpdateRelease(doer *user_model.User, rel *models.Release) {
        sendReleaseHook(doer, rel, api.HookReleaseUpdated)
 }
 
-func (m *webhookNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {
+func (m *webhookNotifier) NotifyDeleteRelease(doer *user_model.User, rel *models.Release) {
        sendReleaseHook(doer, rel, api.HookReleaseDeleted)
 }
 
-func (m *webhookNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (m *webhookNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
        apiPusher := convert.ToUser(pusher, nil)
        apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
        if err != nil {
@@ -814,10 +815,10 @@ func (m *webhookNotifier) NotifySyncPushCommits(pusher *models.User, repo *model
        }
 }
 
-func (m *webhookNotifier) NotifySyncCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
+func (m *webhookNotifier) NotifySyncCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) {
        m.NotifyCreateRef(pusher, repo, refType, refFullName)
 }
 
-func (m *webhookNotifier) NotifySyncDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
+func (m *webhookNotifier) NotifySyncDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) {
        m.NotifyDeleteRef(pusher, repo, refType, refFullName)
 }
index c378dc6dc7689851e4649051908e01c2e7adc3b6..7e4805d60c2ace3be2eeecd01f754643046e7fee 100644 (file)
@@ -11,6 +11,7 @@ import (
        "net/url"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/json"
        "code.gitea.io/gitea/modules/setting"
 )
@@ -18,11 +19,11 @@ import (
 // KeyAndOwner is the response from ServNoCommand
 type KeyAndOwner struct {
        Key   *models.PublicKey `json:"key"`
-       Owner *models.User      `json:"user"`
+       Owner *user_model.User  `json:"user"`
 }
 
 // ServNoCommand returns information about the provided key
-func ServNoCommand(ctx context.Context, keyID int64) (*models.PublicKey, *models.User, error) {
+func ServNoCommand(ctx context.Context, keyID int64) (*models.PublicKey, *user_model.User, error) {
        reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/none/%d",
                keyID)
        resp, err := newInternalRequest(ctx, reqURL, "GET").Response()
diff --git a/modules/repofiles/commit_status.go b/modules/repofiles/commit_status.go
new file mode 100644 (file)
index 0000000..2074b4b
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package repofiles
+
+import (
+       "fmt"
+
+       "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
+       "code.gitea.io/gitea/modules/git"
+)
+
+// CreateCommitStatus creates a new CommitStatus given a bunch of parameters
+// NOTE: All text-values will be trimmed from whitespaces.
+// Requires: Repo, Creator, SHA
+func CreateCommitStatus(repo *models.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error {
+       repoPath := repo.RepoPath()
+
+       // confirm that commit is exist
+       gitRepo, err := git.OpenRepository(repoPath)
+       if err != nil {
+               return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
+       }
+       if _, err := gitRepo.GetCommit(sha); err != nil {
+               gitRepo.Close()
+               return fmt.Errorf("GetCommit[%s]: %v", sha, err)
+       }
+       gitRepo.Close()
+
+       if err := models.NewCommitStatus(models.NewCommitStatusOptions{
+               Repo:         repo,
+               Creator:      creator,
+               SHA:          sha,
+               CommitStatus: status,
+       }); err != nil {
+               return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %v", repo.ID, creator.ID, sha, err)
+       }
+
+       return nil
+}
index a545ce952ba771ccb1b6534a86cf1137790f8884..8e727c95d0e7beaaf43857f70ba52add879c633e 100644 (file)
@@ -9,8 +9,8 @@ import (
        "net/url"
        "time"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/avatars"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        api "code.gitea.io/gitea/modules/structs"
@@ -35,14 +35,14 @@ type PushCommits struct {
        Len        int
 
        avatars    map[string]string
-       emailUsers map[string]*models.User
+       emailUsers map[string]*user_model.User
 }
 
 // NewPushCommits creates a new PushCommits object.
 func NewPushCommits() *PushCommits {
        return &PushCommits{
                avatars:    make(map[string]string),
-               emailUsers: make(map[string]*models.User),
+               emailUsers: make(map[string]*user_model.User),
        }
 }
 
@@ -52,7 +52,7 @@ func (pc *PushCommits) toAPIPayloadCommit(repoPath, repoLink string, commit *Pus
        authorUsername := ""
        author, ok := pc.emailUsers[commit.AuthorEmail]
        if !ok {
-               author, err = models.GetUserByEmail(commit.AuthorEmail)
+               author, err = user_model.GetUserByEmail(commit.AuthorEmail)
                if err == nil {
                        authorUsername = author.Name
                        pc.emailUsers[commit.AuthorEmail] = author
@@ -64,7 +64,7 @@ func (pc *PushCommits) toAPIPayloadCommit(repoPath, repoLink string, commit *Pus
        committerUsername := ""
        committer, ok := pc.emailUsers[commit.CommitterEmail]
        if !ok {
-               committer, err = models.GetUserByEmail(commit.CommitterEmail)
+               committer, err = user_model.GetUserByEmail(commit.CommitterEmail)
                if err == nil {
                        // TODO: check errors other than email not found.
                        committerUsername = committer.Name
@@ -107,7 +107,7 @@ func (pc *PushCommits) ToAPIPayloadCommits(repoPath, repoLink string) ([]*api.Pa
        var headCommit *api.PayloadCommit
 
        if pc.emailUsers == nil {
-               pc.emailUsers = make(map[string]*models.User)
+               pc.emailUsers = make(map[string]*user_model.User)
        }
        for i, commit := range pc.Commits {
                apiCommit, err := pc.toAPIPayloadCommit(repoPath, repoLink, commit)
@@ -146,10 +146,10 @@ func (pc *PushCommits) AvatarLink(email string) string {
        u, ok := pc.emailUsers[email]
        if !ok {
                var err error
-               u, err = models.GetUserByEmail(email)
+               u, err = user_model.GetUserByEmail(email)
                if err != nil {
                        pc.avatars[email] = avatars.GenerateEmailAvatarFastLink(email, size)
-                       if !models.IsErrUserNotExist(err) {
+                       if !user_model.IsErrUserNotExist(err) {
                                log.Error("GetUserByEmail: %v", err)
                                return ""
                        }
@@ -189,6 +189,6 @@ func GitToPushCommits(gitCommits []*git.Commit) *PushCommits {
                CompareURL: "",
                Len:        len(commits),
                avatars:    make(map[string]string),
-               emailUsers: make(map[string]*models.User),
+               emailUsers: make(map[string]*user_model.User),
        }
 }
index 64d92eeb2d385bf8c8e29e59b235cd59d3ba4f3b..850f7488bd0049c22305e1816a84a7c9af6e5014 100644 (file)
@@ -11,6 +11,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/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
@@ -18,7 +19,7 @@ import (
 )
 
 // CreateRepository creates a repository for the user/organization.
-func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*models.Repository, error) {
+func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) {
        if !doer.IsAdmin && !u.CanCreateRepo() {
                return nil, models.ErrReachLimitOfRepo{
                        Limit: u.MaxRepoCreation,
index 12fc7afeeb3962b39b56bab7ba4dcff1658a94a9..d7d32818726bf31bd81bead6eac53f69ecf9109e 100644 (file)
@@ -11,6 +11,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/structs"
 
        "github.com/stretchr/testify/assert"
@@ -32,14 +33,14 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
        }
 
        // Get an admin user.
-       user, err := models.GetUserByID(1)
+       user, err := user_model.GetUserByID(1)
        assert.NoError(t, err, "GetUserByID")
 
        // Create org.
        org := &models.Organization{
                Name:       "All_repo",
                IsActive:   true,
-               Type:       models.UserTypeOrganization,
+               Type:       user_model.UserTypeOrganization,
                Visibility: structs.VisibleTypePublic,
        }
        assert.NoError(t, models.CreateOrganization(org, user), "CreateOrganization")
index f6b76b14affa2346a83792827bff5be4f812693e..61a8b0d1115902b830c2a49275b475795531a45f 100644 (file)
@@ -14,6 +14,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/util"
@@ -239,7 +240,7 @@ func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *models.
 }
 
 // GenerateRepository generates a repository from a template
-func GenerateRepository(ctx context.Context, doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
+func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
        generateRepo := &models.Repository{
                OwnerID:       owner.ID,
                Owner:         owner,
index 076dbf748e68776056896a63cda3a52482c10823..d7f31fabde3879683c3b657d34c88bd4c81e8323 100644 (file)
@@ -14,6 +14,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
@@ -100,7 +101,7 @@ func prepareRepoCommit(ctx context.Context, repo *models.Repository, tmpDir, rep
 }
 
 // initRepoCommit temporarily changes with work directory.
-func initRepoCommit(tmpPath string, repo *models.Repository, u *models.User, defaultBranch string) (err error) {
+func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User, defaultBranch string) (err error) {
        commitTimeStr := time.Now().Format(time.RFC3339)
 
        sig := u.NewGitSig()
@@ -197,7 +198,7 @@ func checkInitRepository(owner, name string) (err error) {
 }
 
 // InitRepository initializes README and .gitignore if needed.
-func initRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
+func initRepository(ctx context.Context, repoPath string, u *user_model.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
        if err = checkInitRepository(repo.OwnerName, repo.Name); err != nil {
                return err
        }
index dd54a99cc9dd21b695f3bfba185f66fdf45ba1a1..c7145658f80ff84849edb15a799e7fc05fc869d5 100644 (file)
@@ -15,6 +15,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/git"
        "code.gitea.io/gitea/modules/lfs"
        "code.gitea.io/gitea/modules/log"
@@ -46,7 +47,7 @@ func WikiRemoteURL(remote string) string {
 }
 
 // MigrateRepositoryGitData starts migrating git related data after created migrating repository
-func MigrateRepositoryGitData(ctx context.Context, u *models.User,
+func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
        repo *models.Repository, opts migration.MigrateOptions,
        httpTransport *http.Transport,
 ) (*models.Repository, error) {
@@ -307,12 +308,12 @@ func PushUpdateAddTag(repo *models.Repository, gitRepo *git.Repository, tagName
                sig = commit.Committer
        }
 
-       var author *models.User
+       var author *user_model.User
        var createdAt = time.Unix(1, 0)
 
        if sig != nil {
-               author, err = models.GetUserByEmail(sig.Email)
-               if err != nil && !models.IsErrUserNotExist(err) {
+               author, err = user_model.GetUserByEmail(sig.Email)
+               if err != nil && !user_model.IsErrUserNotExist(err) {
                        return fmt.Errorf("GetUserByEmail: %v", err)
                }
                createdAt = sig.When
index aec3596bd499974e4f6e92a3a98d71d5fc7acf84..4eb8f3470762bfcfa3e640cbc7b066b1caa3d493 100644 (file)
@@ -24,6 +24,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/avatars"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/emoji"
        "code.gitea.io/gitea/modules/git"
@@ -554,7 +555,7 @@ func Avatar(item interface{}, others ...interface{}) template.HTML {
        size, class := parseOthers(avatars.DefaultAvatarPixelSize, "ui avatar image", others...)
 
        switch t := item.(type) {
-       case *models.User:
+       case *user_model.User:
                src := t.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor)
                if src != "" {
                        return AvatarHTML(src, size, class, t.DisplayName())
index eb1a54d86f886376e3e1983406bcc09df48f8148..548e454c8eafcb3df35268e5cb2edb7ef95de1db 100644 (file)
@@ -15,6 +15,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/web/middleware"
@@ -55,7 +56,7 @@ func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) {
        ctx.Repo = &context.Repository{}
        ctx.Repo.Repository = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository)
        var err error
-       ctx.Repo.Owner, err = models.GetUserByID(ctx.Repo.Repository.OwnerID)
+       ctx.Repo.Owner, err = user_model.GetUserByID(ctx.Repo.Repository.OwnerID)
        assert.NoError(t, err)
        ctx.Repo.RepoLink = ctx.Repo.Repository.Link()
        ctx.Repo.Permission, err = models.GetUserRepoPermission(ctx.Repo.Repository, ctx.User)
@@ -78,7 +79,7 @@ func LoadRepoCommit(t *testing.T, ctx *context.Context) {
 
 // LoadUser load a user into a test context.
 func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
-       ctx.User = unittest.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User)
+       ctx.User = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}).(*user_model.User)
 }
 
 // LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has
index 184a2941a8712a5f07fa38912bc43c1694bde728..85262bc836b18c79b7a3f580eb5b90338f8244be 100644 (file)
@@ -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/util"
        "code.gitea.io/gitea/routers/api/v1/utils"
@@ -79,9 +80,9 @@ func AdoptRepository(ctx *context.APIContext) {
        ownerName := ctx.Params(":username")
        repoName := ctx.Params(":reponame")
 
-       ctxUser, err := models.GetUserByName(ownerName)
+       ctxUser, err := user_model.GetUserByName(ownerName)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.NotFound()
                        return
                }
@@ -141,9 +142,9 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
        ownerName := ctx.Params(":username")
        repoName := ctx.Params(":reponame")
 
-       ctxUser, err := models.GetUserByName(ownerName)
+       ctxUser, err := user_model.GetUserByName(ownerName)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.NotFound()
                        return
                }
index 2633865d2c1e53541d4bbb18a9612a51d2d26747..bdfe87fd4e4ff479c298c33baf654cd525acff7d 100644 (file)
@@ -9,6 +9,8 @@ import (
        "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/context"
        "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
@@ -61,15 +63,15 @@ func CreateOrg(ctx *context.APIContext) {
                Website:     form.Website,
                Location:    form.Location,
                IsActive:    true,
-               Type:        models.UserTypeOrganization,
+               Type:        user_model.UserTypeOrganization,
                Visibility:  visibility,
        }
 
        if err := models.CreateOrganization(org, u); err != nil {
-               if models.IsErrUserAlreadyExist(err) ||
-                       models.IsErrNameReserved(err) ||
-                       models.IsErrNameCharsNotAllowed(err) ||
-                       models.IsErrNamePatternNotAllowed(err) {
+               if user_model.IsErrUserAlreadyExist(err) ||
+                       db.IsErrNameReserved(err) ||
+                       db.IsErrNameCharsNotAllowed(err) ||
+                       db.IsErrNamePatternNotAllowed(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", err)
                } else {
                        ctx.Error(http.StatusInternalServerError, "CreateOrganization", err)
@@ -104,10 +106,10 @@ func GetAllOrgs(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,
-               Type:        models.UserTypeOrganization,
-               OrderBy:     models.SearchOrderByAlphabetically,
+               Type:        user_model.UserTypeOrganization,
+               OrderBy:     db.SearchOrderByAlphabetically,
                ListOptions: listOptions,
                Visible:     []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate},
        })
index 95060e7a1c817a093f8c8e5833834af3e9c8512f..e50abb59376418b00d7e85fa9c6e9a8df6e50a4d 100644 (file)
@@ -11,6 +11,7 @@ import (
        "net/http"
 
        "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"
        "code.gitea.io/gitea/modules/context"
@@ -25,7 +26,7 @@ import (
        user_service "code.gitea.io/gitea/services/user"
 )
 
-func parseLoginSource(ctx *context.APIContext, u *models.User, sourceID int64, loginName string) {
+func parseLoginSource(ctx *context.APIContext, u *user_model.User, sourceID int64, loginName string) {
        if sourceID == 0 {
                return
        }
@@ -70,7 +71,7 @@ func CreateUser(ctx *context.APIContext) {
        //     "$ref": "#/responses/validationError"
        form := web.GetForm(ctx).(*api.CreateUserOption)
 
-       u := &models.User{
+       u := &user_model.User{
                Name:               form.Username,
                FullName:           form.FullName,
                Email:              form.Email,
@@ -102,20 +103,20 @@ func CreateUser(ctx *context.APIContext) {
                return
        }
 
-       var overwriteDefault *models.CreateUserOverwriteOptions
+       var overwriteDefault *user_model.CreateUserOverwriteOptions
        if form.Visibility != "" {
-               overwriteDefault = &models.CreateUserOverwriteOptions{
+               overwriteDefault = &user_model.CreateUserOverwriteOptions{
                        Visibility: api.VisibilityModes[form.Visibility],
                }
        }
 
-       if err := models.CreateUser(u, overwriteDefault); err != nil {
-               if models.IsErrUserAlreadyExist(err) ||
+       if err := user_model.CreateUser(u, overwriteDefault); err != nil {
+               if user_model.IsErrUserAlreadyExist(err) ||
                        user_model.IsErrEmailAlreadyUsed(err) ||
-                       models.IsErrNameReserved(err) ||
-                       models.IsErrNameCharsNotAllowed(err) ||
+                       db.IsErrNameReserved(err) ||
+                       db.IsErrNameCharsNotAllowed(err) ||
                        user_model.IsErrEmailInvalid(err) ||
-                       models.IsErrNamePatternNotAllowed(err) {
+                       db.IsErrNamePatternNotAllowed(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", err)
                } else {
                        ctx.Error(http.StatusInternalServerError, "CreateUser", err)
@@ -183,7 +184,7 @@ func EditUser(ctx *context.APIContext) {
                        ctx.Error(http.StatusBadRequest, "PasswordPwned", errors.New("PasswordPwned"))
                        return
                }
-               if u.Salt, err = models.GetUserSalt(); err != nil {
+               if u.Salt, err = user_model.GetUserSalt(); err != nil {
                        ctx.Error(http.StatusInternalServerError, "UpdateUser", err)
                        return
                }
@@ -246,7 +247,7 @@ func EditUser(ctx *context.APIContext) {
                u.IsRestricted = *form.Restricted
        }
 
-       if err := models.UpdateUser(u); err != nil {
+       if err := user_model.UpdateUser(u); err != nil {
                if user_model.IsErrEmailAlreadyUsed(err) || user_model.IsErrEmailInvalid(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", err)
                } else {
@@ -409,10 +410,10 @@ func GetAllUsers(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,
-               Type:        models.UserTypeIndividual,
-               OrderBy:     models.SearchOrderByAlphabetically,
+               Type:        user_model.UserTypeIndividual,
+               OrderBy:     db.SearchOrderByAlphabetically,
                ListOptions: listOptions,
        })
        if err != nil {
index ea653b96775afc4a086d2df2c8dd93e1b92a2157..867803f8dd5f9d7aca966bc72894460257fe714a 100644 (file)
@@ -103,9 +103,9 @@ func sudo() func(ctx *context.APIContext) {
 
                if len(sudo) > 0 {
                        if ctx.IsSigned && ctx.User.IsAdmin {
-                               user, err := models.GetUserByName(sudo)
+                               user, err := user_model.GetUserByName(sudo)
                                if err != nil {
-                                       if models.IsErrUserNotExist(err) {
+                                       if user_model.IsErrUserNotExist(err) {
                                                ctx.NotFound()
                                        } else {
                                                ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -130,7 +130,7 @@ func repoAssignment() func(ctx *context.APIContext) {
                repoName := ctx.Params("reponame")
 
                var (
-                       owner *models.User
+                       owner *user_model.User
                        err   error
                )
 
@@ -138,9 +138,9 @@ func repoAssignment() func(ctx *context.APIContext) {
                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 redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
                                                context.RedirectToUser(ctx.Context, userName, redirectUserID)
                                        } else if user_model.IsErrUserRedirectNotExist(err) {
index 952e29fba9ce8bf6e707dc58b2b3d564ce02e756..84065363f0283a67667e1c1ca6ba906e1d90064d 100644 (file)
@@ -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"
@@ -19,7 +20,7 @@ import (
        "code.gitea.io/gitea/services/org"
 )
 
-func listUserOrgs(ctx *context.APIContext, u *models.User) {
+func listUserOrgs(ctx *context.APIContext, u *user_model.User) {
        listOptions := utils.GetListOptions(ctx)
        showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == u.ID)
 
@@ -130,12 +131,12 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
        //   "404":
        //     "$ref": "#/responses/notFound"
 
-       var u *models.User
+       var u *user_model.User
        if u = user.GetUserByParams(ctx); u == nil {
                return
        }
 
-       var o *models.User
+       var o *user_model.User
        if o = user.GetUserByParamsName(ctx, ":org"); o == nil {
                return
        }
@@ -206,11 +207,11 @@ func GetAll(ctx *context.APIContext) {
 
        listOptions := utils.GetListOptions(ctx)
 
-       publicOrgs, maxResults, err := models.SearchUsers(&models.SearchUserOptions{
+       publicOrgs, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
                Actor:       ctx.User,
                ListOptions: listOptions,
-               Type:        models.UserTypeOrganization,
-               OrderBy:     models.SearchOrderByAlphabetically,
+               Type:        user_model.UserTypeOrganization,
+               OrderBy:     db.SearchOrderByAlphabetically,
                Visible:     vMode,
        })
        if err != nil {
@@ -266,15 +267,15 @@ func Create(ctx *context.APIContext) {
                Website:                   form.Website,
                Location:                  form.Location,
                IsActive:                  true,
-               Type:                      models.UserTypeOrganization,
+               Type:                      user_model.UserTypeOrganization,
                Visibility:                visibility,
                RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
        }
        if err := models.CreateOrganization(org, ctx.User); err != nil {
-               if models.IsErrUserAlreadyExist(err) ||
-                       models.IsErrNameReserved(err) ||
-                       models.IsErrNameCharsNotAllowed(err) ||
-                       models.IsErrNamePatternNotAllowed(err) {
+               if user_model.IsErrUserAlreadyExist(err) ||
+                       db.IsErrNameReserved(err) ||
+                       db.IsErrNameCharsNotAllowed(err) ||
+                       db.IsErrNamePatternNotAllowed(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", err)
                } else {
                        ctx.Error(http.StatusInternalServerError, "CreateOrganization", err)
@@ -344,7 +345,7 @@ func Edit(ctx *context.APIContext) {
        if form.RepoAdminChangeTeamAccess != nil {
                org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
        }
-       if err := models.UpdateUserCols(db.DefaultContext, org.AsUser(),
+       if err := user_model.UpdateUserCols(db.DefaultContext, org.AsUser(),
                "full_name", "description", "website", "location",
                "visibility", "repo_admin_change_team_access",
        ); err != nil {
index 04da9012396b96421d9ba6c898c4424a51ebe4f1..70e5b3e2b87229c842666dd6601253b764fc7bf8 100644 (file)
@@ -11,6 +11,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/git"
@@ -423,27 +424,27 @@ func CreateBranchProtection(ctx *context.APIContext) {
                requiredApprovals = form.RequiredApprovals
        }
 
-       whitelistUsers, err := models.GetUserIDsByNames(form.PushWhitelistUsernames, false)
+       whitelistUsers, err := user_model.GetUserIDsByNames(form.PushWhitelistUsernames, false)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
                        return
                }
                ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
                return
        }
-       mergeWhitelistUsers, err := models.GetUserIDsByNames(form.MergeWhitelistUsernames, false)
+       mergeWhitelistUsers, err := user_model.GetUserIDsByNames(form.MergeWhitelistUsernames, false)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
                        return
                }
                ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
                return
        }
-       approvalsWhitelistUsers, err := models.GetUserIDsByNames(form.ApprovalsWhitelistUsernames, false)
+       approvalsWhitelistUsers, err := user_model.GetUserIDsByNames(form.ApprovalsWhitelistUsernames, false)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
                        return
                }
@@ -653,9 +654,9 @@ func EditBranchProtection(ctx *context.APIContext) {
 
        var whitelistUsers []int64
        if form.PushWhitelistUsernames != nil {
-               whitelistUsers, err = models.GetUserIDsByNames(form.PushWhitelistUsernames, false)
+               whitelistUsers, err = user_model.GetUserIDsByNames(form.PushWhitelistUsernames, false)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
                                return
                        }
@@ -667,9 +668,9 @@ func EditBranchProtection(ctx *context.APIContext) {
        }
        var mergeWhitelistUsers []int64
        if form.MergeWhitelistUsernames != nil {
-               mergeWhitelistUsers, err = models.GetUserIDsByNames(form.MergeWhitelistUsernames, false)
+               mergeWhitelistUsers, err = user_model.GetUserIDsByNames(form.MergeWhitelistUsernames, false)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
                                return
                        }
@@ -681,9 +682,9 @@ func EditBranchProtection(ctx *context.APIContext) {
        }
        var approvalsWhitelistUsers []int64
        if form.ApprovalsWhitelistUsernames != nil {
-               approvalsWhitelistUsers, err = models.GetUserIDsByNames(form.ApprovalsWhitelistUsernames, false)
+               approvalsWhitelistUsers, err = user_model.GetUserIDsByNames(form.ApprovalsWhitelistUsernames, false)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
                                return
                        }
index d636220f62cf9d5ab45410b95924c5290002e47d..fcc8f9a90fb32889c557623799655f2027bc1b02 100644 (file)
@@ -10,6 +10,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"
@@ -99,9 +100,9 @@ func IsCollaborator(ctx *context.APIContext) {
        //   "422":
        //     "$ref": "#/responses/validationError"
 
-       user, err := models.GetUserByName(ctx.Params(":collaborator"))
+       user, err := user_model.GetUserByName(ctx.Params(":collaborator"))
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", err)
                } else {
                        ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -155,9 +156,9 @@ func AddCollaborator(ctx *context.APIContext) {
 
        form := web.GetForm(ctx).(*api.AddCollaboratorOption)
 
-       collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
+       collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator"))
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", err)
                } else {
                        ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -214,9 +215,9 @@ func DeleteCollaborator(ctx *context.APIContext) {
        //   "422":
        //     "$ref": "#/responses/validationError"
 
-       collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
+       collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator"))
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", err)
                } else {
                        ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
index 639100757bdd7c0ffb19866faa3b82797328bc93..9907054b831d5117a35cd77a4d86d711b7bc8d3a 100644 (file)
@@ -12,6 +12,7 @@ import (
        "strconv"
 
        "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/git"
@@ -188,7 +189,7 @@ func GetAllCommits(ctx *context.APIContext) {
                return
        }
 
-       userCache := make(map[string]*models.User)
+       userCache := make(map[string]*user_model.User)
 
        apiCommits := make([]*api.Commit, len(commits))
        for i, commit := range commits {
index 45d3c815a7142e73c7611bd04388d38af1bbc56b..528b8fdecc7d8a4372dffefd7c8dc9893a6a955f 100644 (file)
@@ -10,6 +10,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"
@@ -99,7 +100,7 @@ func CreateFork(ctx *context.APIContext) {
 
        form := web.GetForm(ctx).(*api.CreateForkOption)
        repo := ctx.Repo.Repository
-       var forker *models.User // user/org that will own the fork
+       var forker *user_model.User // user/org that will own the fork
        if form.Organization == nil {
                forker = ctx.User
        } else {
index a2454b8618382463231f4e747132d7046a0fcc3f..5137c7246ed504862a1681ffe34fce47e9e0dc0a 100644 (file)
@@ -15,6 +15,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        "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/convert"
        issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
@@ -133,7 +134,7 @@ func SearchIssues(ctx *context.APIContext) {
                Collaborate: util.OptionalBoolNone,
                // This needs to be a column that is not nil in fixtures or
                // MySQL will return different results when sorting by null in some cases
-               OrderBy: models.SearchOrderByAlphabetically,
+               OrderBy: db.SearchOrderByAlphabetically,
                Actor:   ctx.User,
        }
        if ctx.IsSigned {
@@ -141,9 +142,9 @@ func SearchIssues(ctx *context.APIContext) {
                opts.AllLimited = true
        }
        if ctx.FormString("owner") != "" {
-               owner, err := models.GetUserByName(ctx.FormString("owner"))
+               owner, err := user_model.GetUserByName(ctx.FormString("owner"))
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.Error(http.StatusBadRequest, "Owner not found", err)
                        } else {
                                ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -492,8 +493,8 @@ func getUserIDForFilter(ctx *context.APIContext, queryName string) int64 {
                return 0
        }
 
-       user, err := models.GetUserByName(userName)
-       if models.IsErrUserNotExist(err) {
+       user, err := user_model.GetUserByName(userName)
+       if user_model.IsErrUserNotExist(err) {
                ctx.NotFound(err)
                return 0
        }
@@ -604,7 +605,7 @@ func CreateIssue(ctx *context.APIContext) {
                issue.MilestoneID = form.Milestone
                assigneeIDs, err = models.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
                        } else {
                                ctx.Error(http.StatusInternalServerError, "AddAssigneeByName", err)
@@ -614,7 +615,7 @@ func CreateIssue(ctx *context.APIContext) {
 
                // Check if the passed assignees is assignable
                for _, aID := range assigneeIDs {
-                       assignee, err := models.GetUserByID(aID)
+                       assignee, err := user_model.GetUserByID(aID)
                        if err != nil {
                                ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
                                return
index 8acd378cc5e037344d730e3ee0763b3973d4f846..09be3cc19315244bbbc4181ef89521ec0f4139ab 100644 (file)
@@ -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"
@@ -114,9 +115,9 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
                return
        }
 
-       user, err := models.GetUserByName(ctx.Params(":user"))
+       user, err := user_model.GetUserByName(ctx.Params(":user"))
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.NotFound()
                } else {
                        ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
index f73e63547b0ce84a4fa484fecaf634f99b74067b..00f8e77febddd88d00b6a05c1ad0f44f98b2fabc 100644 (file)
@@ -11,6 +11,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/convert"
        api "code.gitea.io/gitea/modules/structs"
@@ -92,8 +93,8 @@ func ListTrackedTimes(ctx *context.APIContext) {
 
        qUser := ctx.FormTrim("user")
        if qUser != "" {
-               user, err := models.GetUserByName(qUser)
-               if models.IsErrUserNotExist(err) {
+               user, err := user_model.GetUserByName(qUser)
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusNotFound, "User does not exist", err)
                } else if err != nil {
                        ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -201,7 +202,7 @@ func AddTime(ctx *context.APIContext) {
        if form.User != "" {
                if (ctx.IsUserRepoAdmin() && ctx.User.Name != form.User) || ctx.User.IsAdmin {
                        //allow only RepoAdmin, Admin and User to add time
-                       user, err = models.GetUserByName(form.User)
+                       user, err = user_model.GetUserByName(form.User)
                        if err != nil {
                                ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
                        }
@@ -413,9 +414,9 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
                ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
                return
        }
-       user, err := models.GetUserByName(ctx.Params(":timetrackingusername"))
+       user, err := user_model.GetUserByName(ctx.Params(":timetrackingusername"))
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.NotFound(err)
                } else {
                        ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -510,8 +511,8 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
        // Filters
        qUser := ctx.FormTrim("user")
        if qUser != "" {
-               user, err := models.GetUserByName(qUser)
-               if models.IsErrUserNotExist(err) {
+               user, err := user_model.GetUserByName(qUser)
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusNotFound, "User does not exist", err)
                } else if err != nil {
                        ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
index 767972ee9881a660ee0706dadfbc561cf35a67bc..bc594419f70fee58c08e03f7688d26bcd96addde 100644 (file)
@@ -12,6 +12,8 @@ import (
        "strings"
 
        "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"
        "code.gitea.io/gitea/modules/graceful"
@@ -54,18 +56,18 @@ func Migrate(ctx *context.APIContext) {
 
        //get repoOwner
        var (
-               repoOwner *models.User
+               repoOwner *user_model.User
                err       error
        )
        if len(form.RepoOwner) != 0 {
-               repoOwner, err = models.GetUserByName(form.RepoOwner)
+               repoOwner, err = user_model.GetUserByName(form.RepoOwner)
        } else if form.RepoOwnerID != 0 {
-               repoOwner, err = models.GetUserByID(form.RepoOwnerID)
+               repoOwner, err = user_model.GetUserByID(form.RepoOwnerID)
        } else {
                repoOwner = ctx.User
        }
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", err)
                } else {
                        ctx.Error(http.StatusInternalServerError, "GetUser", err)
@@ -208,7 +210,7 @@ func Migrate(ctx *context.APIContext) {
        ctx.JSON(http.StatusCreated, convert.ToRepo(repo, models.AccessModeAdmin))
 }
 
-func handleMigrateError(ctx *context.APIContext, repoOwner *models.User, remoteAddr string, err error) {
+func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, remoteAddr string, err error) {
        switch {
        case models.IsErrRepoAlreadyExist(err):
                ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
@@ -220,12 +222,12 @@ func handleMigrateError(ctx *context.APIContext, repoOwner *models.User, remoteA
                ctx.Error(http.StatusUnprocessableEntity, "", "Remote visit required two factors authentication.")
        case models.IsErrReachLimitOfRepo(err):
                ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("You have already reached your limit of %d repositories.", repoOwner.MaxCreationLimit()))
-       case models.IsErrNameReserved(err):
-               ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' is reserved.", err.(models.ErrNameReserved).Name))
-       case models.IsErrNameCharsNotAllowed(err):
-               ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' contains invalid characters.", err.(models.ErrNameCharsNotAllowed).Name))
-       case models.IsErrNamePatternNotAllowed(err):
-               ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The pattern '%s' is not allowed in a username.", err.(models.ErrNamePatternNotAllowed).Pattern))
+       case db.IsErrNameReserved(err):
+               ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' is reserved.", err.(db.ErrNameReserved).Name))
+       case db.IsErrNameCharsNotAllowed(err):
+               ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' contains invalid characters.", err.(db.ErrNameCharsNotAllowed).Name))
+       case db.IsErrNamePatternNotAllowed(err):
+               ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The pattern '%s' is not allowed in a username.", err.(db.ErrNamePatternNotAllowed).Pattern))
        case models.IsErrInvalidCloneAddr(err):
                ctx.Error(http.StatusUnprocessableEntity, "", err)
        case base.IsErrNotSupported(err):
index efe72e1502a260419464661deb4528f9085b9900..dd415a34af3f9e205bdd38f135e6c568eef1ce2f 100644 (file)
@@ -15,6 +15,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/convert"
        "code.gitea.io/gitea/modules/git"
@@ -382,7 +383,7 @@ func CreatePullRequest(ctx *context.APIContext) {
        // Get all assignee IDs
        assigneeIDs, err := models.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
                } else {
                        ctx.Error(http.StatusInternalServerError, "AddAssigneeByName", err)
@@ -391,7 +392,7 @@ func CreatePullRequest(ctx *context.APIContext) {
        }
        // Check if the passed assignees is assignable
        for _, aID := range assigneeIDs {
-               assignee, err := models.GetUserByID(aID)
+               assignee, err := user_model.GetUserByID(aID)
                if err != nil {
                        ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
                        return
@@ -522,7 +523,7 @@ func EditPullRequest(ctx *context.APIContext) {
        if ctx.Repo.CanWrite(unit.TypePullRequests) && (form.Assignees != nil || len(form.Assignee) > 0) {
                err = issue_service.UpdateAssignees(issue, form.Assignee, form.Assignees, ctx.User)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
                        } else {
                                ctx.Error(http.StatusInternalServerError, "UpdateAssignees", err)
@@ -900,7 +901,7 @@ func MergePullRequest(ctx *context.APIContext) {
        ctx.Status(http.StatusOK)
 }
 
-func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*models.User, *models.Repository, *git.Repository, *git.CompareInfo, string, string) {
+func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*user_model.User, *models.Repository, *git.Repository, *git.CompareInfo, string, string) {
        baseRepo := ctx.Repo.Repository
 
        // Get compared branches information
@@ -913,7 +914,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
        baseBranch := form.Base
 
        var (
-               headUser   *models.User
+               headUser   *user_model.User
                headBranch string
                isSameRepo bool
                err        error
@@ -927,9 +928,9 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
                headBranch = headInfos[0]
 
        } else if len(headInfos) == 2 {
-               headUser, err = models.GetUserByName(headInfos[0])
+               headUser, err = user_model.GetUserByName(headInfos[0])
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.NotFound("GetUserByName")
                        } else {
                                ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -1209,7 +1210,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
        totalNumberOfCommits := len(commits)
        totalNumberOfPages := int(math.Ceil(float64(totalNumberOfCommits) / float64(listOptions.PageSize)))
 
-       userCache := make(map[string]*models.User)
+       userCache := make(map[string]*user_model.User)
 
        start, end := listOptions.GetStartEnd()
 
index 55b5178305edfa4ac7422a453ae2f578edac30d6..ec5f0456476e0cc2f5c653ab767383a191f9094f 100644 (file)
@@ -10,6 +10,7 @@ import (
        "strings"
 
        "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/git"
@@ -554,7 +555,7 @@ func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullR
                return nil, nil, true
        }
 
-       if err := review.LoadAttributes(); err != nil && !models.IsErrUserNotExist(err) {
+       if err := review.LoadAttributes(); err != nil && !user_model.IsErrUserNotExist(err) {
                ctx.Error(http.StatusInternalServerError, "ReviewLoadAttributes", err)
                return nil, nil, true
        }
@@ -659,7 +660,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
                return
        }
 
-       reviewers := make([]*models.User, 0, len(opts.Reviewers))
+       reviewers := make([]*user_model.User, 0, len(opts.Reviewers))
 
        permDoer, err := models.GetUserRepoPermission(pr.Issue.Repo, ctx.User)
        if err != nil {
@@ -668,15 +669,15 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
        }
 
        for _, r := range opts.Reviewers {
-               var reviewer *models.User
+               var reviewer *user_model.User
                if strings.Contains(r, "@") {
-                       reviewer, err = models.GetUserByEmail(r)
+                       reviewer, err = user_model.GetUserByEmail(r)
                } else {
-                       reviewer, err = models.GetUserByName(r)
+                       reviewer, err = user_model.GetUserByName(r)
                }
 
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.NotFound("UserNotExist", fmt.Sprintf("User '%s' not exist", r))
                                return
                        }
index 872ce228713a01a6bfee1df5f29061b71da7bacc..a74e13d3abde2c9022ba78fb01e30111ede362ae 100644 (file)
@@ -12,7 +12,9 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       "code.gitea.io/gitea/models/db"
        unit_model "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/convert"
        "code.gitea.io/gitea/modules/git"
@@ -26,20 +28,20 @@ import (
        repo_service "code.gitea.io/gitea/services/repository"
 )
 
-var searchOrderByMap = map[string]map[string]models.SearchOrderBy{
+var searchOrderByMap = map[string]map[string]db.SearchOrderBy{
        "asc": {
-               "alpha":   models.SearchOrderByAlphabetically,
-               "created": models.SearchOrderByOldest,
-               "updated": models.SearchOrderByLeastUpdated,
-               "size":    models.SearchOrderBySize,
-               "id":      models.SearchOrderByID,
+               "alpha":   db.SearchOrderByAlphabetically,
+               "created": db.SearchOrderByOldest,
+               "updated": db.SearchOrderByLeastUpdated,
+               "size":    db.SearchOrderBySize,
+               "id":      db.SearchOrderByID,
        },
        "desc": {
-               "alpha":   models.SearchOrderByAlphabeticallyReverse,
-               "created": models.SearchOrderByNewest,
-               "updated": models.SearchOrderByRecentUpdated,
-               "size":    models.SearchOrderBySizeReverse,
-               "id":      models.SearchOrderByIDReverse,
+               "alpha":   db.SearchOrderByAlphabeticallyReverse,
+               "created": db.SearchOrderByNewest,
+               "updated": db.SearchOrderByRecentUpdated,
+               "size":    db.SearchOrderBySizeReverse,
+               "id":      db.SearchOrderByIDReverse,
        },
 }
 
@@ -239,7 +241,7 @@ func Search(ctx *context.APIContext) {
 }
 
 // CreateUserRepo create a repository for a user
-func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateRepoOption) {
+func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.CreateRepoOption) {
        if opt.AutoInit && opt.Readme == "" {
                opt.Readme = "Default"
        }
@@ -259,8 +261,8 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
        if err != nil {
                if models.IsErrRepoAlreadyExist(err) {
                        ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
-               } else if models.IsErrNameReserved(err) ||
-                       models.IsErrNamePatternNotAllowed(err) {
+               } else if db.IsErrNameReserved(err) ||
+                       db.IsErrNamePatternNotAllowed(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", err)
                } else {
                        ctx.Error(http.StatusInternalServerError, "CreateRepository", err)
@@ -374,9 +376,9 @@ func Generate(ctx *context.APIContext) {
        ctxUser := ctx.User
        var err error
        if form.Owner != ctxUser.Name {
-               ctxUser, err = models.GetUserByName(form.Owner)
+               ctxUser, err = user_model.GetUserByName(form.Owner)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.JSON(http.StatusNotFound, map[string]interface{}{
                                        "error": "request owner `" + form.Owner + "` does not exist",
                                })
@@ -408,8 +410,8 @@ func Generate(ctx *context.APIContext) {
        if err != nil {
                if models.IsErrRepoAlreadyExist(err) {
                        ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
-               } else if models.IsErrNameReserved(err) ||
-                       models.IsErrNamePatternNotAllowed(err) {
+               } else if db.IsErrNameReserved(err) ||
+                       db.IsErrNamePatternNotAllowed(err) {
                        ctx.Error(http.StatusUnprocessableEntity, "", err)
                } else {
                        ctx.Error(http.StatusInternalServerError, "CreateRepository", err)
@@ -648,10 +650,10 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
                        switch {
                        case models.IsErrRepoAlreadyExist(err):
                                ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is already taken [name: %s]", newRepoName), err)
-                       case models.IsErrNameReserved(err):
+                       case db.IsErrNameReserved(err):
                                ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is reserved [name: %s]", newRepoName), err)
-                       case models.IsErrNamePatternNotAllowed(err):
-                               ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name's pattern is not allowed [name: %s, pattern: %s]", newRepoName, err.(models.ErrNamePatternNotAllowed).Pattern), err)
+                       case db.IsErrNamePatternNotAllowed(err):
+                               ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name's pattern is not allowed [name: %s, pattern: %s]", newRepoName, err.(db.ErrNamePatternNotAllowed).Pattern), err)
                        default:
                                ctx.Error(http.StatusUnprocessableEntity, "ChangeRepositoryName", err)
                        }
index f16e2bb081fb6b1bdc931cb2c5a4e8f4660431cf..b3913bcd34777c15bf8709c1db93aed554ee4f5a 100644 (file)
@@ -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/modules/log"
@@ -53,9 +54,9 @@ func Transfer(ctx *context.APIContext) {
 
        opts := web.GetForm(ctx).(*api.TransferRepoOption)
 
-       newOwner, err := models.GetUserByName(opts.NewOwner)
+       newOwner, err := user_model.GetUserByName(opts.NewOwner)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
                        return
                }
@@ -63,7 +64,7 @@ func Transfer(ctx *context.APIContext) {
                return
        }
 
-       if newOwner.Type == models.UserTypeOrganization {
+       if newOwner.Type == user_model.UserTypeOrganization {
                if !ctx.User.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) {
                        // The user shouldn't know about this organization
                        ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
index edf3cea3ea04dc16b703da7d2a702b39131385cc..1eacb89db2bfece3fe95daac87151f3a31e9d074 100644 (file)
@@ -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 {
index a7c2e61405423faba5f08acd53a980d41ef8969a..fab3ce2ae5394920d1cb81bcf6c944980f046b5a 100644 (file)
@@ -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")
 }
index 36b1c17b895f84757fefbe6f9bd7f1f86129b677..719e1c0bdcb85e3c0ca87268a103af866f418b48 100644 (file)
@@ -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
index 3c9a17a0bef3db8ff77f4f9b350614ad6df9ab32..0b0b522c15db409032e497eca1b34a9f732e00b0 100644 (file)
@@ -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{
index b4548e7443fa29b09e03042984de5de2ce6d6eb3..40bee566811bdf777b09d964e3d3b67abed4d63f 100644 (file)
@@ -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
        }
index f067722bfa821cd75215fd9e39a29b5b1d7b2604..946ae738e949f1f377e28e87b2b505098ea21168 100644 (file)
@@ -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
index 8c57b1f099fa6ee6e0dd9b7f3a97fa10dbb79dd6..bba7b7a5d1487449fafb9ab09c680a5ccebac002 100644 (file)
@@ -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))
index 3c6f8b30704f385a8cc00e49702e6f3e18699e5d..54d5e74bc002c5464039d5d753c514d99ca6d75e 100644 (file)
@@ -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
index 837467056dc139d34c6fde84b593d89cc6561187..bd19ab5eb64ba0371ee7adf7b9c52cb1108d25e5 100644 (file)
@@ -14,9 +14,9 @@ import (
        "strings"
        "time"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/migrations"
+       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/generate"
@@ -72,7 +72,7 @@ func Init(next http.Handler) http.Handler {
                                "TmplLoadTimes": func() string {
                                        return time.Since(startTime).String()
                                },
-                               "PasswordHashAlgorithms": models.AvailableHashAlgorithms,
+                               "PasswordHashAlgorithms": user_model.AvailableHashAlgorithms,
                        },
                }
                for _, lang := range translation.AllLangs() {
@@ -264,13 +264,13 @@ func SubmitInstall(ctx *context.Context) {
        // Check admin user creation
        if len(form.AdminName) > 0 {
                // Ensure AdminName is valid
-               if err := models.IsUsableUsername(form.AdminName); err != nil {
+               if err := user_model.IsUsableUsername(form.AdminName); err != nil {
                        ctx.Data["Err_Admin"] = true
                        ctx.Data["Err_AdminName"] = true
-                       if models.IsErrNameReserved(err) {
+                       if db.IsErrNameReserved(err) {
                                ctx.RenderWithErr(ctx.Tr("install.err_admin_name_is_reserved"), tplInstall, form)
                                return
-                       } else if models.IsErrNamePatternNotAllowed(err) {
+                       } else if db.IsErrNamePatternNotAllowed(err) {
                                ctx.RenderWithErr(ctx.Tr("install.err_admin_name_pattern_not_allowed"), tplInstall, form)
                                return
                        }
@@ -416,15 +416,15 @@ func SubmitInstall(ctx *context.Context) {
 
        // Create admin account
        if len(form.AdminName) > 0 {
-               u := &models.User{
+               u := &user_model.User{
                        Name:     form.AdminName,
                        Email:    form.AdminEmail,
                        Passwd:   form.AdminPasswd,
                        IsAdmin:  true,
                        IsActive: true,
                }
-               if err = models.CreateUser(u); err != nil {
-                       if !models.IsErrUserAlreadyExist(err) {
+               if err = user_model.CreateUser(u); err != nil {
+                       if !user_model.IsErrUserAlreadyExist(err) {
                                setting.InstallLock = false
                                ctx.Data["Err_AdminName"] = true
                                ctx.Data["Err_AdminEmail"] = true
@@ -432,7 +432,7 @@ func SubmitInstall(ctx *context.Context) {
                                return
                        }
                        log.Info("Admin account already exist")
-                       u, _ = models.GetUserByName(u.Name)
+                       u, _ = user_model.GetUserByName(u.Name)
                }
 
                days := 86400 * setting.LogInRememberDays
index 04c334b38f5beb1138fbddb28e2f7d14fedc43a3..5ab21d525b975830558cff82eb71155cbc03f924 100644 (file)
@@ -13,6 +13,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        gitea_context "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
@@ -23,7 +24,7 @@ import (
 
 type preReceiveContext struct {
        *gitea_context.PrivateContext
-       user *models.User
+       user *user_model.User
        perm models.Permission
 
        canCreatePullRequest        bool
@@ -41,7 +42,7 @@ type preReceiveContext struct {
 }
 
 // User gets or loads User
-func (ctx *preReceiveContext) User() *models.User {
+func (ctx *preReceiveContext) User() *user_model.User {
        if ctx.user == nil {
                ctx.user, ctx.perm = loadUserAndPermission(ctx.PrivateContext, ctx.opts.UserID)
        }
@@ -449,8 +450,8 @@ func generateGitEnv(opts *private.HookOptions) (env []string) {
        return env
 }
 
-func loadUserAndPermission(ctx *gitea_context.PrivateContext, id int64) (user *models.User, perm models.Permission) {
-       user, err := models.GetUserByID(id)
+func loadUserAndPermission(ctx *gitea_context.PrivateContext, id int64) (user *user_model.User, perm models.Permission) {
+       user, err := user_model.GetUserByID(id)
        if err != nil {
                log.Error("Unable to get User id %d Error: %v", id, err)
                ctx.JSON(http.StatusInternalServerError, private.Response{
index 6b9100159a90864da0644c7eca9022a8942f879e..5218cd34a1edfc286491e7421d8ed9fe36d7f4be 100644 (file)
@@ -9,7 +9,7 @@ import (
        "net/http"
        "strconv"
 
-       "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/json"
        "code.gitea.io/gitea/modules/log"
@@ -44,7 +44,7 @@ func SendEmail(ctx *context.PrivateContext) {
        var emails []string
        if len(mail.To) > 0 {
                for _, uname := range mail.To {
-                       user, err := models.GetUserByName(uname)
+                       user, err := user_model.GetUserByName(uname)
                        if err != nil {
                                err := fmt.Sprintf("Failed to get user information: %v", err)
                                log.Error(err)
@@ -59,7 +59,7 @@ func SendEmail(ctx *context.PrivateContext) {
                        }
                }
        } else {
-               err := models.IterateUser(func(user *models.User) error {
+               err := user_model.IterateUser(func(user *user_model.User) error {
                        if len(user.Email) > 0 {
                                emails = append(emails, user.Email)
                        }
index 329d80476a4eb4f9f94206bdaab246604d2a5b39..18057ededb5288808c27b68ae665b132c48e4155 100644 (file)
@@ -12,6 +12,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/git"
        "code.gitea.io/gitea/modules/log"
@@ -48,9 +49,9 @@ func ServNoCommand(ctx *context.PrivateContext) {
        results.Key = key
 
        if key.Type == models.KeyTypeUser || key.Type == models.KeyTypePrincipal {
-               user, err := models.GetUserByID(key.OwnerID)
+               user, err := user_model.GetUserByID(key.OwnerID)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.JSON(http.StatusUnauthorized, private.Response{
                                        Err: fmt.Sprintf("Cannot find owner with id: %d for key: %d", key.OwnerID, keyID),
                                })
@@ -105,7 +106,7 @@ func ServCommand(ctx *context.PrivateContext) {
                results.RepoName = repoName[:len(repoName)-5]
        }
 
-       owner, err := models.GetUserByName(results.OwnerName)
+       owner, err := user_model.GetUserByName(results.OwnerName)
        if err != nil {
                log.Error("Unable to get repository owner: %s/%s Error: %v", results.OwnerName, results.RepoName, err)
                ctx.JSON(http.StatusInternalServerError, private.ErrServCommand{
@@ -214,7 +215,7 @@ func ServCommand(ctx *context.PrivateContext) {
        // So now we need to check if the key is a deploy key
        // We'll keep hold of the deploy key here for permissions checking
        var deployKey *models.DeployKey
-       var user *models.User
+       var user *user_model.User
        if key.Type == models.KeyTypeDeploy {
                results.IsDeployKey = true
 
@@ -248,9 +249,9 @@ func ServCommand(ctx *context.PrivateContext) {
        } else {
                // Get the user represented by the Key
                var err error
-               user, err = models.GetUserByID(key.OwnerID)
+               user, err = user_model.GetUserByID(key.OwnerID)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.JSON(http.StatusUnauthorized, private.ErrServCommand{
                                        Results: results,
                                        Err:     fmt.Sprintf("Public Key: %d:%s owner %d does not exist.", key.ID, key.Name, key.OwnerID),
@@ -333,7 +334,7 @@ func ServCommand(ctx *context.PrivateContext) {
 
        // We already know we aren't using a deploy key
        if !repoExist {
-               owner, err := models.GetUserByName(ownerName)
+               owner, err := user_model.GetUserByName(ownerName)
                if err != nil {
                        ctx.JSON(http.StatusInternalServerError, private.ErrServCommand{
                                Results: results,
index df3118b60f22ceeb880c9b83c82434caa6b2ea08..3d440d83cb184ef77be6f98c894c64fdd40d455b 100644 (file)
@@ -6,8 +6,8 @@
 package admin
 
 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/base"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/setting"
@@ -25,9 +25,9 @@ func Organizations(ctx *context.Context) {
        ctx.Data["PageIsAdmin"] = true
        ctx.Data["PageIsAdminOrganizations"] = true
 
-       explore.RenderUserSearch(ctx, &models.SearchUserOptions{
+       explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{
                Actor: ctx.User,
-               Type:  models.UserTypeOrganization,
+               Type:  user_model.UserTypeOrganization,
                ListOptions: db.ListOptions{
                        PageSize: setting.UI.Admin.OrgPagingNum,
                },
index 432dd2f6ae60706d3c5fba8881f5dcb22ef984d4..69e522ef7e9b215e30b39b71696c69edfc38dddc 100644 (file)
@@ -11,6 +11,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/base"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/log"
@@ -119,9 +120,9 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
                return
        }
 
-       ctxUser, err := models.GetUserByName(dirSplit[0])
+       ctxUser, err := user_model.GetUserByName(dirSplit[0])
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        log.Debug("User does not exist: %s", dirSplit[0])
                        ctx.Redirect(setting.AppSubURL + "/admin/repos")
                        return
index 077cf02f15a715e30006abf67324d65cd040e95f..b92c5cf01a8e45c394630dc94e2fab51eba41e51 100644 (file)
@@ -56,9 +56,9 @@ func Users(ctx *context.Context) {
                "SortType":        sortType,
        }
 
-       explore.RenderUserSearch(ctx, &models.SearchUserOptions{
+       explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{
                Actor: ctx.User,
-               Type:  models.UserTypeIndividual,
+               Type:  user_model.UserTypeIndividual,
                ListOptions: db.ListOptions{
                        PageSize: setting.UI.Admin.UserPagingNum,
                },
@@ -114,7 +114,7 @@ func NewUserPost(ctx *context.Context) {
                return
        }
 
-       u := &models.User{
+       u := &user_model.User{
                Name:      form.UserName,
                Email:     form.Email,
                Passwd:    form.Password,
@@ -156,9 +156,9 @@ func NewUserPost(ctx *context.Context) {
                u.MustChangePassword = form.MustChangePassword
        }
 
-       if err := models.CreateUser(u, &models.CreateUserOverwriteOptions{Visibility: form.Visibility}); err != nil {
+       if err := user_model.CreateUser(u, &user_model.CreateUserOverwriteOptions{Visibility: form.Visibility}); err != nil {
                switch {
-               case models.IsErrUserAlreadyExist(err):
+               case user_model.IsErrUserAlreadyExist(err):
                        ctx.Data["Err_UserName"] = true
                        ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplUserNew, &form)
                case user_model.IsErrEmailAlreadyUsed(err):
@@ -167,15 +167,15 @@ func NewUserPost(ctx *context.Context) {
                case user_model.IsErrEmailInvalid(err):
                        ctx.Data["Err_Email"] = true
                        ctx.RenderWithErr(ctx.Tr("form.email_invalid"), tplUserNew, &form)
-               case models.IsErrNameReserved(err):
+               case db.IsErrNameReserved(err):
                        ctx.Data["Err_UserName"] = true
-                       ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplUserNew, &form)
-               case models.IsErrNamePatternNotAllowed(err):
+                       ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(db.ErrNameReserved).Name), tplUserNew, &form)
+               case db.IsErrNamePatternNotAllowed(err):
                        ctx.Data["Err_UserName"] = true
-                       ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form)
-               case models.IsErrNameCharsNotAllowed(err):
+                       ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form)
+               case db.IsErrNameCharsNotAllowed(err):
                        ctx.Data["Err_UserName"] = true
-                       ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(models.ErrNameCharsNotAllowed).Name), tplUserNew, &form)
+                       ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(db.ErrNameCharsNotAllowed).Name), tplUserNew, &form)
                default:
                        ctx.ServerError("CreateUser", err)
                }
@@ -192,8 +192,8 @@ func NewUserPost(ctx *context.Context) {
        ctx.Redirect(setting.AppSubURL + "/admin/users/" + strconv.FormatInt(u.ID, 10))
 }
 
-func prepareUserInfo(ctx *context.Context) *models.User {
-       u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
+func prepareUserInfo(ctx *context.Context) *user_model.User {
+       u, err := user_model.GetUserByID(ctx.ParamsInt64(":userid"))
        if err != nil {
                ctx.ServerError("GetUserByID", err)
                return nil
@@ -298,7 +298,7 @@ func EditUserPost(ctx *context.Context) {
                        ctx.RenderWithErr(errMsg, tplUserNew, &form)
                        return
                }
-               if u.Salt, err = models.GetUserSalt(); err != nil {
+               if u.Salt, err = user_model.GetUserSalt(); err != nil {
                        ctx.ServerError("UpdateUser", err)
                        return
                }
@@ -352,7 +352,7 @@ func EditUserPost(ctx *context.Context) {
                u.ProhibitLogin = form.ProhibitLogin
        }
 
-       if err := models.UpdateUser(u); err != nil {
+       if err := user_model.UpdateUser(u); err != nil {
                if user_model.IsErrEmailAlreadyUsed(err) {
                        ctx.Data["Err_Email"] = true
                        ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form)
@@ -372,7 +372,7 @@ func EditUserPost(ctx *context.Context) {
 
 // DeleteUser response for deleting a user
 func DeleteUser(ctx *context.Context) {
-       u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
+       u, err := user_model.GetUserByID(ctx.ParamsInt64(":userid"))
        if err != nil {
                ctx.ServerError("GetUserByID", err)
                return
index 607ef2ea663485eb718314e2619fd928a6d7eba9..1849781bc47e06f61f20a24a276e9b27cbca9aa2 100644 (file)
@@ -7,8 +7,8 @@ package admin
 import (
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/test"
@@ -23,10 +23,10 @@ func TestNewUserPost_MustChangePassword(t *testing.T) {
        unittest.PrepareTestEnv(t)
        ctx := test.MockContext(t, "admin/users/new")
 
-       u := unittest.AssertExistsAndLoadBean(t, &models.User{
+       u := unittest.AssertExistsAndLoadBean(t, &user_model.User{
                IsAdmin: true,
                ID:      2,
-       }).(*models.User)
+       }).(*user_model.User)
 
        ctx.User = u
 
@@ -48,7 +48,7 @@ func TestNewUserPost_MustChangePassword(t *testing.T) {
 
        assert.NotEmpty(t, ctx.Flash.SuccessMsg)
 
-       u, err := models.GetUserByName(username)
+       u, err := user_model.GetUserByName(username)
 
        assert.NoError(t, err)
        assert.Equal(t, username, u.Name)
@@ -60,10 +60,10 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
        unittest.PrepareTestEnv(t)
        ctx := test.MockContext(t, "admin/users/new")
 
-       u := unittest.AssertExistsAndLoadBean(t, &models.User{
+       u := unittest.AssertExistsAndLoadBean(t, &user_model.User{
                IsAdmin: true,
                ID:      2,
-       }).(*models.User)
+       }).(*user_model.User)
 
        ctx.User = u
 
@@ -85,7 +85,7 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
 
        assert.NotEmpty(t, ctx.Flash.SuccessMsg)
 
-       u, err := models.GetUserByName(username)
+       u, err := user_model.GetUserByName(username)
 
        assert.NoError(t, err)
        assert.Equal(t, username, u.Name)
@@ -97,10 +97,10 @@ func TestNewUserPost_InvalidEmail(t *testing.T) {
        unittest.PrepareTestEnv(t)
        ctx := test.MockContext(t, "admin/users/new")
 
-       u := unittest.AssertExistsAndLoadBean(t, &models.User{
+       u := unittest.AssertExistsAndLoadBean(t, &user_model.User{
                IsAdmin: true,
                ID:      2,
-       }).(*models.User)
+       }).(*user_model.User)
 
        ctx.User = u
 
@@ -127,10 +127,10 @@ func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) {
        unittest.PrepareTestEnv(t)
        ctx := test.MockContext(t, "admin/users/new")
 
-       u := unittest.AssertExistsAndLoadBean(t, &models.User{
+       u := unittest.AssertExistsAndLoadBean(t, &user_model.User{
                IsAdmin: true,
                ID:      2,
-       }).(*models.User)
+       }).(*user_model.User)
 
        ctx.User = u
 
@@ -152,7 +152,7 @@ func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) {
 
        assert.NotEmpty(t, ctx.Flash.SuccessMsg)
 
-       u, err := models.GetUserByName(username)
+       u, err := user_model.GetUserByName(username)
 
        assert.NoError(t, err)
        assert.Equal(t, username, u.Name)
@@ -165,10 +165,10 @@ func TestNewUserPost_VisibilityPrivate(t *testing.T) {
        unittest.PrepareTestEnv(t)
        ctx := test.MockContext(t, "admin/users/new")
 
-       u := unittest.AssertExistsAndLoadBean(t, &models.User{
+       u := unittest.AssertExistsAndLoadBean(t, &user_model.User{
                IsAdmin: true,
                ID:      2,
-       }).(*models.User)
+       }).(*user_model.User)
 
        ctx.User = u
 
@@ -191,7 +191,7 @@ func TestNewUserPost_VisibilityPrivate(t *testing.T) {
 
        assert.NotEmpty(t, ctx.Flash.SuccessMsg)
 
-       u, err := models.GetUserByName(username)
+       u, err := user_model.GetUserByName(username)
 
        assert.NoError(t, err)
        assert.Equal(t, username, u.Name)
index de334c4f8b88015df11bee19acf273838c2429cb..29d6033a7a10946efe41cf7bc1a7ce18bbfb2bbb 100644 (file)
@@ -7,7 +7,7 @@ package dev
 import (
        "net/http"
 
-       "code.gitea.io/gitea/models"
+       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"
@@ -16,7 +16,7 @@ import (
 
 // TemplatePreview render for previewing the indicated template
 func TemplatePreview(ctx *context.Context) {
-       ctx.Data["User"] = models.User{Name: "Unknown"}
+       ctx.Data["User"] = user_model.User{Name: "Unknown"}
        ctx.Data["AppName"] = setting.AppName
        ctx.Data["AppVer"] = setting.AppVer
        ctx.Data["AppUrl"] = setting.AppURL
index d005cfa50322da0890b71dde379d0d85ef290541..41c0a0c83cf3a10bf41f9e50814d427361a355bd 100644 (file)
@@ -5,8 +5,8 @@
 package explore
 
 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/base"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/setting"
@@ -31,9 +31,9 @@ func Organizations(ctx *context.Context) {
                visibleTypes = append(visibleTypes, structs.VisibleTypeLimited, structs.VisibleTypePrivate)
        }
 
-       RenderUserSearch(ctx, &models.SearchUserOptions{
+       RenderUserSearch(ctx, &user_model.SearchUserOptions{
                Actor:       ctx.User,
-               Type:        models.UserTypeOrganization,
+               Type:        user_model.UserTypeOrganization,
                ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
                Visible:     visibleTypes,
        }, tplExploreOrganizations)
index 78035037e510550cdd152117a314b1af9224edfb..a81386b5fd77bf01b969033a281b739c3b509230 100644 (file)
@@ -39,38 +39,38 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
                repos   []*models.Repository
                count   int64
                err     error
-               orderBy models.SearchOrderBy
+               orderBy db.SearchOrderBy
        )
 
        ctx.Data["SortType"] = ctx.FormString("sort")
        switch ctx.FormString("sort") {
        case "newest":
-               orderBy = models.SearchOrderByNewest
+               orderBy = db.SearchOrderByNewest
        case "oldest":
-               orderBy = models.SearchOrderByOldest
+               orderBy = db.SearchOrderByOldest
        case "recentupdate":
-               orderBy = models.SearchOrderByRecentUpdated
+               orderBy = db.SearchOrderByRecentUpdated
        case "leastupdate":
-               orderBy = models.SearchOrderByLeastUpdated
+               orderBy = db.SearchOrderByLeastUpdated
        case "reversealphabetically":
-               orderBy = models.SearchOrderByAlphabeticallyReverse
+               orderBy = db.SearchOrderByAlphabeticallyReverse
        case "alphabetically":
-               orderBy = models.SearchOrderByAlphabetically
+               orderBy = db.SearchOrderByAlphabetically
        case "reversesize":
-               orderBy = models.SearchOrderBySizeReverse
+               orderBy = db.SearchOrderBySizeReverse
        case "size":
-               orderBy = models.SearchOrderBySize
+               orderBy = db.SearchOrderBySize
        case "moststars":
-               orderBy = models.SearchOrderByStarsReverse
+               orderBy = db.SearchOrderByStarsReverse
        case "feweststars":
-               orderBy = models.SearchOrderByStars
+               orderBy = db.SearchOrderByStars
        case "mostforks":
-               orderBy = models.SearchOrderByForksReverse
+               orderBy = db.SearchOrderByForksReverse
        case "fewestforks":
-               orderBy = models.SearchOrderByForks
+               orderBy = db.SearchOrderByForks
        default:
                ctx.Data["SortType"] = "recentupdate"
-               orderBy = models.SearchOrderByRecentUpdated
+               orderBy = db.SearchOrderByRecentUpdated
        }
 
        keyword := ctx.FormTrim("q")
index 1fe45ed58563b93caaa25093636d3c49c3ec6df6..85603784479e8df1149e882a3a0b45d2929a256f 100644 (file)
@@ -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/base"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/setting"
@@ -34,17 +35,17 @@ func isKeywordValid(keyword string) bool {
 }
 
 // RenderUserSearch render user search page
-func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplName base.TplName) {
+func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, tplName base.TplName) {
        opts.Page = ctx.FormInt("page")
        if opts.Page <= 1 {
                opts.Page = 1
        }
 
        var (
-               users   []*models.User
+               users   []*user_model.User
                count   int64
                err     error
-               orderBy models.SearchOrderBy
+               orderBy db.SearchOrderBy
        )
 
        // we can not set orderBy to `models.SearchOrderByXxx`, because there may be a JOIN in the statement, different tables may have the same name columns
@@ -69,7 +70,7 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN
        opts.Keyword = ctx.FormTrim("q")
        opts.OrderBy = orderBy
        if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) {
-               users, count, err = models.SearchUsers(opts)
+               users, count, err = user_model.SearchUsers(opts)
                if err != nil {
                        ctx.ServerError("SearchUsers", err)
                        return
@@ -100,9 +101,9 @@ func Users(ctx *context.Context) {
        ctx.Data["PageIsExploreUsers"] = true
        ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
 
-       RenderUserSearch(ctx, &models.SearchUserOptions{
+       RenderUserSearch(ctx, &user_model.SearchUserOptions{
                Actor:       ctx.User,
-               Type:        models.UserTypeIndividual,
+               Type:        user_model.UserTypeIndividual,
                ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
                IsActive:    util.OptionalBoolTrue,
                Visible:     []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate},
index 8bd0cb7c29c3f053c04c241e118a77451986179e..1a7f4ad24b21ec4469ddd09af3f87dd88bef0a23 100644 (file)
@@ -9,6 +9,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/context"
 
        "github.com/gorilla/feeds"
@@ -22,7 +23,7 @@ func RetrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) []*mode
                return nil
        }
 
-       userCache := map[int64]*models.User{options.RequestedUser.ID: options.RequestedUser}
+       userCache := map[int64]*user_model.User{options.RequestedUser.ID: options.RequestedUser}
        if ctx.User != nil {
                userCache[ctx.User.ID] = ctx.User
        }
@@ -35,9 +36,9 @@ func RetrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) []*mode
        for _, act := range actions {
                repoOwner, ok := userCache[act.Repo.OwnerID]
                if !ok {
-                       repoOwner, err = models.GetUserByID(act.Repo.OwnerID)
+                       repoOwner, err = user_model.GetUserByID(act.Repo.OwnerID)
                        if err != nil {
-                               if models.IsErrUserNotExist(err) {
+                               if user_model.IsErrUserNotExist(err) {
                                        continue
                                }
                                ctx.ServerError("GetUserByID", err)
@@ -51,7 +52,7 @@ func RetrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) []*mode
 }
 
 // ShowUserFeed show user activity as RSS / Atom feed
-func ShowUserFeed(ctx *context.Context, ctxUser *models.User, formatType string) {
+func ShowUserFeed(ctx *context.Context, ctxUser *user_model.User, formatType string) {
        actions := RetrieveFeeds(ctx, models.GetFeedsOptions{
                RequestedUser:   ctxUser,
                Actor:           ctx.User,
index 6e81257135270c632d2bd77be8ffcdab44e1a494..0dc441fe84a5be57c0285be704f66778bea6d7e7 100644 (file)
@@ -50,32 +50,32 @@ func Home(ctx *context.Context) {
                ctx.Data["RenderedDescription"] = desc
        }
 
-       var orderBy models.SearchOrderBy
+       var orderBy db.SearchOrderBy
        ctx.Data["SortType"] = ctx.FormString("sort")
        switch ctx.FormString("sort") {
        case "newest":
-               orderBy = models.SearchOrderByNewest
+               orderBy = db.SearchOrderByNewest
        case "oldest":
-               orderBy = models.SearchOrderByOldest
+               orderBy = db.SearchOrderByOldest
        case "recentupdate":
-               orderBy = models.SearchOrderByRecentUpdated
+               orderBy = db.SearchOrderByRecentUpdated
        case "leastupdate":
-               orderBy = models.SearchOrderByLeastUpdated
+               orderBy = db.SearchOrderByLeastUpdated
        case "reversealphabetically":
-               orderBy = models.SearchOrderByAlphabeticallyReverse
+               orderBy = db.SearchOrderByAlphabeticallyReverse
        case "alphabetically":
-               orderBy = models.SearchOrderByAlphabetically
+               orderBy = db.SearchOrderByAlphabetically
        case "moststars":
-               orderBy = models.SearchOrderByStarsReverse
+               orderBy = db.SearchOrderByStarsReverse
        case "feweststars":
-               orderBy = models.SearchOrderByStars
+               orderBy = db.SearchOrderByStars
        case "mostforks":
-               orderBy = models.SearchOrderByForksReverse
+               orderBy = db.SearchOrderByForksReverse
        case "fewestforks":
-               orderBy = models.SearchOrderByForks
+               orderBy = db.SearchOrderByForks
        default:
                ctx.Data["SortType"] = "recentupdate"
-               orderBy = models.SearchOrderByRecentUpdated
+               orderBy = db.SearchOrderByRecentUpdated
        }
 
        keyword := ctx.FormTrim("q")
index 6722f8d104c4326b3b56b8959a504f62be82a5cd..c66a0cd4c83d6d16d956d1b9d5a686a36267f444 100644 (file)
@@ -10,6 +10,8 @@ import (
        "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"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/log"
@@ -52,7 +54,7 @@ func CreatePost(ctx *context.Context) {
        org := &models.Organization{
                Name:                      form.OrgName,
                IsActive:                  true,
-               Type:                      models.UserTypeOrganization,
+               Type:                      user_model.UserTypeOrganization,
                Visibility:                form.Visibility,
                RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
        }
@@ -60,12 +62,12 @@ func CreatePost(ctx *context.Context) {
        if err := models.CreateOrganization(org, ctx.User); err != nil {
                ctx.Data["Err_OrgName"] = true
                switch {
-               case models.IsErrUserAlreadyExist(err):
+               case user_model.IsErrUserAlreadyExist(err):
                        ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), tplCreateOrg, &form)
-               case models.IsErrNameReserved(err):
-                       ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), tplCreateOrg, &form)
-               case models.IsErrNamePatternNotAllowed(err):
-                       ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form)
+               case db.IsErrNameReserved(err):
+                       ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(db.ErrNameReserved).Name), tplCreateOrg, &form)
+               case db.IsErrNamePatternNotAllowed(err):
+                       ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form)
                case models.IsErrUserNotAllowedCreateOrg(err):
                        ctx.RenderWithErr(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form)
                default:
index 7a6f4fec60f51c7c92c81e7b28bd29655feaff02..f0e1db14d086fe2c21c08c08d1f0336f6a9e67b4 100644 (file)
@@ -12,6 +12,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/models/webhook"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/context"
@@ -61,7 +62,7 @@ func SettingsPost(ctx *context.Context) {
 
        // Check if organization name has been changed.
        if org.LowerName != strings.ToLower(form.Name) {
-               isExist, err := models.IsUserExist(org.ID, form.Name)
+               isExist, err := user_model.IsUserExist(org.ID, form.Name)
                if err != nil {
                        ctx.ServerError("IsUserExist", err)
                        return
@@ -69,8 +70,8 @@ func SettingsPost(ctx *context.Context) {
                        ctx.Data["OrgName"] = true
                        ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSettingsOptions, &form)
                        return
-               } else if err = models.ChangeUserName(org.AsUser(), form.Name); err != nil {
-                       if err == models.ErrUserNameIllegal {
+               } else if err = user_model.ChangeUserName(org.AsUser(), form.Name); err != nil {
+                       if err == user_model.ErrUserNameIllegal {
                                ctx.Data["OrgName"] = true
                                ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form)
                        } else {
@@ -101,7 +102,7 @@ func SettingsPost(ctx *context.Context) {
        visibilityChanged := form.Visibility != org.Visibility
        org.Visibility = form.Visibility
 
-       if err := models.UpdateUser(org.AsUser()); err != nil {
+       if err := user_model.UpdateUser(org.AsUser()); err != nil {
                ctx.ServerError("UpdateUser", err)
                return
        }
index ac6a42904a87d0f334017b32a3de16548b7c51cd..da0830aad9a854d5b646272e7a495cda680dbff8 100644 (file)
@@ -13,6 +13,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/base"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/log"
@@ -114,10 +115,10 @@ func TeamsAction(ctx *context.Context) {
                        return
                }
                uname := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("uname")))
-               var u *models.User
-               u, err = models.GetUserByName(uname)
+               var u *user_model.User
+               u, err = user_model.GetUserByName(uname)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
                                ctx.Redirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName))
                        } else {
index 2fd72d81ab10aa0e48e1a24da635f4878853fb6c..5786aa1eb2dc217a1e3fe0339e31b63c881de722 100644 (file)
@@ -12,6 +12,7 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models"
+       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/git"
@@ -139,9 +140,9 @@ func RefBlame(ctx *context.Context) {
        ctx.HTML(http.StatusOK, tplBlame)
 }
 
-func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[string]*models.UserCommit, map[string]string) {
+func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[string]*user_model.UserCommit, map[string]string) {
        // store commit data by SHA to look up avatar info etc
-       commitNames := make(map[string]*models.UserCommit)
+       commitNames := make(map[string]*user_model.UserCommit)
        // previousCommits contains links from SHA to parent SHA,
        // if parent also contains the current TreePath.
        previousCommits := make(map[string]string)
@@ -195,14 +196,14 @@ func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[st
        }
 
        // populate commit email addresses to later look up avatars.
-       for _, c := range models.ValidateCommitsWithEmails(commits) {
+       for _, c := range user_model.ValidateCommitsWithEmails(commits) {
                commitNames[c.ID.String()] = c
        }
 
        return commitNames, previousCommits
 }
 
-func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames map[string]*models.UserCommit, previousCommits map[string]string) {
+func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames map[string]*user_model.UserCommit, previousCommits map[string]string) {
        repoLink := ctx.Repo.RepoLink
 
        language := ""
index ecb5107a3d9b751c3987c5b3d373370aca89648f..48386f7935fd7b672791b9080be85295c5fdfb5b 100644 (file)
@@ -12,6 +12,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/base"
        "code.gitea.io/gitea/modules/charset"
        "code.gitea.io/gitea/modules/context"
@@ -344,7 +345,7 @@ func Diff(ctx *context.Context) {
 
        verification := models.ParseCommitWithSignature(commit)
        ctx.Data["Verification"] = verification
-       ctx.Data["Author"] = models.ValidateCommitWithEmail(commit)
+       ctx.Data["Author"] = user_model.ValidateCommitWithEmail(commit)
        ctx.Data["Parents"] = parents
        ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0
 
@@ -358,7 +359,7 @@ func Diff(ctx *context.Context) {
        if err == nil {
                ctx.Data["Note"] = string(charset.ToUTF8WithFallback(note.Message))
                ctx.Data["NoteCommit"] = note.Commit
-               ctx.Data["NoteAuthor"] = models.ValidateCommitWithEmail(note.Commit)
+               ctx.Data["NoteAuthor"] = user_model.ValidateCommitWithEmail(note.Commit)
        }
 
        ctx.Data["BranchName"], err = commit.GetBranchName()
index 706009820a4ebd77be16d92ff7d6a80a94ddf529..865a734caf2fbbcad5dbd7aef14ca89efc08de3e 100644 (file)
@@ -18,6 +18,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/base"
        "code.gitea.io/gitea/modules/charset"
        "code.gitea.io/gitea/modules/context"
@@ -163,7 +164,7 @@ func setCsvCompareContext(ctx *context.Context) {
 
 // CompareInfo represents the collected results from ParseCompareInfo
 type CompareInfo struct {
-       HeadUser         *models.User
+       HeadUser         *user_model.User
        HeadRepo         *models.Repository
        HeadGitRepo      *git.Repository
        CompareInfo      *git.CompareInfo
@@ -237,9 +238,9 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
        } else if len(headInfos) == 2 {
                headInfosSplit := strings.Split(headInfos[0], "/")
                if len(headInfosSplit) == 1 {
-                       ci.HeadUser, err = models.GetUserByName(headInfos[0])
+                       ci.HeadUser, err = user_model.GetUserByName(headInfos[0])
                        if err != nil {
-                               if models.IsErrUserNotExist(err) {
+                               if user_model.IsErrUserNotExist(err) {
                                        ctx.NotFound("GetUserByName", nil)
                                } else {
                                        ctx.ServerError("GetUserByName", err)
@@ -262,7 +263,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
                                return nil
                        }
                        if err := ci.HeadRepo.GetOwner(); err != nil {
-                               if models.IsErrUserNotExist(err) {
+                               if user_model.IsErrUserNotExist(err) {
                                        ctx.NotFound("GetUserByName", nil)
                                } else {
                                        ctx.ServerError("GetUserByName", err)
index 0626d08a7cf6bf033359ec9f882c159ba8d7e5dd..ce2d977518e23e5b569cdf7f2b4fade5191d725b 100644 (file)
@@ -110,9 +110,9 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
                reponame = reponame[:len(reponame)-5]
        }
 
-       owner, err := models.GetUserByName(username)
+       owner, err := user_model.GetUserByName(username)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        if redirectUserID, err := user_model.LookupUserRedirect(username); err == nil {
                                context.RedirectToUser(ctx, username, redirectUserID)
                        } else {
index ac6240e282dd9cf74581d0d5614ea8a756ab0052..1ff126c7d164ae083465e883a1e1235924f0bbdc 100644 (file)
@@ -20,6 +20,7 @@ import (
        "code.gitea.io/gitea/models/db"
        repo_model "code.gitea.io/gitea/models/repo"
        "code.gitea.io/gitea/models/unit"
+       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/convert"
@@ -470,7 +471,7 @@ func retrieveProjects(ctx *context.Context, repo *models.Repository) {
 type repoReviewerSelection struct {
        IsTeam    bool
        Team      *models.Team
-       User      *models.User
+       User      *user_model.User
        Review    *models.Review
        CanChange bool
        Checked   bool
@@ -503,7 +504,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issue
                reviewersResult     []*repoReviewerSelection
                teamReviewersResult []*repoReviewerSelection
                teamReviewers       []*models.Team
-               reviewers           []*models.User
+               reviewers           []*user_model.User
        )
 
        if canChooseReviewer {
@@ -575,7 +576,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issue
                for _, item := range pullReviews {
                        if item.Review.ReviewerID > 0 {
                                if err = item.Review.LoadReviewer(); err != nil {
-                                       if models.IsErrUserNotExist(err) {
+                                       if user_model.IsErrUserNotExist(err) {
                                                continue
                                        }
                                        ctx.ServerError("LoadReviewer", err)
@@ -919,7 +920,7 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull
 
                // Check if the passed assignees actually exists and is assignable
                for _, aID := range assigneeIDs {
-                       assignee, err := models.GetUserByID(aID)
+                       assignee, err := user_model.GetUserByID(aID)
                        if err != nil {
                                ctx.ServerError("GetUserByID", err)
                                return nil, nil, 0, 0
@@ -1019,7 +1020,7 @@ func NewIssuePost(ctx *context.Context) {
 }
 
 // roleDescriptor returns the Role Decriptor for a comment in/with the given repo, poster and issue
-func roleDescriptor(repo *models.Repository, poster *models.User, issue *models.Issue) (models.RoleDescriptor, error) {
+func roleDescriptor(repo *models.Repository, poster *user_model.User, issue *models.Issue) (models.RoleDescriptor, error) {
        perm, err := models.GetUserRepoPermission(repo, poster)
        if err != nil {
                return models.RoleDescriptorNone, err
@@ -1267,7 +1268,7 @@ func ViewIssue(ctx *context.Context) {
                ok           bool
                marked       = make(map[int64]models.RoleDescriptor)
                comment      *models.Comment
-               participants = make([]*models.User, 1, 10)
+               participants = make([]*user_model.User, 1, 10)
        )
        if ctx.Repo.Repository.IsTimetrackerEnabled() {
                if ctx.IsSigned {
@@ -1430,11 +1431,11 @@ func ViewIssue(ctx *context.Context) {
                                continue
                        }
                        if err = comment.Review.LoadAttributes(); err != nil {
-                               if !models.IsErrUserNotExist(err) {
+                               if !user_model.IsErrUserNotExist(err) {
                                        ctx.ServerError("Review.LoadAttributes", err)
                                        return
                                }
-                               comment.Review.Reviewer = models.NewGhostUser()
+                               comment.Review.Reviewer = user_model.NewGhostUser()
                        }
                        if err = comment.Review.LoadCodeComments(); err != nil {
                                ctx.ServerError("Review.LoadCodeComments", err)
@@ -1833,12 +1834,12 @@ func UpdateIssueAssignee(ctx *context.Context) {
        for _, issue := range issues {
                switch action {
                case "clear":
-                       if err := issue_service.DeleteNotPassedAssignee(issue, ctx.User, []*models.User{}); err != nil {
+                       if err := issue_service.DeleteNotPassedAssignee(issue, ctx.User, []*user_model.User{}); err != nil {
                                ctx.ServerError("ClearAssignees", err)
                                return
                        }
                default:
-                       assignee, err := models.GetUserByID(assigneeID)
+                       assignee, err := user_model.GetUserByID(assigneeID)
                        if err != nil {
                                ctx.ServerError("GetUserByID", err)
                                return
@@ -1949,9 +1950,9 @@ func UpdatePullReviewRequest(ctx *context.Context) {
                        continue
                }
 
-               reviewer, err := models.GetUserByID(reviewID)
+               reviewer, err := user_model.GetUserByID(reviewID)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                log.Warn(
                                        "UpdatePullReviewRequest: requested reviewer [%d] for %-v to %-v#%d is not exist: Error: %v",
                                        reviewID, issue.Repo, issue.Index,
@@ -2452,7 +2453,7 @@ func ChangeCommentReaction(ctx *context.Context) {
        })
 }
 
-func addParticipant(poster *models.User, participants []*models.User) []*models.User {
+func addParticipant(poster *user_model.User, participants []*user_model.User) []*user_model.User {
        for _, part := range participants {
                if poster.ID == part.ID {
                        return participants
index b15c7628db6ed9f707005ebfd06144674178a507..b1bc06f08b467098ca4e1d6df3ec9355a672aea4 100644 (file)
@@ -216,9 +216,9 @@ func LFSLockFile(ctx *context.Context) {
        }
 
        _, err := models.CreateLFSLock(&models.LFSLock{
-               Repo:  ctx.Repo.Repository,
-               Path:  lockPath,
-               Owner: ctx.User,
+               Repo:    ctx.Repo.Repository,
+               Path:    lockPath,
+               OwnerID: ctx.User.ID,
        })
        if err != nil {
                if models.IsErrLFSLockAlreadyExist(err) {
index 0dc6e1cb7204e12244eb76ac8a201933e2d2cdbc..3ee9d1a3e98f11e6480eb27a9e927d83c6fc52f8 100644 (file)
@@ -7,8 +7,8 @@ package repo
 import (
        "fmt"
 
-       "code.gitea.io/gitea/models"
        admin_model "code.gitea.io/gitea/models/admin"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/git"
 )
@@ -56,7 +56,7 @@ func SetDiffViewStyle(ctx *context.Context) {
        }
 
        ctx.Data["IsSplitStyle"] = style == "split"
-       if err := models.UpdateUserDiffViewStyle(ctx.User, style); err != nil {
+       if err := user_model.UpdateUserDiffViewStyle(ctx.User, style); err != nil {
                ctx.ServerError("ErrUpdateDiffViewStyle", err)
        }
 }
index 1940d89628699f434f531d5772e421c452267af5..5eba4690d0e4cf0e8a2fff8a697efa2610ebd64b 100644 (file)
@@ -11,6 +11,8 @@ import (
        "strings"
 
        "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"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/lfs"
@@ -66,7 +68,7 @@ func Migrate(ctx *context.Context) {
        ctx.HTML(http.StatusOK, base.TplName("repo/migrate/"+serviceType.Name()))
 }
 
-func handleMigrateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form *forms.MigrateRepoForm) {
+func handleMigrateError(ctx *context.Context, owner *user_model.User, err error, name string, tpl base.TplName, form *forms.MigrateRepoForm) {
        if setting.Repository.DisableMigrations {
                ctx.Error(http.StatusForbidden, "MigrateError: the site administrator has disabled migrations")
                return
@@ -94,12 +96,12 @@ func handleMigrateError(ctx *context.Context, owner *models.User, err error, nam
                default:
                        ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tpl, form)
                }
-       case models.IsErrNameReserved(err):
+       case db.IsErrNameReserved(err):
                ctx.Data["Err_RepoName"] = true
-               ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form)
-       case models.IsErrNamePatternNotAllowed(err):
+               ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
+       case db.IsErrNamePatternNotAllowed(err):
                ctx.Data["Err_RepoName"] = true
-               ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
+               ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
        default:
                remoteAddr, _ := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
                err = util.NewStringURLSanitizedError(err, remoteAddr, true)
index 83e353833fc724914a5e72b45234526b3d061cb6..06aa86206d24ec749f14e6943b7bb49c504779fb 100644 (file)
@@ -20,6 +20,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       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/git"
@@ -237,10 +238,10 @@ func ForkPost(ctx *context.Context) {
                switch {
                case models.IsErrRepoAlreadyExist(err):
                        ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
-               case models.IsErrNameReserved(err):
-                       ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplFork, &form)
-               case models.IsErrNamePatternNotAllowed(err):
-                       ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form)
+               case db.IsErrNameReserved(err):
+                       ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplFork, &form)
+               case db.IsErrNamePatternNotAllowed(err):
+                       ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplFork, &form)
                default:
                        ctx.ServerError("ForkPost", err)
                }
@@ -1024,7 +1025,7 @@ func MergePullRequest(ctx *context.Context) {
        ctx.Redirect(issue.Link())
 }
 
-func stopTimerIfAvailable(user *models.User, issue *models.Issue) error {
+func stopTimerIfAvailable(user *user_model.User, issue *models.Issue) error {
 
        if models.StopwatchExists(user.ID, issue.ID) {
                if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil {
@@ -1185,9 +1186,9 @@ func TriggerTask(ctx *context.Context) {
                return
        }
 
-       pusher, err := models.GetUserByID(pusherID)
+       pusher, err := user_model.GetUserByID(pusherID)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Error(http.StatusNotFound)
                } else {
                        ctx.ServerError("GetUserByID", err)
index 3f12ee72bcb4554265f737eda15c55515fb4bc17..9bca4e6897840e0e8e43721e5e2bfb15d03cd736 100644 (file)
@@ -13,6 +13,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       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/log"
@@ -132,7 +133,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
 
        // Temporary cache commits count of used branches to speed up.
        countCache := make(map[string]int64)
-       cacheUsers := make(map[int64]*models.User)
+       cacheUsers := make(map[int64]*user_model.User)
        if ctx.User != nil {
                cacheUsers[ctx.User.ID] = ctx.User
        }
@@ -140,10 +141,10 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
 
        for _, r := range releases {
                if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok {
-                       r.Publisher, err = models.GetUserByID(r.PublisherID)
+                       r.Publisher, err = user_model.GetUserByID(r.PublisherID)
                        if err != nil {
-                               if models.IsErrUserNotExist(err) {
-                                       r.Publisher = models.NewGhostUser()
+                               if user_model.IsErrUserNotExist(err) {
+                                       r.Publisher = user_model.NewGhostUser()
                                } else {
                                        ctx.ServerError("GetUserByID", err)
                                        return
@@ -207,10 +208,10 @@ func SingleRelease(ctx *context.Context) {
                return
        }
 
-       release.Publisher, err = models.GetUserByID(release.PublisherID)
+       release.Publisher, err = user_model.GetUserByID(release.PublisherID)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
-                       release.Publisher = models.NewGhostUser()
+               if user_model.IsErrUserNotExist(err) {
+                       release.Publisher = user_model.NewGhostUser()
                } else {
                        ctx.ServerError("GetUserByID", err)
                        return
index 9463fc4c5f7a207eff4f26b965522555a40a7e1a..bacfa549b51954f020545c703d4828df7b17550b 100644 (file)
@@ -16,6 +16,7 @@ import (
        "code.gitea.io/gitea/models/db"
        repo_model "code.gitea.io/gitea/models/repo"
        "code.gitea.io/gitea/models/unit"
+       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/graceful"
@@ -55,7 +56,7 @@ func MustBeAbleToUpload(ctx *context.Context) {
        }
 }
 
-func checkContextUser(ctx *context.Context, uid int64) *models.User {
+func checkContextUser(ctx *context.Context, uid int64) *user_model.User {
        orgs, err := models.GetOrgsCanCreateRepoByUserID(ctx.User.ID)
        if err != nil {
                ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
@@ -79,8 +80,8 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
                return ctx.User
        }
 
-       org, err := models.GetUserByID(uid)
-       if models.IsErrUserNotExist(err) {
+       org, err := user_model.GetUserByID(uid)
+       if user_model.IsErrUserNotExist(err) {
                return ctx.User
        }
 
@@ -158,7 +159,7 @@ func Create(ctx *context.Context) {
        ctx.HTML(http.StatusOK, tplCreate)
 }
 
-func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) {
+func handleCreateError(ctx *context.Context, owner *user_model.User, err error, name string, tpl base.TplName, form interface{}) {
        switch {
        case models.IsErrReachLimitOfRepo(err):
                ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.MaxCreationLimit()), tpl, form)
@@ -177,12 +178,12 @@ func handleCreateError(ctx *context.Context, owner *models.User, err error, name
                default:
                        ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tpl, form)
                }
-       case models.IsErrNameReserved(err):
+       case db.IsErrNameReserved(err):
                ctx.Data["Err_RepoName"] = true
-               ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form)
-       case models.IsErrNamePatternNotAllowed(err):
+               ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
+       case db.IsErrNamePatternNotAllowed(err):
                ctx.Data["Err_RepoName"] = true
-               ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
+               ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
        default:
                ctx.ServerError(name, err)
        }
index 6753ce11722b591db5deb4290b695a048690474a..20fa9ea785517df04cc0eac869479ea5ff776030 100644 (file)
@@ -17,6 +17,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        unit_model "code.gitea.io/gitea/models/unit"
+       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/git"
@@ -94,8 +95,8 @@ func SettingsPost(ctx *context.Context) {
                                switch {
                                case models.IsErrRepoAlreadyExist(err):
                                        ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tplSettingsOptions, &form)
-                               case models.IsErrNameReserved(err):
-                                       ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplSettingsOptions, &form)
+                               case db.IsErrNameReserved(err):
+                                       ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplSettingsOptions, &form)
                                case models.IsErrRepoFilesAlreadyExist(err):
                                        ctx.Data["Err_RepoName"] = true
                                        switch {
@@ -108,8 +109,8 @@ func SettingsPost(ctx *context.Context) {
                                        default:
                                                ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tplSettingsOptions, form)
                                        }
-                               case models.IsErrNamePatternNotAllowed(err):
-                                       ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form)
+                               case db.IsErrNamePatternNotAllowed(err):
+                                       ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form)
                                default:
                                        ctx.ServerError("ChangeRepositoryName", err)
                                }
@@ -577,9 +578,9 @@ func SettingsPost(ctx *context.Context) {
                        return
                }
 
-               newOwner, err := models.GetUserByName(ctx.FormString("new_owner_name"))
+               newOwner, err := user_model.GetUserByName(ctx.FormString("new_owner_name"))
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
                                return
                        }
@@ -587,7 +588,7 @@ func SettingsPost(ctx *context.Context) {
                        return
                }
 
-               if newOwner.Type == models.UserTypeOrganization {
+               if newOwner.Type == user_model.UserTypeOrganization {
                        if !ctx.User.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) {
                                // The user shouldn't know about this organization
                                ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
@@ -798,9 +799,9 @@ func CollaborationPost(ctx *context.Context) {
                return
        }
 
-       u, err := models.GetUserByName(name)
+       u, err := user_model.GetUserByName(name)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
                        ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath())
                } else {
@@ -935,10 +936,10 @@ func DeleteTeam(ctx *context.Context) {
 }
 
 // parseOwnerAndRepo get repos by owner
-func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository) {
-       owner, err := models.GetUserByName(ctx.Params(":username"))
+func parseOwnerAndRepo(ctx *context.Context) (*user_model.User, *models.Repository) {
+       owner, err := user_model.GetUserByName(ctx.Params(":username"))
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.NotFound("GetUserByName", err)
                } else {
                        ctx.ServerError("GetUserByName", err)
index 3e8ae2b07e925257f33afb3e4ef254dd879633b5..8e53babe7c3dbf41c8534984e04370aa03dc9ca2 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/test"
@@ -105,9 +106,9 @@ func TestCollaborationPost(t *testing.T) {
 
        ctx.Req.Form.Set("collaborator", "user4")
 
-       u := &models.User{
+       u := &user_model.User{
                LowerName: "user2",
-               Type:      models.UserTypeIndividual,
+               Type:      user_model.UserTypeIndividual,
        }
 
        re := &models.Repository{
@@ -142,7 +143,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) {
        ctx.Req.Form.Set("collaborator", "user9")
 
        repo := &context.Repository{
-               Owner: &models.User{
+               Owner: &user_model.User{
                        LowerName: "user2",
                },
        }
@@ -165,9 +166,9 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
 
        ctx.Req.Form.Set("collaborator", "user4")
 
-       u := &models.User{
+       u := &user_model.User{
                LowerName: "user2",
-               Type:      models.UserTypeIndividual,
+               Type:      user_model.UserTypeIndividual,
        }
 
        re := &models.Repository{
@@ -207,7 +208,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) {
        ctx.Req.Form.Set("collaborator", "user34")
 
        repo := &context.Repository{
-               Owner: &models.User{
+               Owner: &user_model.User{
                        LowerName: "user2",
                },
        }
@@ -226,9 +227,9 @@ func TestAddTeamPost(t *testing.T) {
 
        ctx.Req.Form.Set("team", "team11")
 
-       org := &models.User{
+       org := &user_model.User{
                LowerName: "org26",
-               Type:      models.UserTypeOrganization,
+               Type:      user_model.UserTypeOrganization,
        }
 
        team := &models.Team{
@@ -243,7 +244,7 @@ func TestAddTeamPost(t *testing.T) {
        }
 
        repo := &context.Repository{
-               Owner: &models.User{
+               Owner: &user_model.User{
                        ID:                        26,
                        LowerName:                 "org26",
                        RepoAdminChangeTeamAccess: true,
@@ -266,9 +267,9 @@ func TestAddTeamPost_NotAllowed(t *testing.T) {
 
        ctx.Req.Form.Set("team", "team11")
 
-       org := &models.User{
+       org := &user_model.User{
                LowerName: "org26",
-               Type:      models.UserTypeOrganization,
+               Type:      user_model.UserTypeOrganization,
        }
 
        team := &models.Team{
@@ -283,7 +284,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) {
        }
 
        repo := &context.Repository{
-               Owner: &models.User{
+               Owner: &user_model.User{
                        ID:                        26,
                        LowerName:                 "org26",
                        RepoAdminChangeTeamAccess: false,
@@ -307,9 +308,9 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) {
 
        ctx.Req.Form.Set("team", "team11")
 
-       org := &models.User{
+       org := &user_model.User{
                LowerName: "org26",
-               Type:      models.UserTypeOrganization,
+               Type:      user_model.UserTypeOrganization,
        }
 
        team := &models.Team{
@@ -324,7 +325,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) {
        }
 
        repo := &context.Repository{
-               Owner: &models.User{
+               Owner: &user_model.User{
                        ID:                        26,
                        LowerName:                 "org26",
                        RepoAdminChangeTeamAccess: true,
@@ -348,9 +349,9 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) {
 
        ctx.Req.Form.Set("team", "team-non-existent")
 
-       org := &models.User{
+       org := &user_model.User{
                LowerName: "org26",
-               Type:      models.UserTypeOrganization,
+               Type:      user_model.UserTypeOrganization,
        }
 
        re := &models.Repository{
@@ -360,7 +361,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) {
        }
 
        repo := &context.Repository{
-               Owner: &models.User{
+               Owner: &user_model.User{
                        ID:                        26,
                        LowerName:                 "org26",
                        RepoAdminChangeTeamAccess: true,
@@ -381,9 +382,9 @@ func TestDeleteTeam(t *testing.T) {
 
        ctx.Req.Form.Set("id", "2")
 
-       org := &models.User{
+       org := &user_model.User{
                LowerName: "org3",
-               Type:      models.UserTypeOrganization,
+               Type:      user_model.UserTypeOrganization,
        }
 
        team := &models.Team{
@@ -398,7 +399,7 @@ func TestDeleteTeam(t *testing.T) {
        }
 
        repo := &context.Repository{
-               Owner: &models.User{
+               Owner: &user_model.User{
                        ID:                        3,
                        LowerName:                 "org3",
                        RepoAdminChangeTeamAccess: true,
index 1293882cc5f164811e6d09059322b59273c8f5b0..33420aab3b9e04f9528c0f83a65ebe25ba5831df 100644 (file)
@@ -22,6 +22,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        unit_model "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/cache"
        "code.gitea.io/gitea/modules/charset"
@@ -449,7 +450,12 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
                return
        }
        if lfsLock != nil {
-               ctx.Data["LFSLockOwner"] = lfsLock.Owner.DisplayName()
+               u, err := user_model.GetUserByID(lfsLock.OwnerID)
+               if err != nil {
+                       ctx.ServerError("GetTreePathLock", err)
+                       return
+               }
+               ctx.Data["LFSLockOwner"] = u.DisplayName()
                ctx.Data["LFSLockHint"] = ctx.Tr("repo.editor.this_file_locked")
        }
 
@@ -777,7 +783,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri
                        return nil
                }
                ctx.Data["LatestCommitVerification"] = verification
-               ctx.Data["LatestCommitUser"] = models.ValidateCommitWithEmail(latestCommit)
+               ctx.Data["LatestCommitUser"] = user_model.ValidateCommitWithEmail(latestCommit)
        }
 
        statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{})
@@ -893,7 +899,7 @@ func renderCode(ctx *context.Context) {
 }
 
 // RenderUserCards render a page show users according the input template
-func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*models.User, error), tpl base.TplName) {
+func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) {
        page := ctx.FormInt("page")
        if page <= 0 {
                page = 1
@@ -928,7 +934,7 @@ func Stars(ctx *context.Context) {
        ctx.Data["Title"] = ctx.Tr("repo.stargazers")
        ctx.Data["CardsTitle"] = ctx.Tr("repo.stargazers")
        ctx.Data["PageIsStargazers"] = true
-       RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*models.User, error) {
+       RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*user_model.User, error) {
                return models.GetStargazers(ctx.Repo.Repository, opts)
        }, tplWatchers)
 }
index 4f6660926ee1e630bf71a720b9b505a1cdcea1f8..28ca3e0de54e9fd7e053da3c3c47db4b98e44690 100644 (file)
@@ -15,6 +15,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/models/webhook"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/context"
@@ -1149,7 +1150,7 @@ func TestWebhook(ctx *context.Context) {
        // Grab latest commit or fake one if it's empty repository.
        commit := ctx.Repo.Commit
        if commit == nil {
-               ghost := models.NewGhostUser()
+               ghost := user_model.NewGhostUser()
                commit = &git.Commit{
                        ID:            git.MustIDFromString(git.EmptySHA),
                        Author:        ghost.NewGitSig(),
index c5164c4956e14c97d433b529cb1b94dfa27a0031..02f5afd8bae4f2a59d5b5bbe70b1cdcde8099c66 100644 (file)
@@ -76,9 +76,9 @@ func AutoSignIn(ctx *context.Context) (bool, error) {
                }
        }()
 
-       u, err := models.GetUserByName(uname)
+       u, err := user_model.GetUserByName(uname)
        if err != nil {
-               if !models.IsErrUserNotExist(err) {
+               if !user_model.IsErrUserNotExist(err) {
                        return false, fmt.Errorf("GetUserByName: %v", err)
                }
                return false, nil
@@ -180,17 +180,17 @@ func SignInPost(ctx *context.Context) {
        form := web.GetForm(ctx).(*forms.SignInForm)
        u, source, err := auth.UserSignIn(form.UserName, form.Password)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
                        log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
                } else if user_model.IsErrEmailAlreadyUsed(err) {
                        ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form)
                        log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
-               } else if models.IsErrUserProhibitLogin(err) {
+               } else if user_model.IsErrUserProhibitLogin(err) {
                        log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
                        ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
                        ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
-               } else if models.IsErrUserInactive(err) {
+               } else if user_model.IsErrUserInactive(err) {
                        if setting.Service.RegisterEmailConfirm {
                                ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
                                ctx.HTML(http.StatusOK, TplActivate)
@@ -314,7 +314,7 @@ func TwoFactorPost(ctx *context.Context) {
 
        if ok && twofa.LastUsedPasscode != form.Passcode {
                remember := ctx.Session.Get("twofaRemember").(bool)
-               u, err := models.GetUserByID(id)
+               u, err := user_model.GetUserByID(id)
                if err != nil {
                        ctx.ServerError("UserSignIn", err)
                        return
@@ -398,7 +398,7 @@ func TwoFactorScratchPost(ctx *context.Context) {
                }
 
                remember := ctx.Session.Get("twofaRemember").(bool)
-               u, err := models.GetUserByID(id)
+               u, err := user_model.GetUserByID(id)
                if err != nil {
                        ctx.ServerError("UserSignIn", err)
                        return
@@ -495,7 +495,7 @@ func U2FSign(ctx *context.Context) {
                newCounter, authErr := r.Authenticate(*signResp, *challenge, reg.Counter)
                if authErr == nil {
                        reg.Counter = newCounter
-                       user, err := models.GetUserByID(id)
+                       user, err := user_model.GetUserByID(id)
                        if err != nil {
                                ctx.ServerError("UserSignIn", err)
                                return
@@ -531,11 +531,11 @@ func U2FSign(ctx *context.Context) {
 }
 
 // This handles the final part of the sign-in process of the user.
-func handleSignIn(ctx *context.Context, u *models.User, remember bool) {
+func handleSignIn(ctx *context.Context, u *user_model.User, remember bool) {
        handleSignInFull(ctx, u, remember, true)
 }
 
-func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyRedirect bool) string {
+func handleSignInFull(ctx *context.Context, u *user_model.User, remember bool, obeyRedirect bool) string {
        if remember {
                days := 86400 * setting.LogInRememberDays
                ctx.SetCookie(setting.CookieUserName, u.Name, days)
@@ -565,7 +565,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
        // If the user does not have a locale set, we save the current one.
        if len(u.Language) == 0 {
                u.Language = ctx.Locale.Language()
-               if err := models.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
+               if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
                        log.Error(fmt.Sprintf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language))
                        return setting.AppSubURL + "/"
                }
@@ -582,7 +582,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
 
        // Register last login
        u.SetLastLogin()
-       if err := models.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
+       if err := user_model.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
                ctx.ServerError("UpdateUserCols", err)
                return setting.AppSubURL + "/"
        }
@@ -680,7 +680,7 @@ func SignInOAuthCallback(ctx *context.Context) {
                                ctx.ServerError("CreateUser", err)
                                return
                        }
-                       u = &models.User{
+                       u = &user_model.User{
                                Name:        getUserName(&gothUser),
                                FullName:    gothUser.Name,
                                Email:       gothUser.Email,
@@ -725,7 +725,7 @@ func showLinkingLogin(ctx *context.Context, gothUser goth.User) {
        ctx.Redirect(setting.AppSubURL + "/user/link_account")
 }
 
-func updateAvatarIfNeed(url string, u *models.User) {
+func updateAvatarIfNeed(url string, u *user_model.User) {
        if setting.OAuth2Client.UpdateAvatar && len(url) > 0 {
                resp, err := http.Get(url)
                if err == nil {
@@ -743,7 +743,7 @@ func updateAvatarIfNeed(url string, u *models.User) {
        }
 }
 
-func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.User, gothUser goth.User) {
+func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *user_model.User, gothUser goth.User) {
        updateAvatarIfNeed(gothUser.AvatarURL, u)
 
        needs2FA := false
@@ -774,7 +774,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.Us
 
                // Register last login
                u.SetLastLogin()
-               if err := models.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
+               if err := user_model.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
                        ctx.ServerError("UpdateUserCols", err)
                        return
                }
@@ -817,7 +817,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.Us
 
 // OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful
 // login the user
-func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) {
+func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, response http.ResponseWriter) (*user_model.User, goth.User, error) {
        gothUser, err := loginSource.Cfg.(*oauth2.Source).Callback(request, response)
        if err != nil {
                if err.Error() == "securecookie: the value is too long" || strings.Contains(err.Error(), "Data too long") {
@@ -827,13 +827,13 @@ func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, r
                return nil, goth.User{}, err
        }
 
-       user := &models.User{
+       user := &user_model.User{
                LoginName:   gothUser.UserID,
                LoginType:   login.OAuth2,
                LoginSource: loginSource.ID,
        }
 
-       hasUser, err := models.GetUser(user)
+       hasUser, err := user_model.GetUser(user)
        if err != nil {
                return nil, goth.User{}, err
        }
@@ -852,7 +852,7 @@ func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, r
                return nil, goth.User{}, err
        }
        if hasUser {
-               user, err = models.GetUserByID(externalLoginUser.UserID)
+               user, err = user_model.GetUserByID(externalLoginUser.UserID)
                return user, gothUser, err
        }
 
@@ -893,8 +893,8 @@ func LinkAccount(ctx *context.Context) {
        ctx.Data["email"] = email
 
        if len(email) != 0 {
-               u, err := models.GetUserByEmail(email)
-               if err != nil && !models.IsErrUserNotExist(err) {
+               u, err := user_model.GetUserByEmail(email)
+               if err != nil && !user_model.IsErrUserNotExist(err) {
                        ctx.ServerError("UserSignIn", err)
                        return
                }
@@ -902,8 +902,8 @@ func LinkAccount(ctx *context.Context) {
                        ctx.Data["user_exists"] = true
                }
        } else if len(uname) != 0 {
-               u, err := models.GetUserByName(uname)
-               if err != nil && !models.IsErrUserNotExist(err) {
+               u, err := user_model.GetUserByName(uname)
+               if err != nil && !user_model.IsErrUserNotExist(err) {
                        ctx.ServerError("UserSignIn", err)
                        return
                }
@@ -948,7 +948,7 @@ func LinkAccountPostSignIn(ctx *context.Context) {
 
        u, _, err := auth.UserSignIn(signInForm.UserName, signInForm.Password)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Data["user_exists"] = true
                        ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplLinkAccount, &signInForm)
                } else {
@@ -960,7 +960,7 @@ func LinkAccountPostSignIn(ctx *context.Context) {
        linkAccount(ctx, u, gothUser.(goth.User), signInForm.Remember)
 }
 
-func linkAccount(ctx *context.Context, u *models.User, gothUser goth.User, remember bool) {
+func linkAccount(ctx *context.Context, u *user_model.User, gothUser goth.User, remember bool) {
        updateAvatarIfNeed(gothUser.AvatarURL, u)
 
        // If this user is enrolled in 2FA, we can't sign the user in just yet.
@@ -1081,7 +1081,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
        }
 
        if setting.Service.AllowOnlyExternalRegistration || !setting.Service.RequireExternalRegistrationPassword {
-               // In models.User an empty password is classed as not set, so we set form.Password to empty.
+               // In user_model.User an empty password is classed as not set, so we set form.Password to empty.
                // Eventually the database should be changed to indicate "Second Factor"-enabled accounts
                // (accounts that do not introduce the security vulnerabilities of a password).
                // If a user decides to circumvent second-factor security, and purposefully create a password,
@@ -1105,7 +1105,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
                ctx.ServerError("CreateUser", err)
        }
 
-       u := &models.User{
+       u := &user_model.User{
                Name:        form.UserName,
                Email:       form.Email,
                Passwd:      form.Password,
@@ -1249,7 +1249,7 @@ func SignUpPost(ctx *context.Context) {
                return
        }
 
-       u := &models.User{
+       u := &user_model.User{
                Name:         form.UserName,
                Email:        form.Email,
                Passwd:       form.Password,
@@ -1268,7 +1268,7 @@ func SignUpPost(ctx *context.Context) {
 
 // createAndHandleCreatedUser calls createUserInContext and
 // then handleUserCreated.
-func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form interface{}, u *models.User, gothUser *goth.User, allowLink bool) bool {
+func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, gothUser *goth.User, allowLink bool) bool {
        if !createUserInContext(ctx, tpl, form, u, gothUser, allowLink) {
                return false
        }
@@ -1277,16 +1277,16 @@ func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form int
 
 // createUserInContext creates a user and handles errors within a given context.
 // Optionally a template can be specified.
-func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{}, u *models.User, gothUser *goth.User, allowLink bool) (ok bool) {
-       if err := models.CreateUser(u); err != nil {
-               if allowLink && (models.IsErrUserAlreadyExist(err) || user_model.IsErrEmailAlreadyUsed(err)) {
+func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, gothUser *goth.User, allowLink bool) (ok bool) {
+       if err := user_model.CreateUser(u); err != nil {
+               if allowLink && (user_model.IsErrUserAlreadyExist(err) || user_model.IsErrEmailAlreadyUsed(err)) {
                        if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingAuto {
-                               var user *models.User
-                               user = &models.User{Name: u.Name}
-                               hasUser, err := models.GetUser(user)
+                               var user *user_model.User
+                               user = &user_model.User{Name: u.Name}
+                               hasUser, err := user_model.GetUser(user)
                                if !hasUser || err != nil {
-                                       user = &models.User{Email: u.Email}
-                                       hasUser, err = models.GetUser(user)
+                                       user = &user_model.User{Email: u.Email}
+                                       hasUser, err = user_model.GetUser(user)
                                        if !hasUser || err != nil {
                                                ctx.ServerError("UserLinkAccount", err)
                                                return
@@ -1310,7 +1310,7 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{
 
                // handle error with template
                switch {
-               case models.IsErrUserAlreadyExist(err):
+               case user_model.IsErrUserAlreadyExist(err):
                        ctx.Data["Err_UserName"] = true
                        ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tpl, form)
                case user_model.IsErrEmailAlreadyUsed(err):
@@ -1319,15 +1319,15 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{
                case user_model.IsErrEmailInvalid(err):
                        ctx.Data["Err_Email"] = true
                        ctx.RenderWithErr(ctx.Tr("form.email_invalid"), tpl, form)
-               case models.IsErrNameReserved(err):
+               case db.IsErrNameReserved(err):
                        ctx.Data["Err_UserName"] = true
-                       ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form)
-               case models.IsErrNamePatternNotAllowed(err):
+                       ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
+               case db.IsErrNamePatternNotAllowed(err):
                        ctx.Data["Err_UserName"] = true
-                       ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
-               case models.IsErrNameCharsNotAllowed(err):
+                       ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
+               case db.IsErrNameCharsNotAllowed(err):
                        ctx.Data["Err_UserName"] = true
-                       ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(models.ErrNameCharsNotAllowed).Name), tpl, form)
+                       ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(db.ErrNameCharsNotAllowed).Name), tpl, form)
                default:
                        ctx.ServerError("CreateUser", err)
                }
@@ -1340,13 +1340,13 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{
 // handleUserCreated does additional steps after a new user is created.
 // It auto-sets admin for the only user, updates the optional external user and
 // sends a confirmation email if required.
-func handleUserCreated(ctx *context.Context, u *models.User, gothUser *goth.User) (ok bool) {
+func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.User) (ok bool) {
        // Auto-set admin for the only user.
-       if models.CountUsers() == 1 {
+       if user_model.CountUsers() == 1 {
                u.IsAdmin = true
                u.IsActive = true
                u.SetLastLogin()
-               if err := models.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_active", "last_login_unix"); err != nil {
+               if err := user_model.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_active", "last_login_unix"); err != nil {
                        ctx.ServerError("UpdateUser", err)
                        return
                }
@@ -1406,7 +1406,7 @@ func Activate(ctx *context.Context) {
                return
        }
 
-       user := models.VerifyUserActiveCode(code)
+       user := user_model.VerifyUserActiveCode(code)
        // if code is wrong
        if user == nil {
                ctx.Data["IsActivateFailed"] = true
@@ -1433,7 +1433,7 @@ func ActivatePost(ctx *context.Context) {
                return
        }
 
-       user := models.VerifyUserActiveCode(code)
+       user := user_model.VerifyUserActiveCode(code)
        // if code is wrong
        if user == nil {
                ctx.Data["IsActivateFailed"] = true
@@ -1460,15 +1460,15 @@ func ActivatePost(ctx *context.Context) {
        handleAccountActivation(ctx, user)
 }
 
-func handleAccountActivation(ctx *context.Context, user *models.User) {
+func handleAccountActivation(ctx *context.Context, user *user_model.User) {
        user.IsActive = true
        var err error
-       if user.Rands, err = models.GetUserSalt(); err != nil {
+       if user.Rands, err = user_model.GetUserSalt(); err != nil {
                ctx.ServerError("UpdateUser", err)
                return
        }
-       if err := models.UpdateUserCols(db.DefaultContext, user, "is_active", "rands"); err != nil {
-               if models.IsErrUserNotExist(err) {
+       if err := user_model.UpdateUserCols(db.DefaultContext, user, "is_active", "rands"); err != nil {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.NotFound("UpdateUserCols", err)
                } else {
                        ctx.ServerError("UpdateUser", err)
@@ -1512,7 +1512,7 @@ func ActivateEmail(ctx *context.Context) {
                log.Trace("Email activated: %s", email.Email)
                ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
 
-               if u, err := models.GetUserByID(email.UID); err != nil {
+               if u, err := user_model.GetUserByID(email.UID); err != nil {
                        log.Warn("GetUserByID: %d", email.UID)
                } else {
                        // Allow user to validate more emails
@@ -1556,9 +1556,9 @@ func ForgotPasswdPost(ctx *context.Context) {
        email := ctx.FormString("email")
        ctx.Data["Email"] = email
 
-       u, err := models.GetUserByEmail(email)
+       u, err := user_model.GetUserByEmail(email)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
                        ctx.Data["IsResetSent"] = true
                        ctx.HTML(http.StatusOK, tplForgotPassword)
@@ -1592,7 +1592,7 @@ func ForgotPasswdPost(ctx *context.Context) {
        ctx.HTML(http.StatusOK, tplForgotPassword)
 }
 
-func commonResetPassword(ctx *context.Context) (*models.User, *login.TwoFactor) {
+func commonResetPassword(ctx *context.Context) (*user_model.User, *login.TwoFactor) {
        code := ctx.FormString("code")
 
        ctx.Data["Title"] = ctx.Tr("auth.reset_password")
@@ -1608,7 +1608,7 @@ func commonResetPassword(ctx *context.Context) (*models.User, *login.TwoFactor)
        }
 
        // Fail early, don't frustrate the user
-       u := models.VerifyUserActiveCode(code)
+       u := user_model.VerifyUserActiveCode(code)
        if u == nil {
                ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
                return nil, nil
@@ -1718,7 +1718,7 @@ func ResetPasswdPost(ctx *context.Context) {
                }
        }
        var err error
-       if u.Rands, err = models.GetUserSalt(); err != nil {
+       if u.Rands, err = user_model.GetUserSalt(); err != nil {
                ctx.ServerError("UpdateUser", err)
                return
        }
@@ -1727,7 +1727,7 @@ func ResetPasswdPost(ctx *context.Context) {
                return
        }
        u.MustChangePassword = false
-       if err := models.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
+       if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
                ctx.ServerError("UpdateUser", err)
                return
        }
@@ -1803,7 +1803,7 @@ func MustChangePasswordPost(ctx *context.Context) {
 
        u.MustChangePassword = false
 
-       if err := models.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
+       if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
                ctx.ServerError("UpdateUser", err)
                return
        }
index 4724a7b431fc73587eff0633a9d1fc71ef72dd5a..68e166d12c782243ea8c5881a9c245bf771f68c4 100644 (file)
@@ -9,7 +9,6 @@ import (
        "net/http"
        "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"
@@ -163,9 +162,9 @@ func signInOpenIDVerify(ctx *context.Context) {
        /* Now we should seek for the user and log him in, or prompt
         * to register if not found */
 
-       u, err := models.GetUserByOpenID(id)
+       u, err := user_model.GetUserByOpenID(id)
        if err != nil {
-               if !models.IsErrUserNotExist(err) {
+               if !user_model.IsErrUserNotExist(err) {
                        ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
                                Openid: id,
                        })
@@ -203,9 +202,9 @@ func signInOpenIDVerify(ctx *context.Context) {
        log.Trace("User has email=" + email + " and nickname=" + nickname)
 
        if email != "" {
-               u, err = models.GetUserByEmail(email)
+               u, err = user_model.GetUserByEmail(email)
                if err != nil {
-                       if !models.IsErrUserNotExist(err) {
+                       if !user_model.IsErrUserNotExist(err) {
                                ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
                                        Openid: id,
                                })
@@ -219,9 +218,9 @@ func signInOpenIDVerify(ctx *context.Context) {
        }
 
        if u == nil && nickname != "" {
-               u, _ = models.GetUserByName(nickname)
+               u, _ = user_model.GetUserByName(nickname)
                if err != nil {
-                       if !models.IsErrUserNotExist(err) {
+                       if !user_model.IsErrUserNotExist(err) {
                                ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
                                        Openid: id,
                                })
@@ -294,7 +293,7 @@ func ConnectOpenIDPost(ctx *context.Context) {
 
        u, _, err := auth.UserSignIn(form.UserName, form.Password)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplConnectOID, &form)
                } else {
                        ctx.ServerError("ConnectOpenIDPost", err)
@@ -419,7 +418,7 @@ func RegisterOpenIDPost(ctx *context.Context) {
                return
        }
 
-       u := &models.User{
+       u := &user_model.User{
                Name:     form.UserName,
                Email:    form.Email,
                Passwd:   password,
index f39bcc36d343b698d4d37ae2f454ff4e73a32a72..c8bca9dc2c1df3b10b7f3daba91773b0a0c63e3b 100644 (file)
@@ -8,8 +8,8 @@ import (
        "strings"
        "time"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/avatars"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/httpcache"
 )
@@ -27,15 +27,15 @@ func AvatarByUserName(ctx *context.Context) {
        userName := ctx.Params(":username")
        size := int(ctx.ParamsInt64(":size"))
 
-       var user *models.User
+       var user *user_model.User
        if strings.ToLower(userName) != "ghost" {
                var err error
-               if user, err = models.GetUserByName(userName); err != nil {
+               if user, err = user_model.GetUserByName(userName); err != nil {
                        ctx.ServerError("Invalid user: "+userName, err)
                        return
                }
        } else {
-               user = models.NewGhostUser()
+               user = user_model.NewGhostUser()
        }
 
        cacheableRedirect(ctx, user.AvatarLinkWithSize(size))
index 9efbe755d905494cb8777a6b00fde50f52d392b0..ca2705a42fdb02d405cecdaf13c6b5ea2bb03f7d 100644 (file)
@@ -17,6 +17,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/context"
        issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
@@ -43,7 +44,7 @@ const (
 )
 
 // getDashboardContextUser finds out which context user dashboard is being viewed as .
-func getDashboardContextUser(ctx *context.Context) *models.User {
+func getDashboardContextUser(ctx *context.Context) *user_model.User {
        ctxUser := ctx.User
        orgName := ctx.Params(":org")
        if len(orgName) > 0 {
@@ -727,7 +728,7 @@ func getRepoIDs(reposQuery string) []int64 {
        return repoIDs
 }
 
-func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType unit.Type) ([]int64, error) {
+func getActiveUserRepoIDs(ctxUser *user_model.User, team *models.Team, unitType unit.Type) ([]int64, error) {
        var userRepoIDs []int64
        var err error
 
@@ -737,7 +738,7 @@ func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType unit
                        return nil, fmt.Errorf("orgRepoIds: %v", err)
                }
        } else {
-               userRepoIDs, err = ctxUser.GetActiveAccessRepoIDs(unitType)
+               userRepoIDs, err = models.GetActiveAccessRepoIDs(ctxUser, unitType)
                if err != nil {
                        return nil, fmt.Errorf("ctxUser.GetAccessRepoIDs: %v", err)
                }
@@ -752,7 +753,7 @@ func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType unit
 
 // getActiveTeamOrOrgRepoIds gets RepoIDs for ctxUser as Organization.
 // Should be called if and only if ctxUser.IsOrganization == true.
-func getActiveTeamOrOrgRepoIds(ctxUser *models.User, team *models.Team, unitType unit.Type) ([]int64, error) {
+func getActiveTeamOrOrgRepoIds(ctxUser *user_model.User, team *models.Team, unitType unit.Type) ([]int64, error) {
        var orgRepoIDs []int64
        var err error
        var env models.AccessibleReposEnvironment
@@ -777,7 +778,7 @@ func getActiveTeamOrOrgRepoIds(ctxUser *models.User, team *models.Team, unitType
        return orgRepoIDs, nil
 }
 
-func issueIDsFromSearch(ctxUser *models.User, keyword string, opts *models.IssuesOptions) ([]int64, error) {
+func issueIDsFromSearch(ctxUser *user_model.User, keyword string, opts *models.IssuesOptions) ([]int64, error) {
        if len(keyword) == 0 {
                return []int64{}, nil
        }
@@ -794,7 +795,7 @@ func issueIDsFromSearch(ctxUser *models.User, keyword string, opts *models.Issue
        return issueIDsFromSearch, nil
 }
 
-func repoIDMap(ctxUser *models.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*models.Repository, error) {
+func repoIDMap(ctxUser *user_model.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*models.Repository, error) {
        repoByID := make(map[int64]*models.Repository, len(issueCountByRepo))
        for id := range issueCountByRepo {
                if id <= 0 {
@@ -880,9 +881,9 @@ func ShowGPGKeys(ctx *context.Context, uid int64) {
 
 // Email2User show user page via email
 func Email2User(ctx *context.Context) {
-       u, err := models.GetUserByEmail(ctx.FormString("email"))
+       u, err := user_model.GetUserByEmail(ctx.FormString("email"))
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        ctx.NotFound("GetUserByEmail", err)
                } else {
                        ctx.ServerError("GetUserByEmail", err)
index 7b1854c52104f339112124277264d2b304a91be3..d3baeaedc4055b2956caab2df12116dd1ded263a 100644 (file)
@@ -14,6 +14,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/json"
@@ -170,9 +171,9 @@ func newAccessTokenResponse(grant *login.OAuth2Grant, serverKey, clientKey oauth
                                ErrorDescription: "cannot find application",
                        }
                }
-               user, err := models.GetUserByID(grant.UserID)
+               user, err := user_model.GetUserByID(grant.UserID)
                if err != nil {
-                       if models.IsErrUserNotExist(err) {
+                       if user_model.IsErrUserNotExist(err) {
                                return nil, &AccessTokenError{
                                        ErrorCode:        AccessTokenErrorCodeInvalidRequest,
                                        ErrorDescription: "cannot find user",
@@ -274,7 +275,7 @@ func InfoOAuth(ctx *context.Context) {
 
 // returns a list of "org" and "org:team" strings,
 // that the given user is a part of.
-func getOAuthGroupsForUser(user *models.User) ([]string, error) {
+func getOAuthGroupsForUser(user *user_model.User) ([]string, error) {
        orgs, err := models.GetUserOrgsList(user)
        if err != nil {
                return nil, fmt.Errorf("GetUserOrgList: %v", err)
@@ -359,7 +360,7 @@ func AuthorizeOAuth(ctx *context.Context) {
                return
        }
 
-       user, err := models.GetUserByID(app.UID)
+       user, err := user_model.GetUserByID(app.UID)
        if err != nil {
                ctx.ServerError("GetUserByID", err)
                return
index dfdaa9a1ed0e4af6baa4b59b7ffb23b705da90d8..e26a42b2fcf49c4231d7508d72a56acdbf4f9695 100644 (file)
@@ -7,9 +7,9 @@ package user
 import (
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/login"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/services/auth/source/oauth2"
 
        "github.com/golang-jwt/jwt"
@@ -58,7 +58,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
        assert.Empty(t, oidcToken.Email)
        assert.False(t, oidcToken.EmailVerified)
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
        grants, err = login.GetOAuth2GrantsByUserID(user.ID)
        assert.NoError(t, err)
        assert.Len(t, grants, 1)
index 2594ba3013b1e2507980cdadb434d35034709360..32d2bdde8388217b0e84cf04db97f5d861bd2805 100644 (file)
@@ -24,10 +24,10 @@ import (
 )
 
 // GetUserByName get user by name
-func GetUserByName(ctx *context.Context, name string) *models.User {
-       user, err := models.GetUserByName(name)
+func GetUserByName(ctx *context.Context, name string) *user_model.User {
+       user, err := user_model.GetUserByName(name)
        if err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        if redirectUserID, err := user_model.LookupUserRedirect(name); err == nil {
                                context.RedirectToUser(ctx, name, redirectUserID)
                        } else {
@@ -42,7 +42,7 @@ func GetUserByName(ctx *context.Context, name string) *models.User {
 }
 
 // GetUserByParams returns user whose name is presented in URL paramenter.
-func GetUserByParams(ctx *context.Context) *models.User {
+func GetUserByParams(ctx *context.Context) *user_model.User {
        return GetUserByName(ctx, ctx.Params(":username"))
 }
 
@@ -199,41 +199,41 @@ func Profile(ctx *context.Context) {
                repos   []*models.Repository
                count   int64
                total   int
-               orderBy models.SearchOrderBy
+               orderBy db.SearchOrderBy
        )
 
        ctx.Data["SortType"] = ctx.FormString("sort")
        switch ctx.FormString("sort") {
        case "newest":
-               orderBy = models.SearchOrderByNewest
+               orderBy = db.SearchOrderByNewest
        case "oldest":
-               orderBy = models.SearchOrderByOldest
+               orderBy = db.SearchOrderByOldest
        case "recentupdate":
-               orderBy = models.SearchOrderByRecentUpdated
+               orderBy = db.SearchOrderByRecentUpdated
        case "leastupdate":
-               orderBy = models.SearchOrderByLeastUpdated
+               orderBy = db.SearchOrderByLeastUpdated
        case "reversealphabetically":
-               orderBy = models.SearchOrderByAlphabeticallyReverse
+               orderBy = db.SearchOrderByAlphabeticallyReverse
        case "alphabetically":
-               orderBy = models.SearchOrderByAlphabetically
+               orderBy = db.SearchOrderByAlphabetically
        case "moststars":
-               orderBy = models.SearchOrderByStarsReverse
+               orderBy = db.SearchOrderByStarsReverse
        case "feweststars":
-               orderBy = models.SearchOrderByStars
+               orderBy = db.SearchOrderByStars
        case "mostforks":
-               orderBy = models.SearchOrderByForksReverse
+               orderBy = db.SearchOrderByForksReverse
        case "fewestforks":
-               orderBy = models.SearchOrderByForks
+               orderBy = db.SearchOrderByForks
        default:
                ctx.Data["SortType"] = "recentupdate"
-               orderBy = models.SearchOrderByRecentUpdated
+               orderBy = db.SearchOrderByRecentUpdated
        }
 
        keyword := ctx.FormTrim("q")
        ctx.Data["Keyword"] = keyword
        switch tab {
        case "followers":
-               items, err := models.GetUserFollowers(ctxUser, db.ListOptions{
+               items, err := user_model.GetUserFollowers(ctxUser, db.ListOptions{
                        PageSize: setting.UI.User.RepoPagingNum,
                        Page:     page,
                })
@@ -245,7 +245,7 @@ func Profile(ctx *context.Context) {
 
                total = ctxUser.NumFollowers
        case "following":
-               items, err := models.GetUserFollowing(ctxUser, db.ListOptions{
+               items, err := user_model.GetUserFollowing(ctxUser, db.ListOptions{
                        PageSize: setting.UI.User.RepoPagingNum,
                        Page:     page,
                })
index 603786697aa0d84abcabd032c7b13a41762eb09b..3b51fdb77752790bf4f007e9ed07519548d8201e 100644 (file)
@@ -75,7 +75,7 @@ func AccountPost(ctx *context.Context) {
                        ctx.ServerError("UpdateUser", err)
                        return
                }
-               if err := models.UpdateUserCols(db.DefaultContext, ctx.User, "salt", "passwd_hash_algo", "passwd"); err != nil {
+               if err := user_model.UpdateUserCols(db.DefaultContext, ctx.User, "salt", "passwd_hash_algo", "passwd"); err != nil {
                        ctx.ServerError("UpdateUser", err)
                        return
                }
@@ -152,14 +152,14 @@ func EmailPost(ctx *context.Context) {
        // Set Email Notification Preference
        if ctx.FormString("_method") == "NOTIFICATION" {
                preference := ctx.FormString("preference")
-               if !(preference == models.EmailNotificationsEnabled ||
-                       preference == models.EmailNotificationsOnMention ||
-                       preference == models.EmailNotificationsDisabled) {
+               if !(preference == user_model.EmailNotificationsEnabled ||
+                       preference == user_model.EmailNotificationsOnMention ||
+                       preference == user_model.EmailNotificationsDisabled) {
                        log.Error("Email notifications preference change returned unrecognized option %s: %s", preference, ctx.User.Name)
                        ctx.ServerError("SetEmailPreference", errors.New("option unrecognized"))
                        return
                }
-               if err := models.SetEmailNotifications(ctx.User, preference); err != nil {
+               if err := user_model.SetEmailNotifications(ctx.User, preference); err != nil {
                        log.Error("Set Email Notifications failed: %v", err)
                        ctx.ServerError("SetEmailNotifications", err)
                        return
@@ -233,7 +233,7 @@ func DeleteAccount(ctx *context.Context) {
        ctx.Data["PageIsSettingsAccount"] = true
 
        if _, _, err := auth.UserSignIn(ctx.User.Name, ctx.FormString("password")); err != nil {
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        loadAccountData(ctx)
 
                        ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsAccount, nil)
index 948cc1e9366c5dbbaa87c633da62fa969a46f09b..56ab6ec999450297b1bab48793684722a0382858 100644 (file)
@@ -8,6 +8,7 @@ import (
        "path/filepath"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/util"
@@ -27,7 +28,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
        action := ctx.FormString("action")
 
        ctxUser := ctx.User
-       root := models.UserPath(ctxUser.LowerName)
+       root := user_model.UserPath(ctxUser.LowerName)
 
        // check not a repo
        has, err := models.IsRepositoryExist(ctxUser, dir)
index 1e515f2fd31190a2fb3b0b091893c637e2a3cae5..0475398a9a851d164f34d4105c31d878698e9f6b 100644 (file)
@@ -49,7 +49,7 @@ func Profile(ctx *context.Context) {
 }
 
 // HandleUsernameChange handle username changes from user settings and admin interface
-func HandleUsernameChange(ctx *context.Context, user *models.User, newName string) error {
+func HandleUsernameChange(ctx *context.Context, user *user_model.User, newName string) error {
        // Non-local users are not allowed to change their username.
        if !user.IsLocal() {
                ctx.Flash.Error(ctx.Tr("form.username_change_not_local_user"))
@@ -58,17 +58,17 @@ func HandleUsernameChange(ctx *context.Context, user *models.User, newName strin
 
        // Check if user name has been changed
        if user.LowerName != strings.ToLower(newName) {
-               if err := models.ChangeUserName(user, newName); err != nil {
+               if err := user_model.ChangeUserName(user, newName); err != nil {
                        switch {
-                       case models.IsErrUserAlreadyExist(err):
+                       case user_model.IsErrUserAlreadyExist(err):
                                ctx.Flash.Error(ctx.Tr("form.username_been_taken"))
                        case user_model.IsErrEmailAlreadyUsed(err):
                                ctx.Flash.Error(ctx.Tr("form.email_been_used"))
-                       case models.IsErrNameReserved(err):
+                       case db.IsErrNameReserved(err):
                                ctx.Flash.Error(ctx.Tr("user.form.name_reserved", newName))
-                       case models.IsErrNamePatternNotAllowed(err):
+                       case db.IsErrNamePatternNotAllowed(err):
                                ctx.Flash.Error(ctx.Tr("user.form.name_pattern_not_allowed", newName))
-                       case models.IsErrNameCharsNotAllowed(err):
+                       case db.IsErrNameCharsNotAllowed(err):
                                ctx.Flash.Error(ctx.Tr("user.form.name_chars_not_allowed", newName))
                        default:
                                ctx.ServerError("ChangeUserName", err)
@@ -121,7 +121,7 @@ func ProfilePost(ctx *context.Context) {
        ctx.User.Description = form.Description
        ctx.User.KeepActivityPrivate = form.KeepActivityPrivate
        ctx.User.Visibility = form.Visibility
-       if err := models.UpdateUserSetting(ctx.User); err != nil {
+       if err := user_model.UpdateUserSetting(ctx.User); err != nil {
                if _, ok := err.(user_model.ErrEmailAlreadyUsed); ok {
                        ctx.Flash.Error(ctx.Tr("form.email_been_used"))
                        ctx.Redirect(setting.AppSubURL + "/user/settings")
@@ -141,7 +141,7 @@ func ProfilePost(ctx *context.Context) {
 
 // UpdateAvatarSetting update user's avatar
 // FIXME: limit size.
-func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *models.User) error {
+func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *user_model.User) error {
        ctxUser.UseCustomAvatar = form.Source == forms.AvatarLocal
        if len(form.Gravatar) > 0 {
                if form.Avatar != nil {
@@ -178,12 +178,12 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *
        } else if ctxUser.UseCustomAvatar && ctxUser.Avatar == "" {
                // No avatar is uploaded but setting has been changed to enable,
                // generate a random one when needed.
-               if err := models.GenerateRandomAvatar(ctxUser); err != nil {
+               if err := user_model.GenerateRandomAvatar(ctxUser); err != nil {
                        log.Error("GenerateRandomAvatar[%d]: %v", ctxUser.ID, err)
                }
        }
 
-       if err := models.UpdateUserCols(db.DefaultContext, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil {
+       if err := user_model.UpdateUserCols(db.DefaultContext, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil {
                return fmt.Errorf("UpdateUser: %v", err)
        }
 
@@ -273,7 +273,7 @@ func Repos(ctx *context.Context) {
                repoNames := make([]string, 0, setting.UI.Admin.UserPagingNum)
                repos := map[string]*models.Repository{}
                // We're going to iterate by pagesize.
-               root := models.UserPath(ctxUser.Name)
+               root := user_model.UserPath(ctxUser.Name)
                if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
                        if err != nil {
                                if os.IsNotExist(err) {
@@ -377,7 +377,7 @@ func UpdateUIThemePost(ctx *context.Context) {
                return
        }
 
-       if err := models.UpdateUserTheme(ctx.User, form.Theme); err != nil {
+       if err := user_model.UpdateUserTheme(ctx.User, form.Theme); err != nil {
                ctx.Flash.Error(ctx.Tr("settings.theme_update_error"))
                ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
                return
@@ -403,7 +403,7 @@ func UpdateUserLang(ctx *context.Context) {
                ctx.User.Language = form.Language
        }
 
-       if err := models.UpdateUserSetting(ctx.User); err != nil {
+       if err := user_model.UpdateUserSetting(ctx.User); err != nil {
                ctx.ServerError("UpdateUserSetting", err)
                return
        }
index f32ad371d550574763553484682addf0c5d96242..beb21940b0cd1e03f135e94f5a6d88a3cf944726 100644 (file)
@@ -11,6 +11,7 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/context"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
@@ -124,7 +125,7 @@ func ProcRecive(ctx *context.PrivateContext, opts *private.HookOptions) []privat
                                description = opts.GitPushOptions["description"]
                        }
 
-                       pusher, err := models.GetUserByID(opts.UserID)
+                       pusher, err := user_model.GetUserByID(opts.UserID)
                        if err != nil {
                                log.Error("Failed to get user. Error: %v", err)
                                ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
@@ -232,7 +233,7 @@ func ProcRecive(ctx *context.PrivateContext, opts *private.HookOptions) []privat
                }
 
                pull_service.AddToTaskQueue(pr)
-               pusher, err := models.GetUserByID(opts.UserID)
+               pusher, err := user_model.GetUserByID(opts.UserID)
                if err != nil {
                        log.Error("Failed to get user. Error: %v", err)
                        ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
@@ -268,7 +269,7 @@ func ProcRecive(ctx *context.PrivateContext, opts *private.HookOptions) []privat
 }
 
 // UserNameChanged hanle user name change for agit flow pull
-func UserNameChanged(user *models.User, newName string) error {
+func UserNameChanged(user *user_model.User, newName string) error {
        pulls, err := models.GetAllUnmergedAgitPullRequestByPoster(user.ID)
        if err != nil {
                return err
index a992fbf151d004ab8362ab7f878653ad11be0c8e..9ebd0d29ab442e30146574aa7818ab95e8e700f7 100644 (file)
@@ -9,9 +9,9 @@ import (
        "path/filepath"
        "testing"
 
-       "code.gitea.io/gitea/models"
        repo_model "code.gitea.io/gitea/models/repo"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -23,7 +23,7 @@ func TestMain(m *testing.M) {
 func TestUploadAttachment(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        fPath := "./attachment_test.go"
        f, err := os.Open(fPath)
index 3e48e15047968edcf0ea845babe45bd125f52a26..e53691221f5f82fbdadea8890704d3c5ab0ca97a 100644 (file)
@@ -12,8 +12,8 @@ import (
        "regexp"
        "strings"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/web/middleware"
@@ -105,7 +105,7 @@ func isGitRawReleaseOrLFSPath(req *http.Request) bool {
 }
 
 // handleSignIn clears existing session variables and stores new ones for the specified user object
-func handleSignIn(resp http.ResponseWriter, req *http.Request, sess SessionStore, user *models.User) {
+func handleSignIn(resp http.ResponseWriter, req *http.Request, sess SessionStore, user *user_model.User) {
        _ = sess.Delete("openid_verified_uri")
        _ = sess.Delete("openid_signin_remember")
        _ = sess.Delete("openid_determined_email")
@@ -128,7 +128,7 @@ func handleSignIn(resp http.ResponseWriter, req *http.Request, sess SessionStore
        if len(user.Language) == 0 {
                lc := middleware.Locale(resp, req)
                user.Language = lc.Language()
-               if err := models.UpdateUserCols(db.DefaultContext, user, "language"); err != nil {
+               if err := user_model.UpdateUserCols(db.DefaultContext, user, "language"); err != nil {
                        log.Error(fmt.Sprintf("Error updating user language [user: %d, locale: %s]", user.ID, user.Language))
                        return
                }
index 9cfbd0f644cbc63d86964d3e3d0c71ae46d17df8..e2448eeca07ce3a24539f80f0715d9f21d42548e 100644 (file)
@@ -10,6 +10,7 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
@@ -41,7 +42,7 @@ func (b *Basic) Name() string {
 // "Authorization" header of the request and returns the corresponding user object for that
 // name/token on successful validation.
 // Returns nil if header is empty or validation fails.
-func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
+func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *user_model.User {
        // Basic authentication should only fire on API, Download or on Git or LFSPaths
        if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitRawReleaseOrLFSPath(req) {
                return nil
@@ -75,7 +76,7 @@ func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore
        if uid != 0 {
                log.Trace("Basic Authorization: Valid OAuthAccessToken for user[%d]", uid)
 
-               u, err := models.GetUserByID(uid)
+               u, err := user_model.GetUserByID(uid)
                if err != nil {
                        log.Error("GetUserByID:  %v", err)
                        return nil
@@ -88,7 +89,7 @@ func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore
        token, err := models.GetAccessTokenBySHA(authToken)
        if err == nil {
                log.Trace("Basic Authorization: Valid AccessToken for user[%d]", uid)
-               u, err := models.GetUserByID(token.UID)
+               u, err := user_model.GetUserByID(token.UID)
                if err != nil {
                        log.Error("GetUserByID:  %v", err)
                        return nil
@@ -112,7 +113,7 @@ func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore
        log.Trace("Basic Authorization: Attempting SignIn for %s", uname)
        u, source, err := UserSignIn(uname, passwd)
        if err != nil {
-               if !models.IsErrUserNotExist(err) {
+               if !user_model.IsErrUserNotExist(err) {
                        log.Error("UserSignIn: %v", err)
                }
                return nil
index c396ae046becbaa430ffb6a5b9efcd754d2eb356..bf047338bbd594bf6ac9e421d2ec66a07ed838ac 100644 (file)
@@ -7,8 +7,8 @@ package auth
 import (
        "net/http"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
 )
 
 // Ensure the struct implements the interface.
@@ -60,7 +60,7 @@ func (b *Group) Free() error {
 }
 
 // Verify extracts and validates
-func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
+func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *user_model.User {
        if !db.HasEngine {
                return nil
        }
index a198fbe5b847999f866e70ce47d811991a267a1b..a05ece2078d1d708936a15a2cbcdd60c96aab6e4 100644 (file)
@@ -8,7 +8,7 @@ import (
        "context"
        "net/http"
 
-       "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/session"
        "code.gitea.io/gitea/modules/web/middleware"
 )
@@ -26,7 +26,7 @@ type Method interface {
        // or a new user object (with id = 0) populated with the information that was found
        // in the authentication data (username or email).
        // Returns nil if verification fails.
-       Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User
+       Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *user_model.User
 }
 
 // Initializable represents a structure that requires initialization
@@ -51,7 +51,7 @@ type Freeable interface {
 
 // PasswordAuthenticator represents a source of authentication
 type PasswordAuthenticator interface {
-       Authenticate(user *models.User, login, password string) (*models.User, error)
+       Authenticate(user *user_model.User, login, password string) (*user_model.User, error)
 }
 
 // LocalTwoFASkipper represents a source of authentication that can skip local 2fa
index 723dd2b1a5d0e1b94c94cfd0120ae4157267af29..edce14cd8b34f95085b0a07dc178984201b4efef 100644 (file)
@@ -8,11 +8,12 @@ import (
        "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"
 )
 
 // DeleteLoginSource deletes a LoginSource record in DB.
 func DeleteLoginSource(source *login.Source) error {
-       count, err := db.GetEngine(db.DefaultContext).Count(&models.User{LoginSource: source.ID})
+       count, err := db.GetEngine(db.DefaultContext).Count(&user_model.User{LoginSource: source.ID})
        if err != nil {
                return err
        } else if count > 0 {
index 9b342f3458f60f7a0a8e48eb620c11b8f29ecb40..74dc5eaaf68fa1ad05ddbece1103ad22bff4289f 100644 (file)
@@ -13,6 +13,7 @@ import (
        "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"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/timeutil"
        "code.gitea.io/gitea/modules/web/middleware"
@@ -110,7 +111,7 @@ func (o *OAuth2) userIDFromToken(req *http.Request, store DataStore) int64 {
 // or the "Authorization" header and returns the corresponding user object for that ID.
 // If verification is successful returns an existing user object.
 // Returns nil if verification fails.
-func (o *OAuth2) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
+func (o *OAuth2) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *user_model.User {
        if !db.HasEngine {
                return nil
        }
@@ -125,9 +126,9 @@ func (o *OAuth2) Verify(req *http.Request, w http.ResponseWriter, store DataStor
        }
        log.Trace("OAuth2 Authorization: Found token for user[%d]", id)
 
-       user, err := models.GetUserByID(id)
+       user, err := user_model.GetUserByID(id)
        if err != nil {
-               if !models.IsErrUserNotExist(err) {
+               if !user_model.IsErrUserNotExist(err) {
                        log.Error("GetUserByName: %v", err)
                }
                return nil
index 7cd24c302d21363054d5f3a5c5d6338a00c11a6c..3e44d8b8639cac1d2dca3e6d9b52ebf0791c1154 100644 (file)
@@ -9,7 +9,7 @@ import (
        "net/http"
        "strings"
 
-       "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/web/middleware"
@@ -56,16 +56,16 @@ func (r *ReverseProxy) Name() string {
 // If a username is available in the "setting.ReverseProxyAuthUser" header an existing
 // user object is returned (populated with username or email found in header).
 // Returns nil if header is empty.
-func (r *ReverseProxy) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
+func (r *ReverseProxy) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *user_model.User {
        username := r.getUserName(req)
        if len(username) == 0 {
                return nil
        }
        log.Trace("ReverseProxy Authorization: Found username: %s", username)
 
-       user, err := models.GetUserByName(username)
+       user, err := user_model.GetUserByName(username)
        if err != nil {
-               if !models.IsErrUserNotExist(err) || !r.isAutoRegisterAllowed() {
+               if !user_model.IsErrUserNotExist(err) || !r.isAutoRegisterAllowed() {
                        log.Error("GetUserByName: %v", err)
                        return nil
                }
@@ -91,7 +91,7 @@ func (r *ReverseProxy) isAutoRegisterAllowed() bool {
 
 // newUser creates a new user object for the purpose of automatic registration
 // and populates its name and email with the information present in request headers.
-func (r *ReverseProxy) newUser(req *http.Request) *models.User {
+func (r *ReverseProxy) newUser(req *http.Request) *user_model.User {
        username := r.getUserName(req)
        if len(username) == 0 {
                return nil
@@ -105,12 +105,12 @@ func (r *ReverseProxy) newUser(req *http.Request) *models.User {
                }
        }
 
-       user := &models.User{
+       user := &user_model.User{
                Name:     username,
                Email:    email,
                IsActive: true,
        }
-       if err := models.CreateUser(user); err != nil {
+       if err := user_model.CreateUser(user); err != nil {
                // FIXME: should I create a system notice?
                log.Error("CreateUser: %v", err)
                return nil
index 9a6e2d95d0d3c9ccbc28fb9ca5556b7fbf2ca046..256598d1000924348f38b6c5b85887ab47014091 100644 (file)
@@ -7,7 +7,7 @@ package auth
 import (
        "net/http"
 
-       "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
 )
 
@@ -30,7 +30,7 @@ func (s *Session) Name() string {
 // Verify checks if there is a user uid stored in the session and returns the user
 // object for that uid.
 // Returns nil if there is no user uid stored in the session.
-func (s *Session) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
+func (s *Session) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *user_model.User {
        user := SessionUser(sess)
        if user != nil {
                return user
@@ -39,7 +39,7 @@ func (s *Session) Verify(req *http.Request, w http.ResponseWriter, store DataSto
 }
 
 // SessionUser returns the user object corresponding to the "uid" session variable.
-func SessionUser(sess SessionStore) *models.User {
+func SessionUser(sess SessionStore) *user_model.User {
        // Get user ID
        uid := sess.Get("uid")
        if uid == nil {
@@ -53,9 +53,9 @@ func SessionUser(sess SessionStore) *models.User {
        }
 
        // Get user object
-       user, err := models.GetUserByID(id)
+       user, err := user_model.GetUserByID(id)
        if err != nil {
-               if !models.IsErrUserNotExist(err) {
+               if !user_model.IsErrUserNotExist(err) {
                        log.Error("GetUserById: %v", err)
                }
                return nil
index 504214f9f1626a48bcaa34addd27123bf17e768a..5f75000d9836a5c5f68e4624197199939929e3de 100644 (file)
@@ -7,25 +7,24 @@ package auth
 import (
        "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"
        "code.gitea.io/gitea/modules/log"
 
-       _ "code.gitea.io/gitea/services/auth/source/db" // register the sources (and below)
-       _ "code.gitea.io/gitea/services/auth/source/ldap"
-       "code.gitea.io/gitea/services/auth/source/oauth2"
-       _ "code.gitea.io/gitea/services/auth/source/pam"
-       "code.gitea.io/gitea/services/auth/source/smtp"
-       _ "code.gitea.io/gitea/services/auth/source/sspi"
+       _ "code.gitea.io/gitea/services/auth/source/db"   // register the sources (and below)
+       _ "code.gitea.io/gitea/services/auth/source/ldap" // register the ldap source
+       "code.gitea.io/gitea/services/auth/source/oauth2"
+       _ "code.gitea.io/gitea/services/auth/source/pam" // register the pam source
+       "code.gitea.io/gitea/services/auth/source/smtp"
+       _ "code.gitea.io/gitea/services/auth/source/sspi" // register the sspi source
 )
 
 // UserSignIn validates user name and password.
-func UserSignIn(username, password string) (*models.User, *login.Source, error) {
-       var user *models.User
+func UserSignIn(username, password string) (*user_model.User, *login.Source, error) {
+       var user *user_model.User
        if strings.Contains(username, "@") {
-               user = &models.User{Email: strings.ToLower(strings.TrimSpace(username))}
+               user = &user_model.User{Email: strings.ToLower(strings.TrimSpace(username))}
                // check same email
                cnt, err := db.Count(user)
                if err != nil {
@@ -39,13 +38,13 @@ func UserSignIn(username, password string) (*models.User, *login.Source, error)
        } else {
                trimmedUsername := strings.TrimSpace(username)
                if len(trimmedUsername) == 0 {
-                       return nil, nil, models.ErrUserNotExist{Name: username}
+                       return nil, nil, user_model.ErrUserNotExist{Name: username}
                }
 
-               user = &models.User{LowerName: strings.ToLower(trimmedUsername)}
+               user = &user_model.User{LowerName: strings.ToLower(trimmedUsername)}
        }
 
-       hasUser, err := models.GetUser(user)
+       hasUser, err := user_model.GetUser(user)
        if err != nil {
                return nil, nil, err
        }
@@ -57,12 +56,12 @@ func UserSignIn(username, password string) (*models.User, *login.Source, error)
                }
 
                if !source.IsActive {
-                       return nil, nil, models.ErrLoginSourceNotActived
+                       return nil, nil, oauth2.ErrLoginSourceNotActived
                }
 
                authenticator, ok := source.Cfg.(PasswordAuthenticator)
                if !ok {
-                       return nil, nil, models.ErrUnsupportedLoginType
+                       return nil, nil, smtp.ErrUnsupportedLoginType
                }
 
                user, err := authenticator.Authenticate(user, username, password)
@@ -73,7 +72,7 @@ func UserSignIn(username, password string) (*models.User, *login.Source, error)
                // WARN: DON'T check user.IsActive, that will be checked on reqSign so that
                // user could be hint to resend confirm email.
                if user.ProhibitLogin {
-                       return nil, nil, models.ErrUserProhibitLogin{UID: user.ID, Name: user.Name}
+                       return nil, nil, user_model.ErrUserProhibitLogin{UID: user.ID, Name: user.Name}
                }
 
                return user, source, nil
@@ -101,15 +100,15 @@ func UserSignIn(username, password string) (*models.User, *login.Source, error)
                        if !authUser.ProhibitLogin {
                                return authUser, source, nil
                        }
-                       err = models.ErrUserProhibitLogin{UID: authUser.ID, Name: authUser.Name}
+                       err = user_model.ErrUserProhibitLogin{UID: authUser.ID, Name: authUser.Name}
                }
 
-               if models.IsErrUserNotExist(err) {
+               if user_model.IsErrUserNotExist(err) {
                        log.Debug("Failed to login '%s' via '%s': %v", username, source.Name, err)
                } else {
                        log.Warn("Failed to login '%s' via '%s': %v", username, source.Name, err)
                }
        }
 
-       return nil, nil, models.ErrUserNotExist{Name: username}
+       return nil, nil, user_model.ErrUserNotExist{Name: username}
 }
index af7b719a634e7521e31341101dd05c8536d08415..e0e439c2fe8f6db399a06c1318348f2c4ebe2491 100644 (file)
@@ -5,19 +5,19 @@
 package db
 
 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/setting"
 )
 
 // Authenticate authenticates the provided user against the DB
-func Authenticate(user *models.User, login, password string) (*models.User, error) {
+func Authenticate(user *user_model.User, login, password string) (*user_model.User, error) {
        if user == nil {
-               return nil, models.ErrUserNotExist{Name: login}
+               return nil, user_model.ErrUserNotExist{Name: login}
        }
 
        if !user.IsPasswordSet() || !user.ValidatePassword(password) {
-               return nil, models.ErrUserNotExist{UID: user.ID, Name: user.Name}
+               return nil, user_model.ErrUserNotExist{UID: user.ID, Name: user.Name}
        }
 
        // Update password hash if server password hash algorithm have changed
@@ -25,7 +25,7 @@ func Authenticate(user *models.User, login, password string) (*models.User, erro
                if err := user.SetPassword(password); err != nil {
                        return nil, err
                }
-               if err := models.UpdateUserCols(db.DefaultContext, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
+               if err := user_model.UpdateUserCols(db.DefaultContext, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
                        return nil, err
                }
        }
@@ -33,7 +33,7 @@ func Authenticate(user *models.User, login, password string) (*models.User, erro
        // WARN: DON'T check user.IsActive, that will be checked on reqSign so that
        // user could be hint to resend confirm email.
        if user.ProhibitLogin {
-               return nil, models.ErrUserProhibitLogin{
+               return nil, user_model.ErrUserProhibitLogin{
                        UID:  user.ID,
                        Name: user.Name,
                }
index 2fedff3a7ea85271cc6b6957b9e8757414452f09..5ae2107a3b7df26187d21a05f33246da78c3f7e1 100644 (file)
@@ -5,8 +5,8 @@
 package db
 
 import (
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/login"
+       user_model "code.gitea.io/gitea/models/user"
 )
 
 // Source is a password authentication service
@@ -24,7 +24,7 @@ func (source *Source) ToDB() ([]byte, error) {
 
 // Authenticate queries if login/password is valid against the PAM,
 // and create a local user if success when enabled.
-func (source *Source) Authenticate(user *models.User, login, password string) (*models.User, error) {
+func (source *Source) Authenticate(user *user_model.User, login, password string) (*user_model.User, error) {
        return Authenticate(user, login, password)
 }
 
index 99a99801a4bf39f797082fadc2af61ad6ff30ecc..9bb07d244faa52489e0425c352ac410b7557cf9f 100644 (file)
@@ -11,27 +11,28 @@ import (
        "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"
        "code.gitea.io/gitea/services/mailer"
        user_service "code.gitea.io/gitea/services/user"
 )
 
 // Authenticate queries if login/password is valid against the LDAP directory pool,
 // and create a local user if success when enabled.
-func (source *Source) Authenticate(user *models.User, userName, password string) (*models.User, error) {
+func (source *Source) Authenticate(user *user_model.User, userName, password string) (*user_model.User, error) {
        sr := source.SearchEntry(userName, password, source.loginSource.Type == login.DLDAP)
        if sr == nil {
                // User not in LDAP, do nothing
-               return nil, models.ErrUserNotExist{Name: userName}
+               return nil, user_model.ErrUserNotExist{Name: userName}
        }
 
        isAttributeSSHPublicKeySet := len(strings.TrimSpace(source.AttributeSSHPublicKey)) > 0
 
        // Update User admin flag if exist
-       if isExist, err := models.IsUserExist(0, sr.Username); err != nil {
+       if isExist, err := user_model.IsUserExist(0, sr.Username); err != nil {
                return nil, err
        } else if isExist {
                if user == nil {
-                       user, err = models.GetUserByName(sr.Username)
+                       user, err = user_model.GetUserByName(sr.Username)
                        if err != nil {
                                return nil, err
                        }
@@ -49,7 +50,7 @@ func (source *Source) Authenticate(user *models.User, userName, password string)
                                cols = append(cols, "is_restricted")
                        }
                        if len(cols) > 0 {
-                               err = models.UpdateUserCols(db.DefaultContext, user, cols...)
+                               err = user_model.UpdateUserCols(db.DefaultContext, user, cols...)
                                if err != nil {
                                        return nil, err
                                }
@@ -74,7 +75,7 @@ func (source *Source) Authenticate(user *models.User, userName, password string)
                sr.Mail = fmt.Sprintf("%s@localhost", sr.Username)
        }
 
-       user = &models.User{
+       user = &user_model.User{
                LowerName:    strings.ToLower(sr.Username),
                Name:         sr.Username,
                FullName:     composeFullName(sr.Name, sr.Surname, sr.Username),
@@ -87,7 +88,7 @@ func (source *Source) Authenticate(user *models.User, userName, password string)
                IsRestricted: sr.IsRestricted,
        }
 
-       err := models.CreateUser(user)
+       err := user_model.CreateUser(user)
        if err != nil {
                return user, err
        }
index 89f84ae20cfc29299a71965db266a240232add3f..9c504476c0a34ce57291c5bc2f6cdb0820b1e20b 100644 (file)
@@ -12,6 +12,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/log"
        user_service "code.gitea.io/gitea/services/user"
 )
@@ -25,7 +26,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
        var sshKeysNeedUpdate bool
 
        // Find all users with this login type - FIXME: Should this be an iterator?
-       users, err := models.GetUsersBySource(source.loginSource)
+       users, err := user_model.GetUsersBySource(source.loginSource)
        if err != nil {
                log.Error("SyncExternalUsers: %v", err)
                return err
@@ -83,7 +84,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
                        su.Mail = fmt.Sprintf("%s@localhost", su.Username)
                }
 
-               var usr *models.User
+               var usr *user_model.User
                for userPos < len(users) && users[userPos].LowerName < su.LowerName {
                        userPos++
                }
@@ -97,7 +98,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
                if usr == nil {
                        log.Trace("SyncExternalUsers[%s]: Creating user %s", source.loginSource.Name, su.Username)
 
-                       usr = &models.User{
+                       usr = &user_model.User{
                                LowerName:    su.LowerName,
                                Name:         su.Username,
                                FullName:     fullName,
@@ -110,7 +111,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
                                IsActive:     true,
                        }
 
-                       err = models.CreateUser(usr)
+                       err = user_model.CreateUser(usr)
 
                        if err != nil {
                                log.Error("SyncExternalUsers[%s]: Error creating user %s: %v", source.loginSource.Name, su.Username, err)
@@ -153,7 +154,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
                                }
                                usr.IsActive = true
 
-                               err = models.UpdateUserCols(db.DefaultContext, usr, "full_name", "email", "is_admin", "is_restricted", "is_active")
+                               err = user_model.UpdateUserCols(db.DefaultContext, usr, "full_name", "email", "is_admin", "is_restricted", "is_active")
                                if err != nil {
                                        log.Error("SyncExternalUsers[%s]: Error updating user %s: %v", source.loginSource.Name, usr.Name, err)
                                }
@@ -194,7 +195,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
                                log.Trace("SyncExternalUsers[%s]: Deactivating user %s", source.loginSource.Name, usr.Name)
 
                                usr.IsActive = false
-                               err = models.UpdateUserCols(db.DefaultContext, usr, "is_active")
+                               err = user_model.UpdateUserCols(db.DefaultContext, usr, "is_active")
                                if err != nil {
                                        log.Error("SyncExternalUsers[%s]: Error deactivating user %s: %v", source.loginSource.Name, usr.Name, err)
                                }
index 0fd57a8dbd5a0cc43480ddf2d0daf5d54cc01f5a..18879e917bb849db63d2d413de9758bcaa9a232d 100644 (file)
@@ -5,10 +5,10 @@
 package oauth2
 
 import (
+       "errors"
        "net/url"
        "sort"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/login"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
@@ -139,6 +139,11 @@ func ClearProviders() {
        goth.ClearProviders()
 }
 
+var (
+       // ErrLoginSourceNotActived login source is not actived error
+       ErrLoginSourceNotActived = errors.New("Login source is not actived")
+)
+
 // used to create different types of goth providers
 func createProvider(providerName string, source *Source) (goth.Provider, error) {
        callbackURL := setting.AppURL + "user/oauth2/" + url.PathEscape(providerName) + "/callback"
@@ -148,7 +153,7 @@ func createProvider(providerName string, source *Source) (goth.Provider, error)
 
        p, ok := gothProviders[source.Provider]
        if !ok {
-               return nil, models.ErrLoginSourceNotActived
+               return nil, ErrLoginSourceNotActived
        }
 
        provider, err = p.CreateGothProvider(providerName, callbackURL, source)
index be2ff05356cd4028974273906c8d92fa29f1329c..fdc18411a75d5ab8f6e2d8590134737faa1b3396 100644 (file)
@@ -5,12 +5,12 @@
 package oauth2
 
 import (
-       "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/services/auth/source/db"
 )
 
 // Authenticate falls back to the db authenticator
-func (source *Source) Authenticate(user *models.User, login, password string) (*models.User, error) {
+func (source *Source) Authenticate(user *user_model.User, login, password string) (*user_model.User, error) {
        return db.Authenticate(user, login, password)
 }
 
index 6998241ad7214fa9f162fe16c5c7a86a9f445731..8553653ea0601ee71de0abace9c65bc8fbd08bcc 100644 (file)
@@ -8,7 +8,6 @@ import (
        "fmt"
        "strings"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/login"
        user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/auth/pam"
@@ -20,11 +19,11 @@ import (
 
 // Authenticate queries if login/password is valid against the PAM,
 // and create a local user if success when enabled.
-func (source *Source) Authenticate(user *models.User, userName, password string) (*models.User, error) {
+func (source *Source) Authenticate(user *user_model.User, userName, password string) (*user_model.User, error) {
        pamLogin, err := pam.Auth(source.ServiceName, userName, password)
        if err != nil {
                if strings.Contains(err.Error(), "Authentication failure") {
-                       return nil, models.ErrUserNotExist{Name: userName}
+                       return nil, user_model.ErrUserNotExist{Name: userName}
                }
                return nil, err
        }
@@ -51,7 +50,7 @@ func (source *Source) Authenticate(user *models.User, userName, password string)
                }
        }
 
-       user = &models.User{
+       user = &user_model.User{
                LowerName:   strings.ToLower(username),
                Name:        username,
                Email:       email,
@@ -62,7 +61,7 @@ func (source *Source) Authenticate(user *models.User, userName, password string)
                IsActive:    true,
        }
 
-       if err := models.CreateUser(user); err != nil {
+       if err := user_model.CreateUser(user); err != nil {
                return user, err
        }
 
index d797982da18ec214ab26eb7c83acd51d39f8fa4f..c5bd09b0a7217fc5f1a7bdfbf11dc79db8c435e7 100644 (file)
@@ -6,13 +6,12 @@ package smtp
 
 import (
        "crypto/tls"
+       "errors"
        "fmt"
        "net"
        "net/smtp"
        "os"
        "strconv"
-
-       "code.gitea.io/gitea/models"
 )
 
 //   _________   __________________________
@@ -52,6 +51,11 @@ const (
 // Authenticators contains available SMTP authentication type names.
 var Authenticators = []string{PlainAuthentication, LoginAuthentication, CRAMMD5Authentication}
 
+var (
+       // ErrUnsupportedLoginType login source is unknown error
+       ErrUnsupportedLoginType = errors.New("Login source is unknown")
+)
+
 // Authenticate performs an SMTP authentication.
 func Authenticate(a smtp.Auth, source *Source) error {
        tlsConfig := &tls.Config{
@@ -101,5 +105,5 @@ func Authenticate(a smtp.Auth, source *Source) error {
                return client.Auth(a)
        }
 
-       return models.ErrUnsupportedLoginType
+       return ErrUnsupportedLoginType
 }
index f51c884c3a40b4f00bac8062f6484439f75595ed..c32d638b54fa966913cf94ec694dec8114b1348c 100644 (file)
@@ -10,22 +10,22 @@ import (
        "net/textproto"
        "strings"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/login"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/util"
        "code.gitea.io/gitea/services/mailer"
 )
 
 // Authenticate queries if the provided login/password is authenticates against the SMTP server
 // Users will be autoregistered as required
-func (source *Source) Authenticate(user *models.User, userName, password string) (*models.User, error) {
+func (source *Source) Authenticate(user *user_model.User, userName, password string) (*user_model.User, error) {
        // Verify allowed domains.
        if len(source.AllowedDomains) > 0 {
                idx := strings.Index(userName, "@")
                if idx == -1 {
-                       return nil, models.ErrUserNotExist{Name: userName}
+                       return nil, user_model.ErrUserNotExist{Name: userName}
                } else if !util.IsStringInSlice(userName[idx+1:], strings.Split(source.AllowedDomains, ","), true) {
-                       return nil, models.ErrUserNotExist{Name: userName}
+                       return nil, user_model.ErrUserNotExist{Name: userName}
                }
        }
 
@@ -47,11 +47,11 @@ func (source *Source) Authenticate(user *models.User, userName, password string)
                tperr, ok := err.(*textproto.Error)
                if (ok && tperr.Code == 535) ||
                        strings.Contains(err.Error(), "Username and Password not accepted") {
-                       return nil, models.ErrUserNotExist{Name: userName}
+                       return nil, user_model.ErrUserNotExist{Name: userName}
                }
                if (ok && tperr.Code == 534) ||
                        strings.Contains(err.Error(), "Application-specific password required") {
-                       return nil, models.ErrUserNotExist{Name: userName}
+                       return nil, user_model.ErrUserNotExist{Name: userName}
                }
                return nil, err
        }
@@ -66,7 +66,7 @@ func (source *Source) Authenticate(user *models.User, userName, password string)
                username = userName[:idx]
        }
 
-       user = &models.User{
+       user = &user_model.User{
                LowerName:   strings.ToLower(username),
                Name:        strings.ToLower(username),
                Email:       userName,
@@ -77,7 +77,7 @@ func (source *Source) Authenticate(user *models.User, userName, password string)
                IsActive:    true,
        }
 
-       if err := models.CreateUser(user); err != nil {
+       if err := user_model.CreateUser(user); err != nil {
                return user, err
        }
 
index 821a3df459c328caf474846370f9789f9afd5f47..19f23491224376b62f183af1247260c88ada1dd3 100644 (file)
@@ -9,9 +9,9 @@ import (
        "net/http"
        "strings"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/avatars"
        "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/log"
        "code.gitea.io/gitea/modules/setting"
@@ -83,7 +83,7 @@ func (s *SSPI) Free() error {
 // If authentication is successful, returns the corresponding user object.
 // If negotiation should continue or authentication fails, immediately returns a 401 HTTP
 // response code, as required by the SPNEGO protocol.
-func (s *SSPI) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
+func (s *SSPI) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *user_model.User {
        if !s.shouldAuthenticate(req) {
                return nil
        }
@@ -126,9 +126,9 @@ func (s *SSPI) Verify(req *http.Request, w http.ResponseWriter, store DataStore,
        }
        log.Info("Authenticated as %s\n", username)
 
-       user, err := models.GetUserByName(username)
+       user, err := user_model.GetUserByName(username)
        if err != nil {
-               if !models.IsErrUserNotExist(err) {
+               if !user_model.IsErrUserNotExist(err) {
                        log.Error("GetUserByName: %v", err)
                        return nil
                }
@@ -184,9 +184,9 @@ func (s *SSPI) shouldAuthenticate(req *http.Request) (shouldAuth bool) {
 
 // newUser creates a new user object for the purpose of automatic registration
 // and populates its name and email with the information present in request headers.
-func (s *SSPI) newUser(username string, cfg *sspi.Source) (*models.User, error) {
+func (s *SSPI) newUser(username string, cfg *sspi.Source) (*user_model.User, error) {
        email := gouuid.New().String() + "@localhost.localdomain"
-       user := &models.User{
+       user := &user_model.User{
                Name:                         username,
                Email:                        email,
                KeepEmailPrivate:             true,
@@ -195,9 +195,9 @@ func (s *SSPI) newUser(username string, cfg *sspi.Source) (*models.User, error)
                Language:                     cfg.DefaultLanguage,
                UseCustomAvatar:              true,
                Avatar:                       avatars.DefaultAvatarLink(),
-               EmailNotificationsPreference: models.EmailNotificationsDisabled,
+               EmailNotificationsPreference: user_model.EmailNotificationsDisabled,
        }
-       if err := models.CreateUser(user); err != nil {
+       if err := user_model.CreateUser(user); err != nil {
                return nil, err
        }
 
index 2477f2d2b0e499ec31f6bf97563a54cd0004379e..6e963012753495c5406e235cff0ea9a4ff327344 100644 (file)
@@ -8,12 +8,13 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/issues"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/notification"
        "code.gitea.io/gitea/modules/timeutil"
 )
 
 // CreateIssueComment creates a plain issue comment.
-func CreateIssueComment(doer *models.User, repo *models.Repository, issue *models.Issue, content string, attachments []string) (*models.Comment, error) {
+func CreateIssueComment(doer *user_model.User, repo *models.Repository, issue *models.Issue, content string, attachments []string) (*models.Comment, error) {
        comment, err := models.CreateComment(&models.CreateCommentOptions{
                Type:        models.CommentTypeComment,
                Doer:        doer,
@@ -37,7 +38,7 @@ func CreateIssueComment(doer *models.User, repo *models.Repository, issue *model
 }
 
 // UpdateComment updates information of comment.
-func UpdateComment(c *models.Comment, doer *models.User, oldContent string) error {
+func UpdateComment(c *models.Comment, doer *user_model.User, oldContent string) error {
        var needsContentHistory = c.Content != oldContent &&
                (c.Type == models.CommentTypeComment || c.Type == models.CommentTypeReview || c.Type == models.CommentTypeCode)
        if needsContentHistory {
@@ -70,7 +71,7 @@ func UpdateComment(c *models.Comment, doer *models.User, oldContent string) erro
 }
 
 // DeleteComment deletes the comment
-func DeleteComment(doer *models.User, comment *models.Comment) error {
+func DeleteComment(doer *user_model.User, comment *models.Comment) error {
        if err := models.DeleteComment(comment); err != nil {
                return err
        }
index a0393e23dc83773a0d0939a903a2a3b62c00a295..3d9495764d2a170a03f553311cf70f76b7365a70 100644 (file)
@@ -7,7 +7,7 @@ package cron
 import (
        "time"
 
-       "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/unknwon/i18n"
 )
@@ -17,7 +17,7 @@ type Config interface {
        IsEnabled() bool
        DoRunAtStart() bool
        GetSchedule() string
-       FormatMessage(name, status string, doer *models.User, args ...interface{}) string
+       FormatMessage(name, status string, doer *user_model.User, args ...interface{}) string
        DoNoticeOnSuccess() bool
 }
 
@@ -70,7 +70,7 @@ func (b *BaseConfig) DoNoticeOnSuccess() bool {
 }
 
 // FormatMessage returns a message for the task
-func (b *BaseConfig) FormatMessage(name, status string, doer *models.User, args ...interface{}) string {
+func (b *BaseConfig) FormatMessage(name, status string, doer *user_model.User, args ...interface{}) string {
        realArgs := make([]interface{}, 0, len(args)+2)
        realArgs = append(realArgs, i18n.Tr("en-US", "admin.dashboard."+name))
        if doer == nil {
index 732eead9309596779a722981a8738edbb682e10f..75bb4993c02b998a34918d8521ce86fdccae87d6 100644 (file)
@@ -10,9 +10,9 @@ import (
        "reflect"
        "sync"
 
-       "code.gitea.io/gitea/models"
        admin_model "code.gitea.io/gitea/models/admin"
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/graceful"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/process"
@@ -29,7 +29,7 @@ type Task struct {
        lock      sync.Mutex
        Name      string
        config    Config
-       fun       func(context.Context, *models.User, Config) error
+       fun       func(context.Context, *user_model.User, Config) error
        ExecTimes int64
 }
 
@@ -55,7 +55,7 @@ func (t *Task) GetConfig() Config {
 
 // Run will run the task incrementing the cron counter with no user defined
 func (t *Task) Run() {
-       t.RunWithUser(&models.User{
+       t.RunWithUser(&user_model.User{
                ID:        -1,
                Name:      "(Cron)",
                LowerName: "(cron)",
@@ -63,7 +63,7 @@ func (t *Task) Run() {
 }
 
 // RunWithUser will run the task incrementing the cron counter at the time with User
-func (t *Task) RunWithUser(doer *models.User, config Config) {
+func (t *Task) RunWithUser(doer *user_model.User, config Config) {
        if !taskStatusTable.StartIfNotRunning(t.Name) {
                return
        }
@@ -118,7 +118,7 @@ func GetTask(name string) *Task {
 }
 
 // RegisterTask allows a task to be registered with the cron service
-func RegisterTask(name string, config Config, fun func(context.Context, *models.User, Config) error) error {
+func RegisterTask(name string, config Config, fun func(context.Context, *user_model.User, Config) error) error {
        log.Debug("Registering task: %s", name)
        _, err := setting.GetCronSettings(name, config)
        if err != nil {
@@ -163,7 +163,7 @@ func RegisterTask(name string, config Config, fun func(context.Context, *models.
 }
 
 // RegisterTaskFatal will register a task but if there is an error log.Fatal
-func RegisterTaskFatal(name string, config Config, fun func(context.Context, *models.User, Config) error) {
+func RegisterTaskFatal(name string, config Config, fun func(context.Context, *user_model.User, Config) error) {
        if err := RegisterTask(name, config, fun); err != nil {
                log.Fatal("Unable to register cron task %s Error: %v", name, err)
        }
index 4832ca98a734f2bf20191f61393003d95c39fe75..814f6eae4e5d4dce03414a3b6dea7dd42c9cf7a8 100644 (file)
@@ -9,6 +9,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/models/webhook"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/services/auth"
@@ -33,7 +34,7 @@ func registerUpdateMirrorTask() {
                },
                PullLimit: 50,
                PushLimit: 50,
-       }, func(ctx context.Context, _ *models.User, cfg Config) error {
+       }, func(ctx context.Context, _ *user_model.User, cfg Config) error {
                umtc := cfg.(*UpdateMirrorTaskConfig)
                return mirror_service.Update(ctx, umtc.PullLimit, umtc.PushLimit)
        })
@@ -53,7 +54,7 @@ func registerRepoHealthCheck() {
                },
                Timeout: 60 * time.Second,
                Args:    []string{},
-       }, func(ctx context.Context, _ *models.User, config Config) error {
+       }, func(ctx context.Context, _ *user_model.User, config Config) error {
                rhcConfig := config.(*RepoHealthCheckConfig)
                return repository_service.GitFsck(ctx, rhcConfig.Timeout, rhcConfig.Args)
        })
@@ -64,7 +65,7 @@ func registerCheckRepoStats() {
                Enabled:    true,
                RunAtStart: true,
                Schedule:   "@midnight",
-       }, func(ctx context.Context, _ *models.User, _ Config) error {
+       }, func(ctx context.Context, _ *user_model.User, _ Config) error {
                return models.CheckRepoStats(ctx)
        })
 }
@@ -77,7 +78,7 @@ func registerArchiveCleanup() {
                        Schedule:   "@midnight",
                },
                OlderThan: 24 * time.Hour,
-       }, func(ctx context.Context, _ *models.User, config Config) error {
+       }, func(ctx context.Context, _ *user_model.User, config Config) error {
                acConfig := config.(*OlderThanConfig)
                return models.DeleteOldRepositoryArchives(ctx, acConfig.OlderThan)
        })
@@ -91,7 +92,7 @@ func registerSyncExternalUsers() {
                        Schedule:   "@midnight",
                },
                UpdateExisting: true,
-       }, func(ctx context.Context, _ *models.User, config Config) error {
+       }, func(ctx context.Context, _ *user_model.User, config Config) error {
                realConfig := config.(*UpdateExistingConfig)
                return auth.SyncExternalUsers(ctx, realConfig.UpdateExisting)
        })
@@ -105,7 +106,7 @@ func registerDeletedBranchesCleanup() {
                        Schedule:   "@midnight",
                },
                OlderThan: 24 * time.Hour,
-       }, func(ctx context.Context, _ *models.User, config Config) error {
+       }, func(ctx context.Context, _ *user_model.User, config Config) error {
                realConfig := config.(*OlderThanConfig)
                models.RemoveOldDeletedBranches(ctx, realConfig.OlderThan)
                return nil
@@ -117,7 +118,7 @@ func registerUpdateMigrationPosterID() {
                Enabled:    true,
                RunAtStart: true,
                Schedule:   "@midnight",
-       }, func(ctx context.Context, _ *models.User, _ Config) error {
+       }, func(ctx context.Context, _ *user_model.User, _ Config) error {
                return migrations.UpdateMigrationPosterID(ctx)
        })
 }
@@ -132,7 +133,7 @@ func registerCleanupHookTaskTable() {
                CleanupType:  "OlderThan",
                OlderThan:    168 * time.Hour,
                NumberToKeep: 10,
-       }, func(ctx context.Context, _ *models.User, config Config) error {
+       }, func(ctx context.Context, _ *user_model.User, config Config) error {
                realConfig := config.(*CleanupHookTaskConfig)
                return webhook.CleanupHookTaskTable(ctx, webhook.ToHookTaskCleanupType(realConfig.CleanupType), realConfig.OlderThan, realConfig.NumberToKeep)
        })
index 95293b1c1d06e59fb77fa87ea6751eddc14c1a3a..26dbe548a7ec4b553beb60f8b619fb2268238a11 100644 (file)
@@ -9,6 +9,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/updatechecker"
        repo_service "code.gitea.io/gitea/services/repository"
@@ -23,7 +24,7 @@ func registerDeleteInactiveUsers() {
                        Schedule:   "@annually",
                },
                OlderThan: 0 * time.Second,
-       }, func(ctx context.Context, _ *models.User, config Config) error {
+       }, func(ctx context.Context, _ *user_model.User, config Config) error {
                olderThanConfig := config.(*OlderThanConfig)
                return user_service.DeleteInactiveUsers(ctx, olderThanConfig.OlderThan)
        })
@@ -34,7 +35,7 @@ func registerDeleteRepositoryArchives() {
                Enabled:    false,
                RunAtStart: false,
                Schedule:   "@annually",
-       }, func(ctx context.Context, _ *models.User, _ Config) error {
+       }, func(ctx context.Context, _ *user_model.User, _ Config) error {
                return repo_service.DeleteRepositoryArchives(ctx)
        })
 }
@@ -53,7 +54,7 @@ func registerGarbageCollectRepositories() {
                },
                Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
                Args:    setting.Git.GCArgs,
-       }, func(ctx context.Context, _ *models.User, config Config) error {
+       }, func(ctx context.Context, _ *user_model.User, config Config) error {
                rhcConfig := config.(*RepoHealthCheckConfig)
                return repo_service.GitGcRepos(ctx, rhcConfig.Timeout, rhcConfig.Args...)
        })
@@ -64,7 +65,7 @@ func registerRewriteAllPublicKeys() {
                Enabled:    false,
                RunAtStart: false,
                Schedule:   "@every 72h",
-       }, func(_ context.Context, _ *models.User, _ Config) error {
+       }, func(_ context.Context, _ *user_model.User, _ Config) error {
                return models.RewriteAllPublicKeys()
        })
 }
@@ -74,7 +75,7 @@ func registerRewriteAllPrincipalKeys() {
                Enabled:    false,
                RunAtStart: false,
                Schedule:   "@every 72h",
-       }, func(_ context.Context, _ *models.User, _ Config) error {
+       }, func(_ context.Context, _ *user_model.User, _ Config) error {
                return models.RewriteAllPrincipalKeys()
        })
 }
@@ -84,7 +85,7 @@ func registerRepositoryUpdateHook() {
                Enabled:    false,
                RunAtStart: false,
                Schedule:   "@every 72h",
-       }, func(ctx context.Context, _ *models.User, _ Config) error {
+       }, func(ctx context.Context, _ *user_model.User, _ Config) error {
                return repo_service.SyncRepositoryHooks(ctx)
        })
 }
@@ -94,7 +95,7 @@ func registerReinitMissingRepositories() {
                Enabled:    false,
                RunAtStart: false,
                Schedule:   "@every 72h",
-       }, func(ctx context.Context, _ *models.User, _ Config) error {
+       }, func(ctx context.Context, _ *user_model.User, _ Config) error {
                return repo_service.ReinitMissingRepositories(ctx)
        })
 }
@@ -104,7 +105,7 @@ func registerDeleteMissingRepositories() {
                Enabled:    false,
                RunAtStart: false,
                Schedule:   "@every 72h",
-       }, func(ctx context.Context, user *models.User, _ Config) error {
+       }, func(ctx context.Context, user *user_model.User, _ Config) error {
                return repo_service.DeleteMissingRepositories(ctx, user)
        })
 }
@@ -114,7 +115,7 @@ func registerRemoveRandomAvatars() {
                Enabled:    false,
                RunAtStart: false,
                Schedule:   "@every 72h",
-       }, func(ctx context.Context, _ *models.User, _ Config) error {
+       }, func(ctx context.Context, _ *user_model.User, _ Config) error {
                return models.RemoveRandomAvatars(ctx)
        })
 }
@@ -127,7 +128,7 @@ func registerDeleteOldActions() {
                        Schedule:   "@every 168h",
                },
                OlderThan: 365 * 24 * time.Hour,
-       }, func(ctx context.Context, _ *models.User, config Config) error {
+       }, func(ctx context.Context, _ *user_model.User, config Config) error {
                olderThanConfig := config.(*OlderThanConfig)
                return models.DeleteOldActions(olderThanConfig.OlderThan)
        })
@@ -145,7 +146,7 @@ func registerUpdateGiteaChecker() {
                        Schedule:   "@every 168h",
                },
                HTTPEndpoint: "https://dl.gitea.io/gitea/version.json",
-       }, func(ctx context.Context, _ *models.User, config Config) error {
+       }, func(ctx context.Context, _ *user_model.User, config Config) error {
                updateCheckerConfig := config.(*UpdateCheckerConfig)
                return updatechecker.GiteaUpdateChecker(updateCheckerConfig.HTTPEndpoint)
        })
index e43b3ca7c5f5bb8a08ea8b8109444cd3f010d0c1..c11499d7651beefd6e619c284e4d557efbd5e173 100644 (file)
@@ -9,13 +9,14 @@ 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/structs"
 
        "github.com/markbates/goth"
 )
 
 // LinkAccountToUser link the gothUser to the user
-func LinkAccountToUser(user *models.User, gothUser goth.User) error {
+func LinkAccountToUser(user *user_model.User, gothUser goth.User) error {
        loginSource, err := login.GetActiveOAuth2LoginSourceByName(gothUser.Provider)
        if err != nil {
                return err
index c303de0a01574f7ea850080fa6d2075e3d498f96..44c1727719d3a8cde2b7ad98c926a331d207189b 100644 (file)
@@ -23,6 +23,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/analyze"
        "code.gitea.io/gitea/modules/charset"
        "code.gitea.io/gitea/modules/git"
@@ -666,7 +667,7 @@ type Diff struct {
 }
 
 // LoadComments loads comments into each line
-func (diff *Diff) LoadComments(issue *models.Issue, currentUser *models.User) error {
+func (diff *Diff) LoadComments(issue *models.Issue, currentUser *user_model.User) error {
        allComments, err := models.FetchCodeComments(issue, currentUser)
        if err != nil {
                return err
index 7d63beffebc68863b936c488b1b2672bb74d0182..21afdb4cac446fd658902dffce9ef02ca64fb7b0 100644 (file)
@@ -14,6 +14,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/highlight"
        "code.gitea.io/gitea/modules/json"
@@ -667,7 +668,7 @@ func TestDiff_LoadComments(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
        issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
        diff := setupDefaultDiff()
        assert.NoError(t, diff.LoadComments(issue, user))
        assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 2)
index 290a0041ff213e4ef63b39b6b83205ffa507fc42..62d274a65f89d283d1976609dc0bc24fb6867ef3 100644 (file)
@@ -7,12 +7,13 @@ package issue
 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/log"
        "code.gitea.io/gitea/modules/notification"
 )
 
 // DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array
-func DeleteNotPassedAssignee(issue *models.Issue, doer *models.User, assignees []*models.User) (err error) {
+func DeleteNotPassedAssignee(issue *models.Issue, doer *user_model.User, assignees []*user_model.User) (err error) {
        var found bool
 
        for _, assignee := range issue.Assignees {
@@ -37,13 +38,13 @@ func DeleteNotPassedAssignee(issue *models.Issue, doer *models.User, assignees [
 }
 
 // ToggleAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
-func ToggleAssignee(issue *models.Issue, doer *models.User, assigneeID int64) (removed bool, comment *models.Comment, err error) {
+func ToggleAssignee(issue *models.Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *models.Comment, err error) {
        removed, comment, err = issue.ToggleAssignee(doer, assigneeID)
        if err != nil {
                return
        }
 
-       assignee, err1 := models.GetUserByID(assigneeID)
+       assignee, err1 := user_model.GetUserByID(assigneeID)
        if err1 != nil {
                err = err1
                return
@@ -55,7 +56,7 @@ func ToggleAssignee(issue *models.Issue, doer *models.User, assigneeID int64) (r
 }
 
 // ReviewRequest add or remove a review request from a user for this PR, and make comment for it.
-func ReviewRequest(issue *models.Issue, doer *models.User, reviewer *models.User, isAdd bool) (comment *models.Comment, err error) {
+func ReviewRequest(issue *models.Issue, doer *user_model.User, reviewer *user_model.User, isAdd bool) (comment *models.Comment, err error) {
        if isAdd {
                comment, err = models.AddReviewRequest(issue, reviewer, doer)
        } else {
@@ -74,7 +75,7 @@ func ReviewRequest(issue *models.Issue, doer *models.User, reviewer *models.User
 }
 
 // IsValidReviewRequest Check permission for ReviewRequest
-func IsValidReviewRequest(reviewer, doer *models.User, isAdd bool, issue *models.Issue, permDoer *models.Permission) error {
+func IsValidReviewRequest(reviewer, doer *user_model.User, isAdd bool, issue *models.Issue, permDoer *models.Permission) error {
        if reviewer.IsOrganization() {
                return models.ErrNotValidReviewRequest{
                        Reason: "Organization can't be added as reviewer",
@@ -172,7 +173,7 @@ func IsValidReviewRequest(reviewer, doer *models.User, isAdd bool, issue *models
 }
 
 // IsValidTeamReviewRequest Check permission for ReviewRequest Team
-func IsValidTeamReviewRequest(reviewer *models.Team, doer *models.User, isAdd bool, issue *models.Issue) error {
+func IsValidTeamReviewRequest(reviewer *models.Team, doer *user_model.User, isAdd bool, issue *models.Issue) error {
        if doer.IsOrganization() {
                return models.ErrNotValidReviewRequest{
                        Reason: "Organization can't be doer to add reviewer",
@@ -227,7 +228,7 @@ func IsValidTeamReviewRequest(reviewer *models.Team, doer *models.User, isAdd bo
 }
 
 // TeamReviewRequest add or remove a review request from a team for this PR, and make comment for it.
-func TeamReviewRequest(issue *models.Issue, doer *models.User, reviewer *models.Team, isAdd bool) (comment *models.Comment, err error) {
+func TeamReviewRequest(issue *models.Issue, doer *user_model.User, reviewer *models.Team, isAdd bool) (comment *models.Comment, err error) {
        if isAdd {
                comment, err = models.AddTeamReviewRequest(issue, reviewer, doer)
        } else {
index bc2721ebd41958f9593d8ef07c64aa63da32e4a9..d3d7ad74f889be51653c765b685489eac1e76618 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -20,7 +21,7 @@ func TestDeleteNotPassedAssignee(t *testing.T) {
        issue, err := models.GetIssueWithAttrsByID(1)
        assert.NoError(t, err)
 
-       user1, err := models.GetUserByID(1) // This user is already assigned (see the definition in fixtures), so running  UpdateAssignee should unassign him
+       user1, err := user_model.GetUserByID(1) // This user is already assigned (see the definition in fixtures), so running  UpdateAssignee should unassign him
        assert.NoError(t, err)
 
        // Check if he got removed
@@ -29,7 +30,7 @@ func TestDeleteNotPassedAssignee(t *testing.T) {
        assert.True(t, isAssigned)
 
        // Clean everyone
-       err = DeleteNotPassedAssignee(issue, user1, []*models.User{})
+       err = DeleteNotPassedAssignee(issue, user1, []*user_model.User{})
        assert.NoError(t, err)
 
        // Check they're gone
index 401084639d6307e1eab6a316c3b19189a461ad95..3e2f6c471b47e24963b91d876dd17deeaf7fc4a5 100644 (file)
@@ -14,6 +14,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/references"
        "code.gitea.io/gitea/modules/repository"
 )
@@ -72,7 +73,7 @@ func timeLogToAmount(str string) int64 {
        return a
 }
 
-func issueAddTime(issue *models.Issue, doer *models.User, time time.Time, timeLog string) error {
+func issueAddTime(issue *models.Issue, doer *user_model.User, time time.Time, timeLog string) error {
        amount := timeLogToAmount(timeLog)
        if amount == 0 {
                return nil
@@ -96,7 +97,7 @@ func getIssueFromRef(repo *models.Repository, index int64) (*models.Issue, error
 }
 
 // UpdateIssuesCommit checks if issues are manipulated by commit message.
-func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*repository.PushCommit, branchName string) error {
+func UpdateIssuesCommit(doer *user_model.User, repo *models.Repository, commits []*repository.PushCommit, branchName string) error {
        // Commits are appended in the reverse order.
        for i := len(commits) - 1; i >= 0; i-- {
                c := commits[i]
index 3f8c5f3b42e506f74b93fa01e871aff6ba30f61f..1addbd080f8bd64b0f40ad4a980b1247b780f3c3 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/repository"
        "code.gitea.io/gitea/modules/setting"
 
@@ -44,7 +45,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
                },
        }
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        repo.Owner = user
 
@@ -130,7 +131,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
                },
        }
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        repo.Owner = user
 
@@ -144,7 +145,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
 
 func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        // Test that push to a non-default branch closes an issue.
        pushCommits := []*repository.PushCommit{
@@ -178,7 +179,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
 
 func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        // Test that a push to default branch closes issue in another repo
        // If the user also has push permissions to that repo
@@ -213,7 +214,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
 
 func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
 
        // Test that a push to default branch closes issue in another repo
        // If the user also has push permissions to that repo
@@ -248,7 +249,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
 
 func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 10}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10}).(*user_model.User)
 
        // Test that a push with close reference *can not* close issue
        // If the committer doesn't have push rights in that repo
index 1081e30b5d828d557460ff1d011cfd0b46371e25..6d7883090b04b06b1d1a9d02e02425ae771513a6 100644 (file)
@@ -6,11 +6,12 @@ package issue
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/notification"
 )
 
 // ChangeContent changes issue content, as the given user.
-func ChangeContent(issue *models.Issue, doer *models.User, content string) (err error) {
+func ChangeContent(issue *models.Issue, doer *user_model.User, content string) (err error) {
        oldContent := issue.Content
 
        if err := issue.ChangeContent(doer, content); err != nil {
index e3571bd396f69382ddccbef85b0c7276ebd5398c..cb34a9eacdb86a8db8549afa1357a2daca2eb1bc 100644 (file)
@@ -7,6 +7,7 @@ package issue
 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/git"
        "code.gitea.io/gitea/modules/notification"
        "code.gitea.io/gitea/modules/util"
@@ -41,7 +42,7 @@ func NewIssue(repo *models.Repository, issue *models.Issue, labelIDs []int64, uu
 }
 
 // ChangeTitle changes the title of this issue, as the given user.
-func ChangeTitle(issue *models.Issue, doer *models.User, title string) (err error) {
+func ChangeTitle(issue *models.Issue, doer *user_model.User, title string) (err error) {
        oldTitle := issue.Title
        issue.Title = title
 
@@ -55,7 +56,7 @@ func ChangeTitle(issue *models.Issue, doer *models.User, title string) (err erro
 }
 
 // ChangeIssueRef changes the branch of this issue, as the given user.
-func ChangeIssueRef(issue *models.Issue, doer *models.User, ref string) error {
+func ChangeIssueRef(issue *models.Issue, doer *user_model.User, ref string) error {
        oldRef := issue.Ref
        issue.Ref = ref
 
@@ -74,8 +75,8 @@ func ChangeIssueRef(issue *models.Issue, doer *models.User, ref string) error {
 // "assignees" (array): Logins for Users to assign to this issue.
 // Pass one or more user logins to replace the set of assignees on this Issue.
 // Send an empty array ([]) to clear all assignees from the Issue.
-func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees []string, doer *models.User) (err error) {
-       var allNewAssignees []*models.User
+func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees []string, doer *user_model.User) (err error) {
+       var allNewAssignees []*user_model.User
 
        // Keep the old assignee thingy for compatibility reasons
        if oneAssignee != "" {
@@ -95,7 +96,7 @@ func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees
 
        // Loop through all assignees to add them
        for _, assigneeName := range multipleAssignees {
-               assignee, err := models.GetUserByName(assigneeName)
+               assignee, err := user_model.GetUserByName(assigneeName)
                if err != nil {
                        return err
                }
@@ -125,8 +126,8 @@ func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees
 
 // AddAssigneeIfNotAssigned adds an assignee only if he isn't already assigned to the issue.
 // Also checks for access of assigned user
-func AddAssigneeIfNotAssigned(issue *models.Issue, doer *models.User, assigneeID int64) (err error) {
-       assignee, err := models.GetUserByID(assigneeID)
+func AddAssigneeIfNotAssigned(issue *models.Issue, doer *user_model.User, assigneeID int64) (err error) {
+       assignee, err := user_model.GetUserByID(assigneeID)
        if err != nil {
                return err
        }
index c8ef9e9536640e9571f1fcf8780d6cc8abfce579..96df7ed345b0249155b888761f90147fc6939a97 100644 (file)
@@ -6,11 +6,12 @@ package issue
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/notification"
 )
 
 // ClearLabels clears all of an issue's labels
-func ClearLabels(issue *models.Issue, doer *models.User) (err error) {
+func ClearLabels(issue *models.Issue, doer *user_model.User) (err error) {
        if err = issue.ClearLabels(doer); err != nil {
                return
        }
@@ -21,7 +22,7 @@ func ClearLabels(issue *models.Issue, doer *models.User) (err error) {
 }
 
 // AddLabel adds a new label to the issue.
-func AddLabel(issue *models.Issue, doer *models.User, label *models.Label) error {
+func AddLabel(issue *models.Issue, doer *user_model.User, label *models.Label) error {
        if err := models.NewIssueLabel(issue, label, doer); err != nil {
                return err
        }
@@ -31,7 +32,7 @@ func AddLabel(issue *models.Issue, doer *models.User, label *models.Label) error
 }
 
 // AddLabels adds a list of new labels to the issue.
-func AddLabels(issue *models.Issue, doer *models.User, labels []*models.Label) error {
+func AddLabels(issue *models.Issue, doer *user_model.User, labels []*models.Label) error {
        if err := models.NewIssueLabels(issue, labels, doer); err != nil {
                return err
        }
@@ -41,7 +42,7 @@ func AddLabels(issue *models.Issue, doer *models.User, labels []*models.Label) e
 }
 
 // RemoveLabel removes a label from issue by given ID.
-func RemoveLabel(issue *models.Issue, doer *models.User, label *models.Label) error {
+func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label) error {
        if err := issue.LoadRepo(); err != nil {
                return err
        }
@@ -66,7 +67,7 @@ func RemoveLabel(issue *models.Issue, doer *models.User, label *models.Label) er
 }
 
 // ReplaceLabels removes all current labels and add new labels to the issue.
-func ReplaceLabels(issue *models.Issue, doer *models.User, labels []*models.Label) error {
+func ReplaceLabels(issue *models.Issue, doer *user_model.User, labels []*models.Label) error {
        old, err := models.GetLabelsByIssueID(issue.ID)
        if err != nil {
                return err
index fdc2c4ffb6414cb5d6e0c23245a5664407639574..fc94749bdbd20fa9bf082042263ac3f916853901 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -31,7 +32,7 @@ func TestIssue_AddLabels(t *testing.T) {
                for i, labelID := range test.labelIDs {
                        labels[i] = unittest.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label)
                }
-               doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
+               doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID}).(*user_model.User)
                assert.NoError(t, AddLabels(issue, doer, labels))
                for _, labelID := range test.labelIDs {
                        unittest.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID})
@@ -54,7 +55,7 @@ func TestIssue_AddLabel(t *testing.T) {
                assert.NoError(t, unittest.PrepareTestDatabase())
                issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
                label := unittest.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label)
-               doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
+               doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID}).(*user_model.User)
                assert.NoError(t, AddLabel(issue, doer, label))
                unittest.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
        }
index 6fe527f58cd4e1067267eaba5c7e72c46c6138e5..999da50844f37b8870c9623c6c20b59154e21e8c 100644 (file)
@@ -6,11 +6,12 @@ package issue
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/notification"
 )
 
 // ChangeMilestoneAssign changes assignment of milestone for issue.
-func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneID int64) (err error) {
+func ChangeMilestoneAssign(issue *models.Issue, doer *user_model.User, oldMilestoneID int64) (err error) {
        if err = models.ChangeMilestoneAssign(issue, doer, oldMilestoneID); err != nil {
                return
        }
index 0a18169a27abd706b78ea3977cb27be7f11426e4..5b8d21274d6886eb10b96ddbcdf67d55f2ff429d 100644 (file)
@@ -7,11 +7,12 @@ package issue
 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/notification"
 )
 
 // ChangeStatus changes issue status to open or closed.
-func ChangeStatus(issue *models.Issue, doer *models.User, closed bool) error {
+func ChangeStatus(issue *models.Issue, doer *user_model.User, closed bool) error {
        comment, err := issue.ChangeStatus(doer, closed)
        if err != nil {
                // Don't return an error when dependencies are open as this would let the push fail
index ac72fff6af71f1f10bf63bda3b15119ad232de2d..11cf5c16b9993701ad10d5819136a90f42029c6f 100644 (file)
@@ -168,9 +168,9 @@ func PostLockHandler(ctx *context.Context) {
        }
 
        lock, err := models.CreateLFSLock(&models.LFSLock{
-               Repo:  repository,
-               Path:  req.Path,
-               Owner: ctx.User,
+               Repo:    repository,
+               Path:    req.Path,
+               OwnerID: ctx.User.ID,
        })
        if err != nil {
                if models.IsErrLFSLockAlreadyExist(err) {
@@ -249,7 +249,7 @@ func VerifyLockHandler(ctx *context.Context) {
        lockOursListAPI := make([]*api.LFSLock, 0, len(lockList))
        lockTheirsListAPI := make([]*api.LFSLock, 0, len(lockList))
        for _, l := range lockList {
-               if l.Owner.ID == ctx.User.ID {
+               if l.OwnerID == ctx.User.ID {
                        lockOursListAPI = append(lockOursListAPI, convert.ToLFSLock(l))
                } else {
                        lockTheirsListAPI = append(lockTheirsListAPI, convert.ToLFSLock(l))
index 788765881656b403174e99bc58bf912006e9fee2..28756e4f1906b88162ad36f3ba819b1103b8cc74 100644 (file)
@@ -20,6 +20,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/json"
        lfs_module "code.gitea.io/gitea/modules/lfs"
@@ -506,7 +507,7 @@ func authenticate(ctx *context.Context, repository *models.Repository, authoriza
        return true
 }
 
-func handleLFSToken(tokenSHA string, target *models.Repository, mode models.AccessMode) (*models.User, error) {
+func handleLFSToken(tokenSHA string, target *models.Repository, mode models.AccessMode) (*user_model.User, error) {
        if !strings.Contains(tokenSHA, ".") {
                return nil, nil
        }
@@ -533,7 +534,7 @@ func handleLFSToken(tokenSHA string, target *models.Repository, mode models.Acce
                return nil, fmt.Errorf("invalid token claim")
        }
 
-       u, err := models.GetUserByID(claims.UserID)
+       u, err := user_model.GetUserByID(claims.UserID)
        if err != nil {
                log.Error("Unable to GetUserById[%d]: Error: %v", claims.UserID, err)
                return nil, err
@@ -541,7 +542,7 @@ func handleLFSToken(tokenSHA string, target *models.Repository, mode models.Acce
        return u, nil
 }
 
-func parseToken(authorization string, target *models.Repository, mode models.AccessMode) (*models.User, error) {
+func parseToken(authorization string, target *models.Repository, mode models.AccessMode) (*user_model.User, error) {
        if authorization == "" {
                return nil, fmt.Errorf("no token")
        }
index b579bf383a989b4f3934c3d124aedcc0130e5558..a9978be8b190ad7358530f68669ee0f225ca7971 100644 (file)
@@ -66,7 +66,7 @@ func SendTestMail(email string) error {
 }
 
 // sendUserMail sends a mail to the user
-func sendUserMail(language string, u *models.User, tpl base.TplName, code, subject, info string) {
+func sendUserMail(language string, u *user_model.User, tpl base.TplName, code, subject, info string) {
        locale := translation.NewLocale(language)
        data := map[string]interface{}{
                "DisplayName":       u.DisplayName(),
@@ -94,7 +94,7 @@ func sendUserMail(language string, u *models.User, tpl base.TplName, code, subje
 }
 
 // SendActivateAccountMail sends an activation mail to the user (new user registration)
-func SendActivateAccountMail(locale translation.Locale, u *models.User) {
+func SendActivateAccountMail(locale translation.Locale, u *user_model.User) {
        if setting.MailService == nil {
                // No mail service configured
                return
@@ -103,7 +103,7 @@ func SendActivateAccountMail(locale translation.Locale, u *models.User) {
 }
 
 // SendResetPasswordMail sends a password reset mail to the user
-func SendResetPasswordMail(u *models.User) {
+func SendResetPasswordMail(u *user_model.User) {
        if setting.MailService == nil {
                // No mail service configured
                return
@@ -113,7 +113,7 @@ func SendResetPasswordMail(u *models.User) {
 }
 
 // SendActivateEmailMail sends confirmation email to confirm new email address
-func SendActivateEmailMail(u *models.User, email *user_model.EmailAddress) {
+func SendActivateEmailMail(u *user_model.User, email *user_model.EmailAddress) {
        if setting.MailService == nil {
                // No mail service configured
                return
@@ -145,7 +145,7 @@ func SendActivateEmailMail(u *models.User, email *user_model.EmailAddress) {
 }
 
 // SendRegisterNotifyMail triggers a notify e-mail by admin created a account.
-func SendRegisterNotifyMail(u *models.User) {
+func SendRegisterNotifyMail(u *user_model.User) {
        if setting.MailService == nil {
                // No mail service configured
                return
@@ -176,7 +176,7 @@ func SendRegisterNotifyMail(u *models.User) {
 }
 
 // SendCollaboratorMail sends mail notification to new collaborator.
-func SendCollaboratorMail(u, doer *models.User, repo *models.Repository) {
+func SendCollaboratorMail(u, doer *user_model.User, repo *models.Repository) {
        if setting.MailService == nil {
                // No mail service configured
                return
@@ -209,7 +209,7 @@ func SendCollaboratorMail(u, doer *models.User, repo *models.Repository) {
        SendAsync(msg)
 }
 
-func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipients []*models.User, fromMention bool, info string) ([]*Message, error) {
+func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipients []*user_model.User, fromMention bool, info string) ([]*Message, error) {
        var (
                subject string
                link    string
@@ -337,7 +337,7 @@ func createReference(issue *models.Issue, comment *models.Comment) string {
        return fmt.Sprintf("%s/%s/%d%s@%s", issue.Repo.FullName(), path, issue.Index, extra, setting.Domain)
 }
 
-func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient *models.User) map[string]string {
+func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient *user_model.User) map[string]string {
        repo := ctx.Issue.Repo
 
        return map[string]string{
@@ -381,7 +381,7 @@ func sanitizeSubject(subject string) string {
 }
 
 // SendIssueAssignedMail composes and sends issue assigned email
-func SendIssueAssignedMail(issue *models.Issue, doer *models.User, content string, comment *models.Comment, recipients []*models.User) error {
+func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content string, comment *models.Comment, recipients []*user_model.User) error {
        if setting.MailService == nil {
                // No mail service configured
                return nil
@@ -392,7 +392,7 @@ func SendIssueAssignedMail(issue *models.Issue, doer *models.User, content strin
                return err
        }
 
-       langMap := make(map[string][]*models.User)
+       langMap := make(map[string][]*user_model.User)
        for _, user := range recipients {
                langMap[user.Language] = append(langMap[user.Language], user)
        }
index eef71557e7a655d5bc79d617093bc73bae65a274..3662164092c4b0818cc3f8a261ec1f73f8496c52 100644 (file)
@@ -6,12 +6,13 @@ package mailer
 
 import (
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
 )
 
 // MailParticipantsComment sends new comment emails to repository watchers and mentioned people.
-func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*models.User) error {
+func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*user_model.User) error {
        if setting.MailService == nil {
                // No mail service configured
                return nil
@@ -35,7 +36,7 @@ func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue
 }
 
 // MailMentionsComment sends email to users mentioned in a code comment
-func MailMentionsComment(pr *models.PullRequest, c *models.Comment, mentions []*models.User) (err error) {
+func MailMentionsComment(pr *models.PullRequest, c *models.Comment, mentions []*user_model.User) (err error) {
        if setting.MailService == nil {
                // No mail service configured
                return nil
index 6e631627136c8f535846af21fdcdb8ea786f3fbd..1fbe68e0222ee2a6af0bc0288aec6cc62ff89f94 100644 (file)
@@ -9,6 +9,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/log"
        "code.gitea.io/gitea/modules/setting"
 )
@@ -19,7 +20,7 @@ func fallbackMailSubject(issue *models.Issue) string {
 
 type mailCommentContext struct {
        Issue      *models.Issue
-       Doer       *models.User
+       Doer       *user_model.User
        ActionType models.ActionType
        Content    string
        Comment    *models.Comment
@@ -34,7 +35,7 @@ const (
 // This function sends two list of emails:
 // 1. Repository watchers (except for WIP pull requests) and users who are participated in comments.
 // 2. Users who are not in 1. but get mentioned in current issue/comment.
-func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*models.User) error {
+func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_model.User) error {
 
        // Required by the mail composer; make sure to load these before calling the async function
        if err := ctx.Issue.LoadRepo(); err != nil {
@@ -103,7 +104,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*models.
                visited[i] = true
        }
 
-       unfilteredUsers, err := models.GetMaileableUsersByIDs(unfiltered, false)
+       unfilteredUsers, err := user_model.GetMaileableUsersByIDs(unfiltered, false)
        if err != nil {
                return err
        }
@@ -114,18 +115,18 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*models.
        return nil
 }
 
-func mailIssueCommentBatch(ctx *mailCommentContext, users []*models.User, visited map[int64]bool, fromMention bool) error {
+func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, visited map[int64]bool, fromMention bool) error {
        checkUnit := unit.TypeIssues
        if ctx.Issue.IsPull {
                checkUnit = unit.TypePullRequests
        }
 
-       langMap := make(map[string][]*models.User)
+       langMap := make(map[string][]*user_model.User)
        for _, user := range users {
                // At this point we exclude:
                // user that don't have all mails enabled or users only get mail on mention and this is one ...
-               if !(user.EmailNotificationsPreference == models.EmailNotificationsEnabled ||
-                       fromMention && user.EmailNotificationsPreference == models.EmailNotificationsOnMention) {
+               if !(user.EmailNotificationsPreference == user_model.EmailNotificationsEnabled ||
+                       fromMention && user.EmailNotificationsPreference == user_model.EmailNotificationsOnMention) {
                        continue
                }
 
@@ -164,7 +165,7 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*models.User, visite
 
 // MailParticipants sends new issue thread created emails to repository watchers
 // and mentioned people.
-func MailParticipants(issue *models.Issue, doer *models.User, opType models.ActionType, mentions []*models.User) error {
+func MailParticipants(issue *models.Issue, doer *user_model.User, opType models.ActionType, mentions []*user_model.User) error {
        if setting.MailService == nil {
                // No mail service configured
                return nil
index a6fc28a5ca4471ec7888d7983686d566f5b3a7fd..72476fe8be0cb6f926eeda727d8f963b4939df6e 100644 (file)
@@ -8,6 +8,7 @@ import (
        "bytes"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/base"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/markup"
@@ -34,9 +35,9 @@ func MailNewRelease(rel *models.Release) {
                return
        }
 
-       recipients, err := models.GetMaileableUsersByIDs(watcherIDList, false)
+       recipients, err := user_model.GetMaileableUsersByIDs(watcherIDList, false)
        if err != nil {
-               log.Error("models.GetMaileableUsersByIDs: %v", err)
+               log.Error("user_model.GetMaileableUsersByIDs: %v", err)
                return
        }
 
index ef85f4aa543cd1d6336e435cbe06f79b20878e6a..8a2eeac0871bc68c520bddaaaab9975fb9a4cec1 100644 (file)
@@ -9,13 +9,14 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
        "code.gitea.io/gitea/modules/templates"
        "code.gitea.io/gitea/modules/translation"
 )
 
 // SendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created
-func SendRepoTransferNotifyMail(doer, newOwner *models.User, repo *models.Repository) error {
+func SendRepoTransferNotifyMail(doer, newOwner *user_model.User, repo *models.Repository) error {
        if setting.MailService == nil {
                // No mail service configured
                return nil
@@ -45,7 +46,7 @@ func SendRepoTransferNotifyMail(doer, newOwner *models.User, repo *models.Reposi
 }
 
 // sendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created for each language
-func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *models.User, emails []string, repo *models.Repository) error {
+func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *user_model.User, emails []string, repo *models.Repository) error {
        var (
                locale  = translation.NewLocale(lang)
                content bytes.Buffer
index 94ff5a65ae909362808efcb48aa59ddf1af5f275..8e8cd982312548e2661943f51e75c8b42faf8cf7 100644 (file)
@@ -12,6 +12,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
 
        "github.com/stretchr/testify/assert"
@@ -40,7 +41,7 @@ const bodyTpl = `
 </html>
 `
 
-func prepareMailerTest(t *testing.T) (doer *models.User, repo *models.Repository, issue *models.Issue, comment *models.Comment) {
+func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *models.Repository, issue *models.Issue, comment *models.Comment) {
        assert.NoError(t, unittest.PrepareTestDatabase())
        var mailService = setting.Mailer{
                From: "test@gitea.com",
@@ -49,7 +50,7 @@ func prepareMailerTest(t *testing.T) (doer *models.User, repo *models.Repository
        setting.MailService = &mailService
        setting.Domain = "localhost"
 
-       doer = unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1, Owner: doer}).(*models.Repository)
        issue = unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1, Repo: repo, Poster: doer}).(*models.Issue)
        assert.NoError(t, issue.LoadRepo())
@@ -64,7 +65,7 @@ func TestComposeIssueCommentMessage(t *testing.T) {
        btpl := template.Must(template.New("issue/comment").Parse(bodyTpl))
        InitMailRender(stpl, btpl)
 
-       recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
+       recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
        msgs, err := composeIssueCommentMessages(&mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
                Content: "test body", Comment: comment}, "en-US", recipients, false, "issue comment")
        assert.NoError(t, err)
@@ -91,7 +92,7 @@ func TestComposeIssueMessage(t *testing.T) {
        btpl := template.Must(template.New("issue/new").Parse(bodyTpl))
        InitMailRender(stpl, btpl)
 
-       recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
+       recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
        msgs, err := composeIssueCommentMessages(&mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
                Content: "test body"}, "en-US", recipients, false, "issue create")
        assert.NoError(t, err)
@@ -113,7 +114,7 @@ func TestComposeIssueMessage(t *testing.T) {
 
 func TestTemplateSelection(t *testing.T) {
        doer, repo, issue, comment := prepareMailerTest(t)
-       recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}}
+       recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
 
        stpl := texttmpl.Must(texttmpl.New("issue/default").Parse("issue/default/subject"))
        texttmpl.Must(stpl.New("issue/new").Parse("issue/new/subject"))
@@ -159,14 +160,14 @@ func TestTemplateServices(t *testing.T) {
        doer, _, issue, comment := prepareMailerTest(t)
        assert.NoError(t, issue.LoadRepo())
 
-       expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *models.User,
+       expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *user_model.User,
                actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string) {
 
                stpl := texttmpl.Must(texttmpl.New("issue/default").Parse(tplSubject))
                btpl := template.Must(template.New("issue/default").Parse(tplBody))
                InitMailRender(stpl, btpl)
 
-               recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}}
+               recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
                msg := testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: actionType,
                        Content: "test body", Comment: comment}, recipients, fromMention, "TestTemplateServices")
 
@@ -198,7 +199,7 @@ func TestTemplateServices(t *testing.T) {
                "//Re: //")
 }
 
-func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recipients []*models.User, fromMention bool, info string) *Message {
+func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recipients []*user_model.User, fromMention bool, info string) *Message {
        msgs, err := composeIssueCommentMessages(ctx, "en-US", recipients, fromMention, info)
        assert.NoError(t, err)
        assert.Len(t, msgs, 1)
@@ -209,7 +210,7 @@ func TestGenerateAdditionalHeaders(t *testing.T) {
        doer, _, issue, _ := prepareMailerTest(t)
 
        ctx := &mailCommentContext{Issue: issue, Doer: doer}
-       recipient := &models.User{Name: "Test", Email: "test@gitea.com"}
+       recipient := &user_model.User{Name: "Test", Email: "test@gitea.com"}
 
        headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)
 
index 6e3596230fda6710b314fb342ac14bb4fcd4a5af..afff49a05973a0716e3d04b7b397ebc78b64baa4 100644 (file)
@@ -17,7 +17,7 @@ import (
        "strings"
        "time"
 
-       "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        base "code.gitea.io/gitea/modules/migration"
@@ -607,7 +607,7 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) {
 
 // RestoreRepository restore a repository from the disk directory
 func RestoreRepository(ctx context.Context, baseDir string, ownerName, repoName string, units []string) error {
-       doer, err := models.GetAdminUser()
+       doer, err := user_model.GetAdminUser()
        if err != nil {
                return err
        }
index d28c83a64f5efccba029763f32b3092e268bbfbf..3bc8992c3a6afe4a3824f7dd4c522bb8eb26e387 100644 (file)
@@ -18,6 +18,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        repo_model "code.gitea.io/gitea/models/repo"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        base "code.gitea.io/gitea/modules/migration"
@@ -39,7 +40,7 @@ var (
 // GiteaLocalUploader implements an Uploader to gitea sites
 type GiteaLocalUploader struct {
        ctx            context.Context
-       doer           *models.User
+       doer           *user_model.User
        repoOwner      string
        repoName       string
        repo           *models.Repository
@@ -54,7 +55,7 @@ type GiteaLocalUploader struct {
 }
 
 // NewGiteaLocalUploader creates an gitea Uploader via gitea API v1
-func NewGiteaLocalUploader(ctx context.Context, doer *models.User, repoOwner, repoName string) *GiteaLocalUploader {
+func NewGiteaLocalUploader(ctx context.Context, doer *user_model.User, repoOwner, repoName string) *GiteaLocalUploader {
        return &GiteaLocalUploader{
                ctx:         ctx,
                doer:        doer,
@@ -87,7 +88,7 @@ func (g *GiteaLocalUploader) MaxBatchInsertSize(tp string) int {
 
 // CreateRepo creates a repository
 func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.MigrateOptions) error {
-       owner, err := models.GetUserByName(g.repoOwner)
+       owner, err := user_model.GetUserByName(g.repoOwner)
        if err != nil {
                return err
        }
index 9b04004cd73b9dc8b938f6e94c8bb1c7df3972d1..45876dd9603205d23baad24ac76ba20eccd550a7 100644 (file)
@@ -13,6 +13,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/graceful"
        base "code.gitea.io/gitea/modules/migration"
        "code.gitea.io/gitea/modules/structs"
@@ -27,7 +28,7 @@ func TestGiteaUploadRepo(t *testing.T) {
 
        unittest.PrepareTestEnv(t)
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
 
        var (
                downloader = NewGithubDownloaderV3(context.Background(), "https://github.com", "", "", "", "go-xorm", "builder")
index 3e805f0b71eb67e538d50a90b7c0f6de0b7a9b08..02b167b27c4d66552da051d2779ed26e619ae74f 100644 (file)
@@ -15,6 +15,7 @@ import (
 
        "code.gitea.io/gitea/models"
        admin_model "code.gitea.io/gitea/models/admin"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/hostmatcher"
        "code.gitea.io/gitea/modules/log"
        base "code.gitea.io/gitea/modules/migration"
@@ -38,7 +39,7 @@ func RegisterDownloaderFactory(factory base.DownloaderFactory) {
 }
 
 // IsMigrateURLAllowed checks if an URL is allowed to be migrated from
-func IsMigrateURLAllowed(remoteURL string, doer *models.User) error {
+func IsMigrateURLAllowed(remoteURL string, doer *user_model.User) error {
        // Remote address can be HTTP/HTTPS/Git URL or local path.
        u, err := url.Parse(remoteURL)
        if err != nil {
@@ -105,7 +106,7 @@ func IsMigrateURLAllowed(remoteURL string, doer *models.User) error {
 }
 
 // MigrateRepository migrate repository according MigrateOptions
-func MigrateRepository(ctx context.Context, doer *models.User, ownerName string, opts base.MigrateOptions, messenger base.Messenger) (*models.Repository, error) {
+func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName string, opts base.MigrateOptions, messenger base.Messenger) (*models.Repository, error) {
        err := IsMigrateURLAllowed(opts.CloneAddr, doer)
        if err != nil {
                return nil, err
index e2363242a20babcf75259eaed464cf660ecd17d3..d09c184d91e0d51e8df98a1163627109aa6ad96d 100644 (file)
@@ -8,8 +8,8 @@ import (
        "path/filepath"
        "testing"
 
-       "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
 
        "github.com/stretchr/testify/assert"
@@ -18,8 +18,8 @@ import (
 func TestMigrateWhiteBlocklist(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       adminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
-       nonAdminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
+       adminUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user1"}).(*user_model.User)
+       nonAdminUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user2"}).(*user_model.User)
 
        setting.Migrations.AllowedDomains = "github.com"
        setting.Migrations.AllowLocalNetworks = false
index c2b21d10ac9167809de5c7a5b8bb157da03eea11..834c6e5abacfedee056812c3c82566120abf7670 100644 (file)
@@ -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/storage"
        "code.gitea.io/gitea/modules/util"
 )
@@ -40,7 +41,7 @@ func DeleteOrganization(org *models.Organization) error {
        // FIXME: system notice
        // Note: There are something just cannot be roll back,
        //      so just keep error logs of those operations.
-       path := models.UserPath(org.Name)
+       path := user_model.UserPath(org.Name)
 
        if err := util.RemoveAll(path); err != nil {
                return fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
index 3c620c055be5e9e95767aba0db4a8a76d78ed855..aaa2756bb5cff9b09091e7b5130dc73f09a8dd0f 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -33,5 +34,5 @@ func TestDeleteOrganization(t *testing.T) {
 
        user := unittest.AssertExistsAndLoadBean(t, &models.Organization{ID: 5}).(*models.Organization)
        assert.Error(t, DeleteOrganization(user))
-       unittest.CheckConsistencyFor(t, &models.User{}, &models.Team{})
+       unittest.CheckConsistencyFor(t, &user_model.User{}, &models.Team{})
 }
index 1fb167ac2192f59adc05573f81055789bcff48a0..03d4a39919f196bf2b1c2dffd7d7b28191913bb8 100644 (file)
@@ -14,6 +14,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/git"
        "code.gitea.io/gitea/modules/graceful"
        "code.gitea.io/gitea/modules/log"
@@ -159,7 +160,7 @@ func manuallyMerged(pr *models.PullRequest) bool {
                pr.MergedCommitID = commit.ID.String()
                pr.MergedUnix = timeutil.TimeStamp(commit.Author.When.Unix())
                pr.Status = models.PullRequestStatusManuallyMerged
-               merger, _ := models.GetUserByEmail(commit.Author.Email)
+               merger, _ := user_model.GetUserByEmail(commit.Author.Email)
 
                // When the commit author is unknown set the BaseRepo owner as merger
                if merger == nil {
index e4ed4e38bd9c5d179cb6e33bd9feff7c5b1775ed..f94aa36128de79ba9e0442f26ba7cda2c58186d1 100644 (file)
@@ -17,6 +17,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/cache"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
@@ -30,7 +31,7 @@ import (
 // Merge merges pull request to base repository.
 // Caller should check PR is ready to be merged (review and status checks)
 // FIXME: add repoWorkingPull make sure two merges does not happen at same time.
-func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository, mergeStyle models.MergeStyle, message string) (err error) {
+func Merge(pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle models.MergeStyle, message string) (err error) {
        if err = pr.LoadHeadRepo(); err != nil {
                log.Error("LoadHeadRepo: %v", err)
                return fmt.Errorf("LoadHeadRepo: %v", err)
@@ -110,7 +111,7 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
 }
 
 // rawMerge perform the merge operation without changing any pull information in database
-func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.MergeStyle, message string) (string, error) {
+func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.MergeStyle, message string) (string, error) {
        err := git.LoadGitVersion()
        if err != nil {
                log.Error("git.LoadGitVersion: %v", err)
@@ -396,10 +397,10 @@ func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.Merge
                }
        }
 
-       var headUser *models.User
+       var headUser *user_model.User
        err = pr.HeadRepo.GetOwner()
        if err != nil {
-               if !models.IsErrUserNotExist(err) {
+               if !user_model.IsErrUserNotExist(err) {
                        log.Error("Can't find user: %d for head repository - %v", pr.HeadRepo.OwnerID, err)
                        return "", err
                }
@@ -541,7 +542,7 @@ func getDiffTree(repoPath, baseBranch, headBranch string) (string, error) {
 }
 
 // IsSignedIfRequired check if merge will be signed if required
-func IsSignedIfRequired(pr *models.PullRequest, doer *models.User) (bool, error) {
+func IsSignedIfRequired(pr *models.PullRequest, doer *user_model.User) (bool, error) {
        if err := pr.LoadProtectedBranch(); err != nil {
                return false, err
        }
@@ -556,7 +557,7 @@ func IsSignedIfRequired(pr *models.PullRequest, doer *models.User) (bool, error)
 }
 
 // IsUserAllowedToMerge check if user is allowed to merge PR with given permissions and branch protections
-func IsUserAllowedToMerge(pr *models.PullRequest, p models.Permission, user *models.User) (bool, error) {
+func IsUserAllowedToMerge(pr *models.PullRequest, p models.Permission, user *user_model.User) (bool, error) {
        if user == nil {
                return false, nil
        }
@@ -632,7 +633,7 @@ func CheckPRReadyToMerge(pr *models.PullRequest, skipProtectedFilesCheck bool) (
 }
 
 // MergedManually mark pr as merged manually
-func MergedManually(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository, commitID string) (err error) {
+func MergedManually(pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, commitID string) (err error) {
        prUnit, err := pr.BaseRepo.GetUnit(unit.TypePullRequests)
        if err != nil {
                return
index 5f6198a393147b9afff1dac5eddeb31d7444b89f..339fb1e22d163323c53fc9b5652bba6567e2f15a 100644 (file)
@@ -15,6 +15,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/git"
        "code.gitea.io/gitea/modules/graceful"
        "code.gitea.io/gitea/modules/json"
@@ -113,7 +114,7 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6
 }
 
 // ChangeTargetBranch changes the target branch of this pull request, as the given user.
-func ChangeTargetBranch(pr *models.PullRequest, doer *models.User, targetBranch string) (err error) {
+func ChangeTargetBranch(pr *models.PullRequest, doer *user_model.User, targetBranch string) (err error) {
        // Current target branch is already the same
        if pr.BaseBranch == targetBranch {
                return nil
@@ -209,7 +210,7 @@ func ChangeTargetBranch(pr *models.PullRequest, doer *models.User, targetBranch
        return nil
 }
 
-func checkForInvalidation(requests models.PullRequestList, repoID int64, doer *models.User, branch string) error {
+func checkForInvalidation(requests models.PullRequestList, repoID int64, doer *user_model.User, branch string) error {
        repo, err := models.GetRepositoryByID(repoID)
        if err != nil {
                return fmt.Errorf("GetRepositoryByID: %v", err)
@@ -231,7 +232,7 @@ func checkForInvalidation(requests models.PullRequestList, repoID int64, doer *m
 
 // AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
 // and generate new patch for testing as needed.
-func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSync bool, oldCommitID, newCommitID string) {
+func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, isSync bool, oldCommitID, newCommitID string) {
        log.Trace("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests", repoID, branch)
        graceful.GetManager().RunWithShutdownContext(func(ctx context.Context) {
                // There is no sensible way to shut this down ":-("
@@ -494,7 +495,7 @@ func (errs errlist) Error() string {
 }
 
 // CloseBranchPulls close all the pull requests who's head branch is the branch
-func CloseBranchPulls(doer *models.User, repoID int64, branch string) error {
+func CloseBranchPulls(doer *user_model.User, repoID int64, branch string) error {
        prs, err := models.GetUnmergedPullRequestsByHeadInfo(repoID, branch)
        if err != nil {
                return err
@@ -523,7 +524,7 @@ func CloseBranchPulls(doer *models.User, repoID int64, branch string) error {
 }
 
 // CloseRepoBranchesPulls close all pull requests which head branches are in the given repository, but only whose base repo is not in the given repository
-func CloseRepoBranchesPulls(doer *models.User, repo *models.Repository) error {
+func CloseRepoBranchesPulls(doer *user_model.User, repo *models.Repository) error {
        branches, _, err := git.GetBranchesByPath(repo.RepoPath(), 0, 0)
        if err != nil {
                return err
index 081b17cd83e83e34f3037ece127553e33a47bf08..31c2e99782c40ee8c4aa43bb3198059e9f6ec7c3 100644 (file)
@@ -13,6 +13,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/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/notification"
@@ -20,7 +21,7 @@ import (
 )
 
 // CreateCodeComment creates a comment on the code line
-func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models.Issue, line int64, content string, treePath string, isReview bool, replyReviewID int64, latestCommitID string) (*models.Comment, error) {
+func CreateCodeComment(doer *user_model.User, gitRepo *git.Repository, issue *models.Issue, line int64, content string, treePath string, isReview bool, replyReviewID int64, latestCommitID string) (*models.Comment, error) {
 
        var (
                existsReview bool
@@ -114,7 +115,7 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models
 var notEnoughLines = regexp.MustCompile(`exit status 128 - fatal: file .* has only \d+ lines?`)
 
 // createCodeComment creates a plain code comment at the specified line / path
-func createCodeComment(doer *models.User, repo *models.Repository, issue *models.Issue, content, treePath string, line, reviewID int64) (*models.Comment, error) {
+func createCodeComment(doer *user_model.User, repo *models.Repository, issue *models.Issue, content, treePath string, line, reviewID int64) (*models.Comment, error) {
        var commitID, patch string
        if err := issue.LoadPullRequest(); err != nil {
                return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err)
@@ -216,7 +217,7 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
 }
 
 // SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
-func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issue, reviewType models.ReviewType, content, commitID string, attachmentUUIDs []string) (*models.Review, *models.Comment, error) {
+func SubmitReview(doer *user_model.User, gitRepo *git.Repository, issue *models.Issue, reviewType models.ReviewType, content, commitID string, attachmentUUIDs []string) (*models.Review, *models.Comment, error) {
        pr, err := issue.GetPullRequest()
        if err != nil {
                return nil, nil, err
@@ -270,7 +271,7 @@ func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issu
 }
 
 // DismissReview dismissing stale review by repo admin
-func DismissReview(reviewID int64, message string, doer *models.User, isDismiss bool) (comment *models.Comment, err error) {
+func DismissReview(reviewID int64, message string, doer *user_model.User, isDismiss bool) (comment *models.Comment, err error) {
        review, err := models.GetReviewByID(reviewID)
        if err != nil {
                return
index 4b4e67797ef3433ca16995e8e17430e57763f98f..ef6e84598e5dc0cc6c23e2f3908020a1de53f219 100644 (file)
@@ -8,12 +8,13 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
 )
 
 // Update updates pull request with base branch.
-func Update(pull *models.PullRequest, doer *models.User, message string, rebase bool) error {
+func Update(pull *models.PullRequest, doer *user_model.User, message string, rebase bool) error {
        var (
                pr    *models.PullRequest
                style models.MergeStyle
@@ -67,7 +68,7 @@ func Update(pull *models.PullRequest, doer *models.User, message string, rebase
 }
 
 // IsUserAllowedToUpdate check if user is allowed to update PR with given permissions and branch protections
-func IsUserAllowedToUpdate(pull *models.PullRequest, user *models.User) (mergeAllowed, rebaseAllowed bool, err error) {
+func IsUserAllowedToUpdate(pull *models.PullRequest, user *user_model.User) (mergeAllowed, rebaseAllowed bool, err error) {
        if pull.Flow == models.PullRequestFlowAGit {
                return false, false, nil
        }
index 30274f93efa9db0c6ea40bbd51187cea0ca90f37..ec1494d42606159909114500c4d1e717e18cd37d 100644 (file)
@@ -12,6 +12,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        repo_model "code.gitea.io/gitea/models/repo"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/notification"
@@ -93,7 +94,7 @@ func createTag(gitRepo *git.Repository, rel *models.Release, msg string) (bool,
                }
 
                if rel.PublisherID <= 0 {
-                       u, err := models.GetUserByEmail(commit.Author.Email)
+                       u, err := user_model.GetUserByEmail(commit.Author.Email)
                        if err == nil {
                                rel.PublisherID = u.ID
                        }
@@ -136,7 +137,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
 }
 
 // CreateNewTag creates a new repository tag
-func CreateNewTag(doer *models.User, repo *models.Repository, commit, tagName, msg string) error {
+func CreateNewTag(doer *user_model.User, repo *models.Repository, commit, tagName, msg string) error {
        isExist, err := models.IsReleaseExist(repo.ID, tagName)
        if err != nil {
                return err
@@ -179,7 +180,7 @@ func CreateNewTag(doer *models.User, repo *models.Repository, commit, tagName, m
 // addAttachmentUUIDs accept a slice of new created attachments' uuids which will be reassigned release_id as the created release
 // delAttachmentUUIDs accept a slice of attachments' uuids which will be deleted from the release
 // editAttachments accept a map of attachment uuid to new attachment name which will be updated with attachments.
-func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Release,
+func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *models.Release,
        addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string) (err error) {
        if rel.ID == 0 {
                return errors.New("UpdateRelease only accepts an exist release")
@@ -278,7 +279,7 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea
 }
 
 // DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
-func DeleteReleaseByID(id int64, doer *models.User, delTag bool) error {
+func DeleteReleaseByID(id int64, doer *user_model.User, delTag bool) error {
        rel, err := models.GetReleaseByID(id)
        if err != nil {
                return fmt.Errorf("GetReleaseByID: %v", err)
index 92eb128f71dae91af4653e2f5280504f24ce9f3b..29ff78ca3a7dfdfe6b253682e2a5448df804bf8f 100644 (file)
@@ -13,6 +13,7 @@ import (
        "code.gitea.io/gitea/models"
        repo_model "code.gitea.io/gitea/models/repo"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/services/attachment"
 
@@ -26,7 +27,7 @@ func TestMain(m *testing.M) {
 func TestRelease_Create(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        repoPath := models.RepoPath(user.Name, repo.Name)
 
@@ -130,7 +131,7 @@ func TestRelease_Create(t *testing.T) {
 func TestRelease_Update(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        repoPath := models.RepoPath(user.Name, repo.Name)
 
@@ -272,7 +273,7 @@ func TestRelease_Update(t *testing.T) {
 func TestRelease_createTag(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        repoPath := models.RepoPath(user.Name, repo.Name)
 
@@ -354,7 +355,7 @@ func TestRelease_createTag(t *testing.T) {
 
 func TestCreateNewTag(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
 
        assert.NoError(t, CreateNewTag(user, repo, "master", "v2.0",
index d48411fbb427d18385c80fe3d0dab781c088b2c2..3f4045a778310ec851bb875f463499155e8246eb 100644 (file)
@@ -13,6 +13,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/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/notification"
@@ -24,7 +25,7 @@ import (
 )
 
 // AdoptRepository adopts pre-existing repository files for the user/organization.
-func AdoptRepository(doer, u *models.User, opts models.CreateRepoOptions) (*models.Repository, error) {
+func AdoptRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) {
        if !doer.IsAdmin && !u.CanCreateRepo() {
                return nil, models.ErrReachLimitOfRepo{
                        Limit: u.MaxRepoCreation,
@@ -98,7 +99,7 @@ func AdoptRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mode
        return repo, nil
 }
 
-func adoptRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
+func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
        isExist, err := util.IsExist(repoPath)
        if err != nil {
                log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
@@ -185,7 +186,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *models.User, repo
 }
 
 // DeleteUnadoptedRepository deletes unadopted repository files from the filesystem
-func DeleteUnadoptedRepository(doer, u *models.User, repoName string) error {
+func DeleteUnadoptedRepository(doer, u *user_model.User, repoName string) error {
        if err := models.IsUsableRepoName(repoName); err != nil {
                return err
        }
@@ -240,7 +241,7 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
        repoNamesToCheck := make([]string, 0, opts.PageSize)
 
        repoNames := make([]string, 0, opts.PageSize)
-       var ctxUser *models.User
+       var ctxUser *user_model.User
 
        count := 0
 
@@ -293,9 +294,9 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
                                return filepath.SkipDir
                        }
 
-                       ctxUser, err = models.GetUserByName(info.Name())
+                       ctxUser, err = user_model.GetUserByName(info.Name())
                        if err != nil {
-                               if models.IsErrUserNotExist(err) {
+                               if user_model.IsErrUserNotExist(err) {
                                        log.Debug("Missing user: %s", info.Name())
                                        return filepath.SkipDir
                                }
index f94a9afcb67925ca6679a7a49f0e040405fec435..92e662f3d6d45a7cccb047b657ba0f054610bd42 100644 (file)
@@ -9,6 +9,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/notification"
@@ -17,7 +18,7 @@ import (
 )
 
 // CreateNewBranch creates a new repository branch
-func CreateNewBranch(doer *models.User, repo *models.Repository, oldBranchName, branchName string) (err error) {
+func CreateNewBranch(doer *user_model.User, repo *models.Repository, oldBranchName, branchName string) (err error) {
        // Check if branch name can be used
        if err := checkBranchName(repo, branchName); err != nil {
                return err
@@ -99,7 +100,7 @@ func checkBranchName(repo *models.Repository, name string) error {
 }
 
 // CreateNewBranchFromCommit creates a new repository branch
-func CreateNewBranchFromCommit(doer *models.User, repo *models.Repository, commit, branchName string) (err error) {
+func CreateNewBranchFromCommit(doer *user_model.User, repo *models.Repository, commit, branchName string) (err error) {
        // Check if branch name can be used
        if err := checkBranchName(repo, branchName); err != nil {
                return err
@@ -120,7 +121,7 @@ func CreateNewBranchFromCommit(doer *models.User, repo *models.Repository, commi
 }
 
 // RenameBranch rename a branch
-func RenameBranch(repo *models.Repository, doer *models.User, gitRepo *git.Repository, from, to string) (string, error) {
+func RenameBranch(repo *models.Repository, doer *user_model.User, gitRepo *git.Repository, from, to string) (string, error) {
        if from == to {
                return "target_exist", nil
        }
@@ -164,7 +165,7 @@ var (
 )
 
 // DeleteBranch delete branch
-func DeleteBranch(doer *models.User, repo *models.Repository, gitRepo *git.Repository, branchName string) error {
+func DeleteBranch(doer *user_model.User, repo *models.Repository, gitRepo *git.Repository, branchName string) error {
        if branchName == repo.DefaultBranch {
                return ErrBranchIsDefault
        }
index 36bd4e2e0de6f0bb71c348f2c9e61b9565bdde71..ab7539e555549c8347895d2e3e5cd5798a8164f3 100644 (file)
@@ -13,6 +13,7 @@ import (
        "code.gitea.io/gitea/models"
        admin_model "code.gitea.io/gitea/models/admin"
        "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/util"
@@ -149,7 +150,7 @@ func gatherMissingRepoRecords(ctx context.Context) ([]*models.Repository, error)
 }
 
 // DeleteMissingRepositories deletes all repository records that lost Git files.
-func DeleteMissingRepositories(ctx context.Context, doer *models.User) error {
+func DeleteMissingRepositories(ctx context.Context, doer *user_model.User) error {
        repos, err := gatherMissingRepoRecords(ctx)
        if err != nil {
                return err
index ebae0971123f772690b05f1f114f5824a8382754..8f14ed89263004f96f830c29a96ffbcef48f529b 100644 (file)
@@ -8,6 +8,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/structs"
 )
@@ -15,7 +16,7 @@ import (
 // CreateCommitStatus creates a new CommitStatus given a bunch of parameters
 // NOTE: All text-values will be trimmed from whitespaces.
 // Requires: Repo, Creator, SHA
-func CreateCommitStatus(repo *models.Repository, creator *models.User, sha string, status *models.CommitStatus) error {
+func CreateCommitStatus(repo *models.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error {
        repoPath := repo.RepoPath()
 
        // confirm that commit is exist
index f8d7f62c14294948fd92840c4d950d7f7002a1b1..f7b342db3f7a86f9f935809d288c3525d2b2143f 100644 (file)
@@ -9,6 +9,7 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        api "code.gitea.io/gitea/modules/structs"
        repo_service "code.gitea.io/gitea/services/repository"
@@ -29,7 +30,7 @@ type DeleteRepoFileOptions struct {
 }
 
 // DeleteRepoFile deletes a file in the given repository
-func DeleteRepoFile(repo *models.Repository, doer *models.User, opts *DeleteRepoFileOptions) (*api.FileResponse, error) {
+func DeleteRepoFile(repo *models.Repository, doer *user_model.User, opts *DeleteRepoFileOptions) (*api.FileResponse, error) {
        // If no branch name is set, assume the repo's default branch
        if opts.OldBranch == "" {
                opts.OldBranch = repo.DefaultBranch
index ad445bb4ae20be216884782d3b6ba34143f79f7b..8de60c4cb85441f79f9f0d9cf369337114b992f0 100644 (file)
@@ -12,6 +12,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        api "code.gitea.io/gitea/modules/structs"
 )
@@ -81,7 +82,7 @@ func GetFileCommitResponse(repo *models.Repository, commit *git.Commit) (*api.Fi
 }
 
 // GetAuthorAndCommitterUsers Gets the author and committer user objects from the IdentityOptions
-func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *models.User) (authorUser, committerUser *models.User) {
+func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *user_model.User) (authorUser, committerUser *user_model.User) {
        // Committer and author are optional. If they are not the doer (not same email address)
        // then we use bogus User objects for them to store their FullName and Email.
        // If only one of the two are provided, we set both of them to it.
@@ -93,7 +94,7 @@ func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *models
                                committerUser.FullName = committer.Name
                        }
                } else {
-                       committerUser = &models.User{
+                       committerUser = &user_model.User{
                                FullName: committer.Name,
                                Email:    committer.Email,
                        }
@@ -106,7 +107,7 @@ func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *models
                                authorUser.FullName = author.Name
                        }
                } else {
-                       authorUser = &models.User{
+                       authorUser = &user_model.User{
                                FullName: author.Name,
                                Email:    author.Email,
                        }
index 2a6d6c3ab6235faf91ebe7185a81a676b9794ab1..0b6bea637954b6e6245cef7fce9de2ea3d087245 100644 (file)
@@ -15,6 +15,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/setting"
@@ -185,12 +186,12 @@ func (t *TemporaryUploadRepository) GetLastCommitByRef(ref string) (string, erro
 }
 
 // CommitTree creates a commit from a given tree for the user with provided message
-func (t *TemporaryUploadRepository) CommitTree(author, committer *models.User, treeHash string, message string, signoff bool) (string, error) {
+func (t *TemporaryUploadRepository) CommitTree(author, committer *user_model.User, treeHash string, message string, signoff bool) (string, error) {
        return t.CommitTreeWithDate(author, committer, treeHash, message, signoff, time.Now(), time.Now())
 }
 
 // CommitTreeWithDate creates a commit from a given tree for the user with provided message
-func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models.User, treeHash string, message string, signoff bool, authorDate, committerDate time.Time) (string, error) {
+func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *user_model.User, treeHash string, message string, signoff bool, authorDate, committerDate time.Time) (string, error) {
        authorSig := author.NewGitSig()
        committerSig := committer.NewGitSig()
 
@@ -260,7 +261,7 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models
 }
 
 // Push the provided commitHash to the repository branch by the provided user
-func (t *TemporaryUploadRepository) Push(doer *models.User, commitHash string, branch string) error {
+func (t *TemporaryUploadRepository) Push(doer *user_model.User, commitHash string, branch string) error {
        // Because calls hooks we need to pass in the environment
        env := models.PushingEnvironment(doer, t.repo)
        if err := git.Push(t.basePath, git.PushOptions{
index 5d6c3da6707d7ae14d8a5a1ae58b5e54ea423ae9..eeb98f363026c373ff0cf6ec04f56e7700af7dca 100644 (file)
@@ -12,6 +12,7 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/charset"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/lfs"
@@ -122,7 +123,7 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string
 }
 
 // CreateOrUpdateRepoFile adds or updates a file in the given repository
-func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *UpdateRepoFileOptions) (*structs.FileResponse, error) {
+func CreateOrUpdateRepoFile(repo *models.Repository, doer *user_model.User, opts *UpdateRepoFileOptions) (*structs.FileResponse, error) {
        // If no branch name is set, assume default branch
        if opts.OldBranch == "" {
                opts.OldBranch = repo.DefaultBranch
@@ -439,7 +440,7 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up
 }
 
 // VerifyBranchProtection verify the branch protection for modifying the given treePath on the given branch
-func VerifyBranchProtection(repo *models.Repository, doer *models.User, branchName string, treePath string) error {
+func VerifyBranchProtection(repo *models.Repository, doer *user_model.User, branchName string, treePath string) error {
        protectedBranch, err := repo.GetBranchProtection(branchName)
        if err != nil {
                return err
index 98d01506d53a9643330965171dc54eea8368b880..7a0ea31085e5b578a0dfc36cb7cfa53b516e03de 100644 (file)
@@ -11,6 +11,7 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/lfs"
        "code.gitea.io/gitea/modules/setting"
@@ -47,7 +48,7 @@ func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, orig
 }
 
 // UploadRepoFiles uploads files to the given repository
-func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRepoFileOptions) error {
+func UploadRepoFiles(repo *models.Repository, doer *user_model.User, opts *UploadRepoFileOptions) error {
        if len(opts.Files) == 0 {
                return nil
        }
@@ -67,7 +68,11 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
                        return err
                }
                if lfsLock != nil && lfsLock.OwnerID != doer.ID {
-                       return models.ErrLFSFileLocked{RepoID: repo.ID, Path: filepath, UserName: lfsLock.Owner.Name}
+                       u, err := user_model.GetUserByID(lfsLock.OwnerID)
+                       if err != nil {
+                               return err
+                       }
+                       return models.ErrLFSFileLocked{RepoID: repo.ID, Path: filepath, UserName: u.Name}
                }
 
                names[i] = upload.Name
index f052d18a7591631c96e6f6a8a61cd57ca909aa54..3fc08b4986f8e266790f258573bdb698324e4ceb 100644 (file)
@@ -12,6 +12,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/git"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/notification"
@@ -21,7 +22,7 @@ import (
 )
 
 // ForkRepository forks a repository
-func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *models.Repository, err error) {
+func ForkRepository(doer, owner *user_model.User, opts models.ForkRepoOptions) (_ *models.Repository, err error) {
        forkedRepo, err := opts.BaseRepo.GetUserFork(owner.ID)
        if err != nil {
                return nil, err
index 1280a3d84da1b24db878e01b787f39c60bc1910d..befb606135678f170bbe3299cc03783446662fd8 100644 (file)
@@ -9,6 +9,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
 )
@@ -17,7 +18,7 @@ func TestForkRepository(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
        // user 13 has already forked repo10
-       user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 13}).(*models.User)
+       user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
 
        fork, err := ForkRepository(user, user, models.ForkRepoOptions{
index fe38723dea35347352e872366c1245c5747038a7..031648666d9b4953d8f80a669af852a26fccc846 100644 (file)
@@ -9,13 +9,14 @@ 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/log"
        "code.gitea.io/gitea/modules/notification"
        repo_module "code.gitea.io/gitea/modules/repository"
 )
 
 // GenerateRepository generates a repository from a template
-func GenerateRepository(doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
+func GenerateRepository(doer, owner *user_model.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
        if !doer.IsAdmin && !owner.CanCreateRepo() {
                return nil, models.ErrReachLimitOfRepo{
                        Limit: owner.MaxRepoCreation,
index 97554c64900ca6a5c2065181d215eeba428ed7d9..7b439a41f48658520afed4598a42a5d084b2bca6 100644 (file)
@@ -13,6 +13,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/cache"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/graceful"
@@ -93,7 +94,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
 
        addTags := make([]string, 0, len(optsList))
        delTags := make([]string, 0, len(optsList))
-       var pusher *models.User
+       var pusher *user_model.User
 
        for _, opts := range optsList {
                if opts.IsNewRef() && opts.IsDelRef() {
@@ -102,7 +103,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
                if opts.IsTag() { // If is tag reference
                        if pusher == nil || pusher.ID != opts.PusherID {
                                var err error
-                               if pusher, err = models.GetUserByID(opts.PusherID); err != nil {
+                               if pusher, err = user_model.GetUserByID(opts.PusherID); err != nil {
                                        return err
                                }
                        }
@@ -133,7 +134,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
                } else if opts.IsBranch() { // If is branch reference
                        if pusher == nil || pusher.ID != opts.PusherID {
                                var err error
-                               if pusher, err = models.GetUserByID(opts.PusherID); err != nil {
+                               if pusher, err = user_model.GetUserByID(opts.PusherID); err != nil {
                                        return err
                                }
                        }
@@ -276,7 +277,7 @@ func pushUpdateAddTags(ctx context.Context, repo *models.Repository, gitRepo *gi
 
        newReleases := make([]*models.Release, 0, len(lowerTags)-len(relMap))
 
-       emailToUser := make(map[string]*models.User)
+       emailToUser := make(map[string]*user_model.User)
 
        for i, lowerTag := range lowerTags {
                tag, err := gitRepo.GetTag(tags[i])
@@ -295,15 +296,15 @@ func pushUpdateAddTags(ctx context.Context, repo *models.Repository, gitRepo *gi
                if sig == nil {
                        sig = commit.Committer
                }
-               var author *models.User
+               var author *user_model.User
                var createdAt = time.Unix(1, 0)
 
                if sig != nil {
                        var ok bool
                        author, ok = emailToUser[sig.Email]
                        if !ok {
-                               author, err = models.GetUserByEmailContext(ctx, sig.Email)
-                               if err != nil && !models.IsErrUserNotExist(err) {
+                               author, err = user_model.GetUserByEmailContext(ctx, sig.Email)
+                               if err != nil && !user_model.IsErrUserNotExist(err) {
                                        return fmt.Errorf("GetUserByEmail: %v", err)
                                }
                                if author != nil {
index 1d390247f1aad8990d71c93ce0e18e1e5ab00c91..4929f9f446f8872b8f7c92b56632237c37e43740 100644 (file)
@@ -8,6 +8,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/notification"
        repo_module "code.gitea.io/gitea/modules/repository"
@@ -16,7 +17,7 @@ import (
 )
 
 // CreateRepository creates a repository for the user/organization.
-func CreateRepository(doer, owner *models.User, opts models.CreateRepoOptions) (*models.Repository, error) {
+func CreateRepository(doer, owner *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) {
        repo, err := repo_module.CreateRepository(doer, owner, opts)
        if err != nil {
                // No need to rollback here we should do this in CreateRepository...
@@ -29,7 +30,7 @@ func CreateRepository(doer, owner *models.User, opts models.CreateRepoOptions) (
 }
 
 // DeleteRepository deletes a repository for a user or organization.
-func DeleteRepository(doer *models.User, repo *models.Repository) error {
+func DeleteRepository(doer *user_model.User, repo *models.Repository) error {
        if err := pull_service.CloseRepoBranchesPulls(doer, repo); err != nil {
                log.Error("CloseRepoBranchesPulls failed: %v", err)
        }
@@ -42,7 +43,7 @@ func DeleteRepository(doer *models.User, repo *models.Repository) error {
 }
 
 // PushCreateRepo creates a repository when a new repository is pushed to an appropriate namespace
-func PushCreateRepo(authUser, owner *models.User, repoName string) (*models.Repository, error) {
+func PushCreateRepo(authUser, owner *user_model.User, repoName string) (*models.Repository, error) {
        if !authUser.IsAdmin {
                if owner.IsOrganization() {
                        if ok, err := models.CanCreateOrgRepo(owner.ID, authUser.ID); err != nil {
index bb323c1c0a23bd007d48b921d9221a3f9671f7bc..e6b73fc9e0878693914c541c8f0e8f965065ffff 100644 (file)
@@ -8,6 +8,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/notification"
        "code.gitea.io/gitea/modules/sync"
 )
@@ -16,7 +17,7 @@ import (
 var repoWorkingPool = sync.NewExclusivePool()
 
 // TransferOwnership transfers all corresponding setting from old user to new one.
-func TransferOwnership(doer, newOwner *models.User, repo *models.Repository, teams []*models.Team) error {
+func TransferOwnership(doer, newOwner *user_model.User, repo *models.Repository, teams []*models.Team) error {
        if err := repo.GetOwner(); err != nil {
                return err
        }
@@ -52,7 +53,7 @@ func TransferOwnership(doer, newOwner *models.User, repo *models.Repository, tea
 }
 
 // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
-func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoName string) error {
+func ChangeRepositoryName(doer *user_model.User, repo *models.Repository, newRepoName string) error {
        oldRepoName := repo.Name
 
        // Change repository directory name. We must lock the local copy of the
@@ -73,7 +74,7 @@ func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoNam
 
 // StartRepositoryTransfer transfer a repo from one owner to a new one.
 // it make repository into pending transfer state, if doer can not create repo for new owner.
-func StartRepositoryTransfer(doer, newOwner *models.User, repo *models.Repository, teams []*models.Team) error {
+func StartRepositoryTransfer(doer, newOwner *user_model.User, repo *models.Repository, teams []*models.Team) error {
        if err := models.TestRepositoryReadyForTransfer(repo.Status); err != nil {
                return err
        }
index 09c9829216a33d6e4b3b7938f43f9ca178681e69..866e49c86678a187603838cb567a1834dc0ee13e 100644 (file)
@@ -10,6 +10,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/notification"
        "code.gitea.io/gitea/modules/notification/action"
        "code.gitea.io/gitea/modules/util"
@@ -30,9 +31,9 @@ func TestTransferOwnership(t *testing.T) {
 
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
-       repo.Owner = unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
        assert.NoError(t, TransferOwnership(doer, doer, repo, nil))
 
        transferredRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
@@ -51,16 +52,16 @@ func TestTransferOwnership(t *testing.T) {
                Content:   "user3/repo3",
        })
 
-       unittest.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
+       unittest.CheckConsistencyFor(t, &models.Repository{}, &user_model.User{}, &models.Team{})
 }
 
 func TestStartRepositoryTransferSetPermission(t *testing.T) {
        assert.NoError(t, unittest.PrepareTestDatabase())
 
-       doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
-       recipient := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+       doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
+       recipient := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
-       repo.Owner = unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+       repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
 
        hasAccess, err := models.HasAccess(recipient.ID, repo)
        assert.NoError(t, err)
@@ -72,5 +73,5 @@ func TestStartRepositoryTransferSetPermission(t *testing.T) {
        assert.NoError(t, err)
        assert.True(t, hasAccess)
 
-       unittest.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
+       unittest.CheckConsistencyFor(t, &models.Repository{}, &user_model.User{}, &models.Team{})
 }
index 100aac1967e3bb933fea89d7fad7abe7c552d8af..46ea80b00285c8c169d3261e667389b967b9a747 100644 (file)
@@ -11,6 +11,8 @@ import (
        "strings"
 
        "code.gitea.io/gitea/models"
+       "code.gitea.io/gitea/models/db"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/graceful"
        "code.gitea.io/gitea/modules/json"
        "code.gitea.io/gitea/modules/log"
@@ -23,16 +25,16 @@ import (
        "code.gitea.io/gitea/services/migrations"
 )
 
-func handleCreateError(owner *models.User, err error) error {
+func handleCreateError(owner *user_model.User, err error) error {
        switch {
        case models.IsErrReachLimitOfRepo(err):
                return fmt.Errorf("You have already reached your limit of %d repositories", owner.MaxCreationLimit())
        case models.IsErrRepoAlreadyExist(err):
                return errors.New("The repository name is already used")
-       case models.IsErrNameReserved(err):
-               return fmt.Errorf("The repository name '%s' is reserved", err.(models.ErrNameReserved).Name)
-       case models.IsErrNamePatternNotAllowed(err):
-               return fmt.Errorf("The pattern '%s' is not allowed in a repository name", err.(models.ErrNamePatternNotAllowed).Pattern)
+       case db.IsErrNameReserved(err):
+               return fmt.Errorf("The repository name '%s' is reserved", err.(db.ErrNameReserved).Name)
+       case db.IsErrNamePatternNotAllowed(err):
+               return fmt.Errorf("The pattern '%s' is not allowed in a repository name", err.(db.ErrNamePatternNotAllowed).Pattern)
        default:
                return err
        }
index f538b36efc06bf6e1593ad0ae27745417959b060..350b8206b26818cc9e599bc95d2134ee931fbea5 100644 (file)
@@ -8,6 +8,7 @@ import (
        "fmt"
 
        "code.gitea.io/gitea/models"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/graceful"
        "code.gitea.io/gitea/modules/json"
        "code.gitea.io/gitea/modules/log"
@@ -57,7 +58,7 @@ func handle(data ...queue.Data) {
 }
 
 // MigrateRepository add migration repository to task
-func MigrateRepository(doer, u *models.User, opts base.MigrateOptions) error {
+func MigrateRepository(doer, u *user_model.User, opts base.MigrateOptions) error {
        task, err := CreateMigrateTask(doer, u, opts)
        if err != nil {
                return err
@@ -67,7 +68,7 @@ func MigrateRepository(doer, u *models.User, opts base.MigrateOptions) error {
 }
 
 // CreateMigrateTask creates a migrate task
-func CreateMigrateTask(doer, u *models.User, opts base.MigrateOptions) (*models.Task, error) {
+func CreateMigrateTask(doer, u *user_model.User, opts base.MigrateOptions) (*models.Task, error) {
        // encrypt credentials for persistence
        var err error
        opts.CloneAddrEncrypted, err = secret.EncryptSecret(setting.SecretKey, opts.CloneAddr)
index 0578f70b27f8eecdff5d9982b5f096bd19da530a..6df9eec1316e2afdec7e154fba59ccdce314e673 100644 (file)
@@ -25,7 +25,7 @@ import (
 // DeleteUser completely and permanently deletes everything of a user,
 // but issues/comments/pulls will be kept and shown as someone has been deleted,
 // unless the user is younger than USER_DELETE_WITH_COMMENTS_MAX_DAYS.
-func DeleteUser(u *models.User) error {
+func DeleteUser(u *user_model.User) error {
        if u.IsOrganization() {
                return fmt.Errorf("%s is an organization not a user", u.Name)
        }
@@ -72,7 +72,7 @@ func DeleteUser(u *models.User) error {
 
        // Note: There are something just cannot be roll back,
        //      so just keep error logs of those operations.
-       path := models.UserPath(u.Name)
+       path := user_model.UserPath(u.Name)
        if err := util.RemoveAll(path); err != nil {
                err = fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
                _ = admin_model.CreateNotice(db.DefaultContext, admin_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
@@ -93,7 +93,7 @@ func DeleteUser(u *models.User) error {
 
 // DeleteInactiveUsers deletes all inactive users and email addresses.
 func DeleteInactiveUsers(ctx context.Context, olderThan time.Duration) error {
-       users, err := models.GetInactiveUsers(ctx, olderThan)
+       users, err := user_model.GetInactiveUsers(ctx, olderThan)
        if err != nil {
                return err
        }
@@ -118,7 +118,7 @@ func DeleteInactiveUsers(ctx context.Context, olderThan time.Duration) error {
 }
 
 // UploadAvatar saves custom avatar for user.
-func UploadAvatar(u *models.User, data []byte) error {
+func UploadAvatar(u *user_model.User, data []byte) error {
        m, err := avatar.Prepare(data)
        if err != nil {
                return err
@@ -136,7 +136,7 @@ func UploadAvatar(u *models.User, data []byte) error {
        // Otherwise, if any of the users delete his avatar
        // Other users will lose their avatars too.
        u.Avatar = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
-       if err = models.UpdateUserCols(ctx, u, "use_custom_avatar", "avatar"); err != nil {
+       if err = user_model.UpdateUserCols(ctx, u, "use_custom_avatar", "avatar"); err != nil {
                return fmt.Errorf("updateUser: %v", err)
        }
 
@@ -153,7 +153,7 @@ func UploadAvatar(u *models.User, data []byte) error {
 }
 
 // DeleteAvatar deletes the user's custom avatar.
-func DeleteAvatar(u *models.User) error {
+func DeleteAvatar(u *user_model.User) error {
        aPath := u.CustomAvatarRelativePath()
        log.Trace("DeleteAvatar[%d]: %s", u.ID, aPath)
        if len(u.Avatar) > 0 {
index 9162273fae001a8105128e76714b4e877471db6e..e18b760308d828c4f6cdb600eeb09f97c62fab93 100644 (file)
@@ -11,6 +11,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/setting"
 
        "github.com/stretchr/testify/assert"
@@ -23,7 +24,7 @@ func TestMain(m *testing.M) {
 func TestDeleteUser(t *testing.T) {
        test := func(userID int64) {
                assert.NoError(t, unittest.PrepareTestDatabase())
-               user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User)
+               user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}).(*user_model.User)
 
                ownedRepos := make([]*models.Repository, 0, 10)
                assert.NoError(t, db.GetEngine(db.DefaultContext).Find(&ownedRepos, &models.Repository{OwnerID: userID}))
@@ -43,20 +44,20 @@ func TestDeleteUser(t *testing.T) {
                        }
                }
                assert.NoError(t, DeleteUser(user))
-               unittest.AssertNotExistsBean(t, &models.User{ID: userID})
-               unittest.CheckConsistencyFor(t, &models.User{}, &models.Repository{})
+               unittest.AssertNotExistsBean(t, &user_model.User{ID: userID})
+               unittest.CheckConsistencyFor(t, &user_model.User{}, &models.Repository{})
        }
        test(2)
        test(4)
        test(8)
        test(11)
 
-       org := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
+       org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
        assert.Error(t, DeleteUser(org))
 }
 
 func TestCreateUser(t *testing.T) {
-       user := &models.User{
+       user := &user_model.User{
                Name:               "GiteaBot",
                Email:              "GiteaBot@gitea.io",
                Passwd:             ";p['////..-++']",
@@ -65,7 +66,7 @@ func TestCreateUser(t *testing.T) {
                MustChangePassword: false,
        }
 
-       assert.NoError(t, models.CreateUser(user))
+       assert.NoError(t, user_model.CreateUser(user))
 
        assert.NoError(t, DeleteUser(user))
 }
@@ -77,11 +78,11 @@ func TestCreateUser_Issue5882(t *testing.T) {
        passwd := ".//.;1;;//.,-=_"
 
        tt := []struct {
-               user               *models.User
+               user               *user_model.User
                disableOrgCreation bool
        }{
-               {&models.User{Name: "GiteaBot", Email: "GiteaBot@gitea.io", Passwd: passwd, MustChangePassword: false}, false},
-               {&models.User{Name: "GiteaBot2", Email: "GiteaBot2@gitea.io", Passwd: passwd, MustChangePassword: false}, true},
+               {&user_model.User{Name: "GiteaBot", Email: "GiteaBot@gitea.io", Passwd: passwd, MustChangePassword: false}, false},
+               {&user_model.User{Name: "GiteaBot2", Email: "GiteaBot2@gitea.io", Passwd: passwd, MustChangePassword: false}, true},
        }
 
        setting.Service.DefaultAllowCreateOrganization = true
@@ -89,9 +90,9 @@ func TestCreateUser_Issue5882(t *testing.T) {
        for _, v := range tt {
                setting.Admin.DisableRegularOrgCreation = v.disableOrgCreation
 
-               assert.NoError(t, models.CreateUser(v.user))
+               assert.NoError(t, user_model.CreateUser(v.user))
 
-               u, err := models.GetUserByEmail(v.user.Email)
+               u, err := user_model.GetUserByEmail(v.user.Email)
                assert.NoError(t, err)
 
                assert.Equal(t, !u.AllowCreateOrganization, v.disableOrgCreation)
index 4c8d7dbc53c1ee38f6914ef16e575ed90bb7eab1..8b2344467330e74474117631b142cb7532aa5a37 100644 (file)
@@ -15,6 +15,7 @@ import (
        admin_model "code.gitea.io/gitea/models/admin"
        "code.gitea.io/gitea/models/db"
        "code.gitea.io/gitea/models/unit"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/log"
        repo_module "code.gitea.io/gitea/modules/repository"
@@ -116,7 +117,7 @@ func prepareWikiFileName(gitRepo *git.Repository, wikiName string) (bool, string
 }
 
 // updateWikiPage adds a new page to the repository wiki.
-func updateWikiPage(doer *models.User, repo *models.Repository, oldWikiName, newWikiName, content, message string, isNew bool) (err error) {
+func updateWikiPage(doer *user_model.User, repo *models.Repository, oldWikiName, newWikiName, content, message string, isNew bool) (err error) {
        if err = nameAllowed(newWikiName); err != nil {
                return err
        }
@@ -264,18 +265,18 @@ func updateWikiPage(doer *models.User, repo *models.Repository, oldWikiName, new
 }
 
 // AddWikiPage adds a new wiki page with a given wikiPath.
-func AddWikiPage(doer *models.User, repo *models.Repository, wikiName, content, message string) error {
+func AddWikiPage(doer *user_model.User, repo *models.Repository, wikiName, content, message string) error {
        return updateWikiPage(doer, repo, "", wikiName, content, message, true)
 }
 
 // EditWikiPage updates a wiki page identified by its wikiPath,
 // optionally also changing wikiPath.
-func EditWikiPage(doer *models.User, repo *models.Repository, oldWikiName, newWikiName, content, message string) error {
+func EditWikiPage(doer *user_model.User, repo *models.Repository, oldWikiName, newWikiName, content, message string) error {
        return updateWikiPage(doer, repo, oldWikiName, newWikiName, content, message, false)
 }
 
 // DeleteWikiPage deletes a wiki page identified by its path.
-func DeleteWikiPage(doer *models.User, repo *models.Repository, wikiName string) (err error) {
+func DeleteWikiPage(doer *user_model.User, repo *models.Repository, wikiName string) (err error) {
        wikiWorkingPool.CheckIn(fmt.Sprint(repo.ID))
        defer wikiWorkingPool.CheckOut(fmt.Sprint(repo.ID))
 
index ee548d23158cf5b69a87d11adc1eb0a8bb7495d6..5b42dd590f76b8768ef4432d711d223de678ced1 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/models/unittest"
+       user_model "code.gitea.io/gitea/models/user"
        "code.gitea.io/gitea/modules/git"
        "code.gitea.io/gitea/modules/util"
 
@@ -126,7 +127,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
        const wikiContent = "This is the wiki content"
        const commitMsg = "Commit message"
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        for _, wikiName := range []string{
                "Another page",
                "Here's a <tag> and a/slash",
@@ -171,7 +172,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
        const newWikiContent = "This is the new content"
        const commitMsg = "Commit message"
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        for _, newWikiName := range []string{
                "Home", // same name as before
                "New home",
@@ -201,7 +202,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
 func TestRepository_DeleteWikiPage(t *testing.T) {
        unittest.PrepareTestEnv(t)
        repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
-       doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+       doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
        assert.NoError(t, DeleteWikiPage(doer, repo, "Home"))
 
        // Now need to show that the page has been added: