summaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-03-14 20:51:46 -0400
committerLunny Xiao <xiaolunwen@gmail.com>2017-03-15 08:51:46 +0800
commitec0ae5d50c59315a3c597b1cf24d4c5508c718e5 (patch)
tree6f4d6f826dd9866f9b39b66522ec629555700de2 /models/issue.go
parent7d8f9d1c46e38681f2a4033a7da811ab7562d953 (diff)
downloadgitea-ec0ae5d50c59315a3c597b1cf24d4c5508c718e5.tar.gz
gitea-ec0ae5d50c59315a3c597b1cf24d4c5508c718e5.zip
Refactor and fix incorrect comment (#1247)
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go27
1 files changed, 9 insertions, 18 deletions
diff --git a/models/issue.go b/models/issue.go
index c740d8fec4..d5e20eb20a 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -374,7 +374,7 @@ func (issue *Issue) RemoveLabel(doer *User, label *Label) error {
return err
}
- if has, err := HasAccess(doer, issue.Repo, AccessModeWrite); err != nil {
+ if has, err := HasAccess(doer.ID, issue.Repo, AccessModeWrite); err != nil {
return err
} else if !has {
return ErrLabelNotExist{}
@@ -415,7 +415,7 @@ func (issue *Issue) ClearLabels(doer *User) (err error) {
return err
}
- if has, err := hasAccess(sess, doer, issue.Repo, AccessModeWrite); err != nil {
+ if has, err := hasAccess(sess, doer.ID, issue.Repo, AccessModeWrite); err != nil {
return err
} else if !has {
return ErrLabelNotExist{}
@@ -809,23 +809,14 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
}
}
- if opts.Issue.AssigneeID > 0 {
- assignee, err := getUserByID(e, opts.Issue.AssigneeID)
- if err != nil && !IsErrUserNotExist(err) {
- return fmt.Errorf("getUserByID: %v", err)
+ if assigneeID := opts.Issue.AssigneeID; assigneeID > 0 {
+ valid, err := hasAccess(e, assigneeID, opts.Repo, AccessModeWrite)
+ if err != nil {
+ return fmt.Errorf("hasAccess [user_id: %d, repo_id: %d]: %v", assigneeID, opts.Repo.ID, err)
}
-
- // Assume assignee is invalid and drop silently.
- opts.Issue.AssigneeID = 0
- if assignee != nil {
- valid, err := hasAccess(e, assignee, opts.Repo, AccessModeWrite)
- if err != nil {
- return fmt.Errorf("hasAccess [user_id: %d, repo_id: %d]: %v", assignee.ID, opts.Repo.ID, err)
- }
- if valid {
- opts.Issue.AssigneeID = assignee.ID
- opts.Issue.Assignee = assignee
- }
+ if !valid {
+ opts.Issue.AssigneeID = 0
+ opts.Issue.Assignee = nil
}
}