summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-10-28 10:11:50 +0800
committerGitHub <noreply@github.com>2019-10-28 10:11:50 +0800
commit495d5e4329326b27158a25b44c37986923d0bb6b (patch)
treefa8474775eb9a1bdb11380ca17a9ca42a991fcb3 /models
parent018b0e818038f3c38cc6bfc96fadeb25c92380e6 (diff)
downloadgitea-495d5e4329326b27158a25b44c37986923d0bb6b.tar.gz
gitea-495d5e4329326b27158a25b44c37986923d0bb6b.zip
Move more issue assignee code from models to issue service (#8690)
* Move more issue assignee code from models to issue service * fix test
Diffstat (limited to 'models')
-rw-r--r--models/issue_assignees.go73
-rw-r--r--models/issue_assignees_test.go9
-rw-r--r--models/repo_permission.go6
3 files changed, 6 insertions, 82 deletions
diff --git a/models/issue_assignees.go b/models/issue_assignees.go
index ed0576b38b..e15b718eb2 100644
--- a/models/issue_assignees.go
+++ b/models/issue_assignees.go
@@ -7,9 +7,6 @@ package models
import (
"fmt"
- "code.gitea.io/gitea/modules/log"
- api "code.gitea.io/gitea/modules/structs"
-
"xorm.io/xorm"
)
@@ -65,31 +62,6 @@ func isUserAssignedToIssue(e Engine, issue *Issue, user *User) (isAssigned bool,
return e.Get(&IssueAssignees{IssueID: issue.ID, AssigneeID: user.ID})
}
-// DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array
-func DeleteNotPassedAssignee(issue *Issue, doer *User, assignees []*User) (err error) {
- var found bool
-
- for _, assignee := range issue.Assignees {
-
- found = false
- for _, alreadyAssignee := range assignees {
- if assignee.ID == alreadyAssignee.ID {
- found = true
- break
- }
- }
-
- if !found {
- // This function also does comments and hooks, which is why we call it seperatly instead of directly removing the assignees here
- if _, _, err := issue.ToggleAssignee(doer, assignee.ID); err != nil {
- return err
- }
- }
- }
-
- return nil
-}
-
// MakeAssigneeList concats a string with all names of the assignees. Useful for logs.
func MakeAssigneeList(issue *Issue) (assigneeList string, err error) {
err = issue.loadAssignees(x)
@@ -131,8 +103,6 @@ func (issue *Issue) ToggleAssignee(doer *User, assigneeID int64) (removed bool,
return false, nil, err
}
- go HookQueue.Add(issue.RepoID)
-
return removed, comment, nil
}
@@ -158,49 +128,6 @@ func (issue *Issue) toggleAssignee(sess *xorm.Session, doer *User, assigneeID in
return removed, comment, err
}
- if issue.IsPull {
- mode, _ := accessLevelUnit(sess, doer, issue.Repo, UnitTypePullRequests)
-
- if err = issue.loadPullRequest(sess); err != nil {
- return false, nil, fmt.Errorf("loadPullRequest: %v", err)
- }
- issue.PullRequest.Issue = issue
- apiPullRequest := &api.PullRequestPayload{
- Index: issue.Index,
- PullRequest: issue.PullRequest.apiFormat(sess),
- Repository: issue.Repo.innerAPIFormat(sess, mode, false),
- Sender: doer.APIFormat(),
- }
- if removed {
- apiPullRequest.Action = api.HookIssueUnassigned
- } else {
- apiPullRequest.Action = api.HookIssueAssigned
- }
- // Assignee comment triggers a webhook
- if err := prepareWebhooks(sess, issue.Repo, HookEventPullRequest, apiPullRequest); err != nil {
- log.Error("PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, removed, err)
- return false, nil, err
- }
- } else {
- mode, _ := accessLevelUnit(sess, doer, issue.Repo, UnitTypeIssues)
-
- apiIssue := &api.IssuePayload{
- Index: issue.Index,
- Issue: issue.apiFormat(sess),
- Repository: issue.Repo.innerAPIFormat(sess, mode, false),
- Sender: doer.APIFormat(),
- }
- if removed {
- apiIssue.Action = api.HookIssueUnassigned
- } else {
- apiIssue.Action = api.HookIssueAssigned
- }
- // Assignee comment triggers a webhook
- if err := prepareWebhooks(sess, issue.Repo, HookEventIssues, apiIssue); err != nil {
- log.Error("PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, removed, err)
- return false, nil, err
- }
- }
return removed, comment, nil
}
diff --git a/models/issue_assignees_test.go b/models/issue_assignees_test.go
index 1c5b5e7a22..163234b167 100644
--- a/models/issue_assignees_test.go
+++ b/models/issue_assignees_test.go
@@ -58,13 +58,4 @@ func TestUpdateAssignee(t *testing.T) {
isAssigned, err = IsUserAssignedToIssue(issue, &User{ID: 4})
assert.NoError(t, err)
assert.False(t, isAssigned)
-
- // Clean everyone
- err = DeleteNotPassedAssignee(issue, user1, []*User{})
- assert.NoError(t, err)
-
- // Check they're gone
- assignees, err = GetAssigneesByIssue(issue)
- assert.NoError(t, err)
- assert.Equal(t, 0, len(assignees))
}
diff --git a/models/repo_permission.go b/models/repo_permission.go
index fad29bd169..782b195629 100644
--- a/models/repo_permission.go
+++ b/models/repo_permission.go
@@ -311,6 +311,12 @@ func AccessLevel(user *User, repo *Repository) (AccessMode, error) {
return accessLevelUnit(x, user, repo, UnitTypeCode)
}
+// AccessLevelUnit returns the Access a user has to a repository's. Will return NoneAccess if the
+// user does not have access.
+func AccessLevelUnit(user *User, repo *Repository, unitType UnitType) (AccessMode, error) {
+ return accessLevelUnit(x, user, repo, unitType)
+}
+
func accessLevelUnit(e Engine, user *User, repo *Repository, unitType UnitType) (AccessMode, error) {
perm, err := getUserRepoPermission(e, repo, user)
if err != nil {