diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-24 17:49:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-24 17:49:20 +0800 |
commit | a666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch) | |
tree | 9ab1434b759a8a2cb275a83149903a823851e309 /services/issue | |
parent | 4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff) | |
download | gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip |
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
Diffstat (limited to 'services/issue')
-rw-r--r-- | services/issue/assignee.go | 15 | ||||
-rw-r--r-- | services/issue/assignee_test.go | 5 | ||||
-rw-r--r-- | services/issue/commit.go | 5 | ||||
-rw-r--r-- | services/issue/commit_test.go | 13 | ||||
-rw-r--r-- | services/issue/content.go | 3 | ||||
-rw-r--r-- | services/issue/issue.go | 15 | ||||
-rw-r--r-- | services/issue/label.go | 11 | ||||
-rw-r--r-- | services/issue/label_test.go | 5 | ||||
-rw-r--r-- | services/issue/milestone.go | 3 | ||||
-rw-r--r-- | services/issue/status.go | 3 |
10 files changed, 44 insertions, 34 deletions
diff --git a/services/issue/assignee.go b/services/issue/assignee.go index 290a0041ff..62d274a65f 100644 --- a/services/issue/assignee.go +++ b/services/issue/assignee.go @@ -7,12 +7,13 @@ package issue import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" ) // DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array -func DeleteNotPassedAssignee(issue *models.Issue, doer *models.User, assignees []*models.User) (err error) { +func DeleteNotPassedAssignee(issue *models.Issue, doer *user_model.User, assignees []*user_model.User) (err error) { var found bool for _, assignee := range issue.Assignees { @@ -37,13 +38,13 @@ func DeleteNotPassedAssignee(issue *models.Issue, doer *models.User, assignees [ } // ToggleAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it. -func ToggleAssignee(issue *models.Issue, doer *models.User, assigneeID int64) (removed bool, comment *models.Comment, err error) { +func ToggleAssignee(issue *models.Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *models.Comment, err error) { removed, comment, err = issue.ToggleAssignee(doer, assigneeID) if err != nil { return } - assignee, err1 := models.GetUserByID(assigneeID) + assignee, err1 := user_model.GetUserByID(assigneeID) if err1 != nil { err = err1 return @@ -55,7 +56,7 @@ func ToggleAssignee(issue *models.Issue, doer *models.User, assigneeID int64) (r } // ReviewRequest add or remove a review request from a user for this PR, and make comment for it. -func ReviewRequest(issue *models.Issue, doer *models.User, reviewer *models.User, isAdd bool) (comment *models.Comment, err error) { +func ReviewRequest(issue *models.Issue, doer *user_model.User, reviewer *user_model.User, isAdd bool) (comment *models.Comment, err error) { if isAdd { comment, err = models.AddReviewRequest(issue, reviewer, doer) } else { @@ -74,7 +75,7 @@ func ReviewRequest(issue *models.Issue, doer *models.User, reviewer *models.User } // IsValidReviewRequest Check permission for ReviewRequest -func IsValidReviewRequest(reviewer, doer *models.User, isAdd bool, issue *models.Issue, permDoer *models.Permission) error { +func IsValidReviewRequest(reviewer, doer *user_model.User, isAdd bool, issue *models.Issue, permDoer *models.Permission) error { if reviewer.IsOrganization() { return models.ErrNotValidReviewRequest{ Reason: "Organization can't be added as reviewer", @@ -172,7 +173,7 @@ func IsValidReviewRequest(reviewer, doer *models.User, isAdd bool, issue *models } // IsValidTeamReviewRequest Check permission for ReviewRequest Team -func IsValidTeamReviewRequest(reviewer *models.Team, doer *models.User, isAdd bool, issue *models.Issue) error { +func IsValidTeamReviewRequest(reviewer *models.Team, doer *user_model.User, isAdd bool, issue *models.Issue) error { if doer.IsOrganization() { return models.ErrNotValidReviewRequest{ Reason: "Organization can't be doer to add reviewer", @@ -227,7 +228,7 @@ func IsValidTeamReviewRequest(reviewer *models.Team, doer *models.User, isAdd bo } // TeamReviewRequest add or remove a review request from a team for this PR, and make comment for it. -func TeamReviewRequest(issue *models.Issue, doer *models.User, reviewer *models.Team, isAdd bool) (comment *models.Comment, err error) { +func TeamReviewRequest(issue *models.Issue, doer *user_model.User, reviewer *models.Team, isAdd bool) (comment *models.Comment, err error) { if isAdd { comment, err = models.AddTeamReviewRequest(issue, reviewer, doer) } else { diff --git a/services/issue/assignee_test.go b/services/issue/assignee_test.go index bc2721ebd4..d3d7ad74f8 100644 --- a/services/issue/assignee_test.go +++ b/services/issue/assignee_test.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "github.com/stretchr/testify/assert" ) @@ -20,7 +21,7 @@ func TestDeleteNotPassedAssignee(t *testing.T) { issue, err := models.GetIssueWithAttrsByID(1) assert.NoError(t, err) - user1, err := models.GetUserByID(1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him + user1, err := user_model.GetUserByID(1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him assert.NoError(t, err) // Check if he got removed @@ -29,7 +30,7 @@ func TestDeleteNotPassedAssignee(t *testing.T) { assert.True(t, isAssigned) // Clean everyone - err = DeleteNotPassedAssignee(issue, user1, []*models.User{}) + err = DeleteNotPassedAssignee(issue, user1, []*user_model.User{}) assert.NoError(t, err) // Check they're gone diff --git a/services/issue/commit.go b/services/issue/commit.go index 401084639d..3e2f6c471b 100644 --- a/services/issue/commit.go +++ b/services/issue/commit.go @@ -14,6 +14,7 @@ import ( "time" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/references" "code.gitea.io/gitea/modules/repository" ) @@ -72,7 +73,7 @@ func timeLogToAmount(str string) int64 { return a } -func issueAddTime(issue *models.Issue, doer *models.User, time time.Time, timeLog string) error { +func issueAddTime(issue *models.Issue, doer *user_model.User, time time.Time, timeLog string) error { amount := timeLogToAmount(timeLog) if amount == 0 { return nil @@ -96,7 +97,7 @@ func getIssueFromRef(repo *models.Repository, index int64) (*models.Issue, error } // UpdateIssuesCommit checks if issues are manipulated by commit message. -func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*repository.PushCommit, branchName string) error { +func UpdateIssuesCommit(doer *user_model.User, repo *models.Repository, commits []*repository.PushCommit, branchName string) error { // Commits are appended in the reverse order. for i := len(commits) - 1; i >= 0; i-- { c := commits[i] diff --git a/services/issue/commit_test.go b/services/issue/commit_test.go index 3f8c5f3b42..1addbd080f 100644 --- a/services/issue/commit_test.go +++ b/services/issue/commit_test.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" @@ -44,7 +45,7 @@ func TestUpdateIssuesCommit(t *testing.T) { }, } - user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) repo.Owner = user @@ -130,7 +131,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) { }, } - user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) repo.Owner = user @@ -144,7 +145,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) { func TestUpdateIssuesCommit_Issue5957(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) // Test that push to a non-default branch closes an issue. pushCommits := []*repository.PushCommit{ @@ -178,7 +179,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) { func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) // Test that a push to default branch closes issue in another repo // If the user also has push permissions to that repo @@ -213,7 +214,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) { func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) // Test that a push to default branch closes issue in another repo // If the user also has push permissions to that repo @@ -248,7 +249,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) { func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 10}).(*models.User) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10}).(*user_model.User) // Test that a push with close reference *can not* close issue // If the committer doesn't have push rights in that repo diff --git a/services/issue/content.go b/services/issue/content.go index 1081e30b5d..6d7883090b 100644 --- a/services/issue/content.go +++ b/services/issue/content.go @@ -6,11 +6,12 @@ package issue import ( "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification" ) // ChangeContent changes issue content, as the given user. -func ChangeContent(issue *models.Issue, doer *models.User, content string) (err error) { +func ChangeContent(issue *models.Issue, doer *user_model.User, content string) (err error) { oldContent := issue.Content if err := issue.ChangeContent(doer, content); err != nil { diff --git a/services/issue/issue.go b/services/issue/issue.go index e3571bd396..cb34a9eacd 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -7,6 +7,7 @@ package issue import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/util" @@ -41,7 +42,7 @@ func NewIssue(repo *models.Repository, issue *models.Issue, labelIDs []int64, uu } // ChangeTitle changes the title of this issue, as the given user. -func ChangeTitle(issue *models.Issue, doer *models.User, title string) (err error) { +func ChangeTitle(issue *models.Issue, doer *user_model.User, title string) (err error) { oldTitle := issue.Title issue.Title = title @@ -55,7 +56,7 @@ func ChangeTitle(issue *models.Issue, doer *models.User, title string) (err erro } // ChangeIssueRef changes the branch of this issue, as the given user. -func ChangeIssueRef(issue *models.Issue, doer *models.User, ref string) error { +func ChangeIssueRef(issue *models.Issue, doer *user_model.User, ref string) error { oldRef := issue.Ref issue.Ref = ref @@ -74,8 +75,8 @@ func ChangeIssueRef(issue *models.Issue, doer *models.User, ref string) error { // "assignees" (array): Logins for Users to assign to this issue. // Pass one or more user logins to replace the set of assignees on this Issue. // Send an empty array ([]) to clear all assignees from the Issue. -func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees []string, doer *models.User) (err error) { - var allNewAssignees []*models.User +func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees []string, doer *user_model.User) (err error) { + var allNewAssignees []*user_model.User // Keep the old assignee thingy for compatibility reasons if oneAssignee != "" { @@ -95,7 +96,7 @@ func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees // Loop through all assignees to add them for _, assigneeName := range multipleAssignees { - assignee, err := models.GetUserByName(assigneeName) + assignee, err := user_model.GetUserByName(assigneeName) if err != nil { return err } @@ -125,8 +126,8 @@ func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees // AddAssigneeIfNotAssigned adds an assignee only if he isn't already assigned to the issue. // Also checks for access of assigned user -func AddAssigneeIfNotAssigned(issue *models.Issue, doer *models.User, assigneeID int64) (err error) { - assignee, err := models.GetUserByID(assigneeID) +func AddAssigneeIfNotAssigned(issue *models.Issue, doer *user_model.User, assigneeID int64) (err error) { + assignee, err := user_model.GetUserByID(assigneeID) if err != nil { return err } diff --git a/services/issue/label.go b/services/issue/label.go index c8ef9e9536..96df7ed345 100644 --- a/services/issue/label.go +++ b/services/issue/label.go @@ -6,11 +6,12 @@ package issue import ( "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification" ) // ClearLabels clears all of an issue's labels -func ClearLabels(issue *models.Issue, doer *models.User) (err error) { +func ClearLabels(issue *models.Issue, doer *user_model.User) (err error) { if err = issue.ClearLabels(doer); err != nil { return } @@ -21,7 +22,7 @@ func ClearLabels(issue *models.Issue, doer *models.User) (err error) { } // AddLabel adds a new label to the issue. -func AddLabel(issue *models.Issue, doer *models.User, label *models.Label) error { +func AddLabel(issue *models.Issue, doer *user_model.User, label *models.Label) error { if err := models.NewIssueLabel(issue, label, doer); err != nil { return err } @@ -31,7 +32,7 @@ func AddLabel(issue *models.Issue, doer *models.User, label *models.Label) error } // AddLabels adds a list of new labels to the issue. -func AddLabels(issue *models.Issue, doer *models.User, labels []*models.Label) error { +func AddLabels(issue *models.Issue, doer *user_model.User, labels []*models.Label) error { if err := models.NewIssueLabels(issue, labels, doer); err != nil { return err } @@ -41,7 +42,7 @@ func AddLabels(issue *models.Issue, doer *models.User, labels []*models.Label) e } // RemoveLabel removes a label from issue by given ID. -func RemoveLabel(issue *models.Issue, doer *models.User, label *models.Label) error { +func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label) error { if err := issue.LoadRepo(); err != nil { return err } @@ -66,7 +67,7 @@ func RemoveLabel(issue *models.Issue, doer *models.User, label *models.Label) er } // ReplaceLabels removes all current labels and add new labels to the issue. -func ReplaceLabels(issue *models.Issue, doer *models.User, labels []*models.Label) error { +func ReplaceLabels(issue *models.Issue, doer *user_model.User, labels []*models.Label) error { old, err := models.GetLabelsByIssueID(issue.ID) if err != nil { return err diff --git a/services/issue/label_test.go b/services/issue/label_test.go index fdc2c4ffb6..fc94749bdb 100644 --- a/services/issue/label_test.go +++ b/services/issue/label_test.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "github.com/stretchr/testify/assert" ) @@ -31,7 +32,7 @@ func TestIssue_AddLabels(t *testing.T) { for i, labelID := range test.labelIDs { labels[i] = unittest.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label) } - doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User) + doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID}).(*user_model.User) assert.NoError(t, AddLabels(issue, doer, labels)) for _, labelID := range test.labelIDs { unittest.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID}) @@ -54,7 +55,7 @@ func TestIssue_AddLabel(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue) label := unittest.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label) - doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User) + doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID}).(*user_model.User) assert.NoError(t, AddLabel(issue, doer, label)) unittest.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID}) } diff --git a/services/issue/milestone.go b/services/issue/milestone.go index 6fe527f58c..999da50844 100644 --- a/services/issue/milestone.go +++ b/services/issue/milestone.go @@ -6,11 +6,12 @@ package issue import ( "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification" ) // ChangeMilestoneAssign changes assignment of milestone for issue. -func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneID int64) (err error) { +func ChangeMilestoneAssign(issue *models.Issue, doer *user_model.User, oldMilestoneID int64) (err error) { if err = models.ChangeMilestoneAssign(issue, doer, oldMilestoneID); err != nil { return } diff --git a/services/issue/status.go b/services/issue/status.go index 0a18169a27..5b8d21274d 100644 --- a/services/issue/status.go +++ b/services/issue/status.go @@ -7,11 +7,12 @@ package issue import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification" ) // ChangeStatus changes issue status to open or closed. -func ChangeStatus(issue *models.Issue, doer *models.User, closed bool) error { +func ChangeStatus(issue *models.Issue, doer *user_model.User, closed bool) error { comment, err := issue.ChangeStatus(doer, closed) if err != nil { // Don't return an error when dependencies are open as this would let the push fail |