From b6fc35f63720e88b044c953fd232733243fcbd31 Mon Sep 17 00:00:00 2001 From: "Kim \"BKC\" Carlbäcker" Date: Wed, 15 Feb 2017 00:45:08 +0100 Subject: Implement list/check/delete Repo Collaborator (#3689) --- models/repo_collaboration.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'models') 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 { -- cgit v1.2.3