Assignee back end
This commit is contained in:
parent
a03f380fa8
commit
e867283406
8 changed files with 96 additions and 46 deletions
|
@ -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)
|
||||
|
|
|
@ -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.Uid = w.UserId
|
||||
iu.IsPoster = iu.Uid == uid
|
||||
iu.IsAssigned = iu.Uid == aid
|
||||
if _, err = orm.Insert(iu); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if isNeedAddPoster {
|
||||
iu.Uid = pid
|
||||
iu.IsPoster = true
|
||||
iu.IsAssigned = iu.Uid == aid
|
||||
if _, err = orm.Insert(iu); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue