diff options
author | Unknwon <u@gogs.io> | 2015-08-10 21:47:23 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-08-10 21:47:23 +0800 |
commit | 75aff60c903c2c5ab92d75c9f067d6815f3daa2e (patch) | |
tree | e12104d0fbb25f15c41ee83c6c47acf9841df703 /models/repo.go | |
parent | 09a1b2a1f5ca4c510be2828635a790b2a775ac94 (diff) | |
download | gitea-75aff60c903c2c5ab92d75c9f067d6815f3daa2e.tar.gz gitea-75aff60c903c2c5ab92d75c9f067d6815f3daa2e.zip |
finish create issue with milestone and assignee
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/models/repo.go b/models/repo.go index 7355b5e8d2..1c4f09c4d7 100644 --- a/models/repo.go +++ b/models/repo.go @@ -177,6 +177,43 @@ func (repo *Repository) GetOwner() (err error) { return repo.getOwner(x) } +// GetAssignees returns all users that have write access of repository. +func (repo *Repository) GetAssignees() (_ []*User, err error) { + if err = repo.GetOwner(); err != nil { + return nil, err + } + + accesses := make([]*Access, 0, 10) + if err = x.Where("repo_id=? AND mode>=?", repo.ID, ACCESS_MODE_WRITE).Find(&accesses); err != nil { + return nil, err + } + + users := make([]*User, 0, len(accesses)+1) // Just waste 1 unit does not matter. + if !repo.Owner.IsOrganization() { + users = append(users, repo.Owner) + } + + var u *User + for i := range accesses { + u, err = GetUserByID(accesses[i].UserID) + if err != nil { + return nil, err + } + users = append(users, u) + } + return users, nil +} + +// GetAssigneeByID returns the user that has write access of repository by given ID. +func (repo *Repository) GetAssigneeByID(userID int64) (*User, error) { + return GetAssigneeByID(repo, userID) +} + +// GetMilestoneByID returns the milestone belongs to repository by given ID. +func (repo *Repository) GetMilestoneByID(milestoneID int64) (*Milestone, error) { + return GetRepoMilestoneByID(repo.ID, milestoneID) +} + func (repo *Repository) GetMirror() (err error) { repo.Mirror, err = GetMirror(repo.ID) return err @@ -876,7 +913,7 @@ func DeleteRepository(uid, repoID int64, userName string) error { return err } else if _, err = sess.Delete(&Mirror{RepoID: repoID}); err != nil { return err - } else if _, err = sess.Delete(&IssueUser{RepoId: repoID}); err != nil { + } else if _, err = sess.Delete(&IssueUser{RepoID: repoID}); err != nil { return err } else if _, err = sess.Delete(&Milestone{RepoID: repoID}); err != nil { return err |