aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-08 12:24:11 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-08 12:24:11 -0400
commite86728340654b18a657a65920c16e28a1b00cca7 (patch)
tree5ef13e753aef6fab75c78fac703945fe0938fd03 /models
parenta03f380fa86f83f35a5636535ec3002100b335bb (diff)
downloadgitea-e86728340654b18a657a65920c16e28a1b00cca7.tar.gz
gitea-e86728340654b18a657a65920c16e28a1b00cca7.zip
Assignee back end
Diffstat (limited to 'models')
-rw-r--r--models/access.go5
-rw-r--r--models/issue.go48
-rw-r--r--models/repo.go21
3 files changed, 49 insertions, 25 deletions
diff --git a/models/access.go b/models/access.go
index 749a2604d5..4f944517ed 100644
--- a/models/access.go
+++ b/models/access.go
@@ -58,9 +58,10 @@ func UpdateAccessWithSession(sess *xorm.Session, access *Access) error {
}
// HasAccess returns true if someone can read or write to given repository.
-func HasAccess(userName, repoName string, mode int) (bool, error) {
+// The repoName should be in format <username>/<reponame>.
+func HasAccess(uname, repoName string, mode int) (bool, error) {
access := &Access{
- UserName: strings.ToLower(userName),
+ UserName: strings.ToLower(uname),
RepoName: strings.ToLower(repoName),
}
has, err := orm.Get(access)
diff --git a/models/issue.go b/models/issue.go
index 14faa5b31f..525e75f2c3 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -28,8 +28,9 @@ type Issue struct {
Poster *User `xorm:"-"`
MilestoneId int64
AssigneeId int64
- IsRead bool `xorm:"-"`
- IsPull bool // Indicates whether is a pull request or not.
+ Assignee *User `xorm:"-"`
+ IsRead bool `xorm:"-"`
+ IsPull bool // Indicates whether is a pull request or not.
IsClosed bool
Labels string `xorm:"TEXT"`
Content string `xorm:"TEXT"`
@@ -46,6 +47,14 @@ func (i *Issue) GetPoster() (err error) {
return err
}
+func (i *Issue) GetAssignee() (err error) {
+ if i.AssigneeId == 0 {
+ return nil
+ }
+ i.Assignee, err = GetUserById(i.AssigneeId)
+ return err
+}
+
// CreateIssue creates new issue for repository.
func NewIssue(issue *Issue) (err error) {
sess := orm.NewSession()
@@ -159,38 +168,35 @@ type IssueUser struct {
}
// NewIssueUserPairs adds new issue-user pairs for new issue of repository.
-func NewIssueUserPairs(rid, iid, oid, uid, aid int64) (err error) {
+func NewIssueUserPairs(rid, iid, oid, pid, aid int64, repoName string) (err error) {
iu := &IssueUser{IssueId: iid, RepoId: rid}
- ws, err := GetWatchers(rid)
+ us, err := GetCollaborators(repoName)
if err != nil {
return err
}
- // TODO: check collaborators.
- // Add owner.
- ids := []int64{oid}
- for _, id := range ids {
- if IsWatching(id, rid) {
- continue
+ isNeedAddPoster := true
+ for _, u := range us {
+ iu.Uid = u.Id
+ iu.IsPoster = iu.Uid == pid
+ if isNeedAddPoster && iu.IsPoster {
+ isNeedAddPoster = false
}
-
- // In case owner is not watching.
- ws = append(ws, &Watch{UserId: id})
- }
-
- for _, w := range ws {
- if w.UserId == 0 {
- continue
+ iu.IsAssigned = iu.Uid == aid
+ if _, err = orm.Insert(iu); err != nil {
+ return err
}
-
- iu.Uid = w.UserId
- iu.IsPoster = iu.Uid == uid
+ }
+ if isNeedAddPoster {
+ iu.Uid = pid
+ iu.IsPoster = true
iu.IsAssigned = iu.Uid == aid
if _, err = orm.Insert(iu); err != nil {
return err
}
}
+
return nil
}
diff --git a/models/repo.go b/models/repo.go
index 595d79b5c3..e97164d26b 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -713,8 +713,8 @@ func GetRepositoryCount(user *User) (int64, error) {
return orm.Count(&Repository{OwnerId: user.Id})
}
-// GetCollaborators returns a list of user name of repository's collaborators.
-func GetCollaborators(repoName string) ([]string, error) {
+// GetCollaboratorNames returns a list of user name of repository's collaborators.
+func GetCollaboratorNames(repoName string) ([]string, error) {
accesses := make([]*Access, 0, 10)
if err := orm.Find(&accesses, &Access{RepoName: strings.ToLower(repoName)}); err != nil {
return nil, err
@@ -727,6 +727,23 @@ func GetCollaborators(repoName string) ([]string, error) {
return names, nil
}
+// GetCollaborators returns a list of users of repository's collaborators.
+func GetCollaborators(repoName string) (us []*User, err error) {
+ accesses := make([]*Access, 0, 10)
+ if err = orm.Find(&accesses, &Access{RepoName: strings.ToLower(repoName)}); err != nil {
+ return nil, err
+ }
+
+ us = make([]*User, len(accesses))
+ for i := range accesses {
+ us[i], err = GetUserByName(accesses[i].UserName)
+ if err != nil {
+ return nil, err
+ }
+ }
+ return us, nil
+}
+
// Watch is connection request for receiving repository notifycation.
type Watch struct {
Id int64