mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-24 10:13:10 +00:00
Move user related model into models/user (#17781)
* Move user related model into models/user * Fix lint for windows * Fix windows lint * Fix windows lint * Move some tests in models * Merge
This commit is contained in:
parent
4e7ca946da
commit
a666829a37
345 changed files with 4230 additions and 3813 deletions
21
cmd/admin.go
21
cmd/admin.go
|
@ -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
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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{})
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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{
|
||||
{
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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})
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)()
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
|
||||
package db
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ErrCancelled represents an error due to context cancellation
|
||||
type ErrCancelled struct {
|
||||
|
|
91
models/db/name.go
Normal file
91
models/db/name.go
Normal file
|
@ -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
|
||||
}
|
30
models/db/search.go
Normal file
30
models/db/search.go
Normal file
|
@ -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"
|
||||
)
|
116
models/error.go
116
models/error.go
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() + ":" +
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue