diff options
author | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-02-15 00:45:08 +0100 |
---|---|---|
committer | 无闻 <u@gogs.io> | 2017-02-14 18:45:08 -0500 |
commit | b6fc35f63720e88b044c953fd232733243fcbd31 (patch) | |
tree | f74e14cdf4a515cca1fa02bab5e6ecd2d21c84ef /models/repo_collaboration.go | |
parent | e24d62e5831d26ccc7ff55600f8ff5826c8a3afd (diff) |
Implement list/check/delete Repo Collaborator (#3689)
Diffstat (limited to 'models/repo_collaboration.go')
-rw-r--r-- | models/repo_collaboration.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/models/repo_collaboration.go b/models/repo_collaboration.go index f4b23f9e..73ec7ada 100644 --- a/models/repo_collaboration.go +++ b/models/repo_collaboration.go @@ -6,6 +6,8 @@ package models import ( "fmt" + + api "github.com/gogits/go-gogs-client" ) // Collaboration represent the relation between an individual and a repository. @@ -29,6 +31,16 @@ func (c *Collaboration) ModeI18nKey() string { } } +//IsCollaborator returns true if the user is a collaborator +func (repo *Repository) IsCollaborator(uid int64) (bool, error) { + collaboration := &Collaboration{ + RepoID: repo.ID, + UserID: uid, + } + + return x.Get(collaboration) +} + // AddCollaborator adds new collaboration to a repository with default access mode. func (repo *Repository) AddCollaborator(u *User) error { collaboration := &Collaboration{ @@ -77,6 +89,17 @@ type Collaborator struct { Collaboration *Collaboration } +func (c *Collaborator) APIFormat() *api.Collaborator { + return &api.Collaborator{ + User: c.User.APIFormat(), + Permissions: api.Permission{ + Admin: c.Collaboration.Mode >= ACCESS_MODE_ADMIN, + Push: c.Collaboration.Mode >= ACCESS_MODE_WRITE, + Pull: c.Collaboration.Mode >= ACCESS_MODE_READ, + }, + } +} + func (repo *Repository) getCollaborators(e Engine) ([]*Collaborator, error) { collaborations, err := repo.getCollaborations(e) if err != nil { |