Skip to content

Commit 8f65cf8

Browse files
author
Gauvain Pocentek
committed
Merge pull request #1 from dekimsey/team-api
Addded API for team access.
2 parents 05ab473 + cb5b754 commit 8f65cf8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

gitlab.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,20 @@ def User(self, id=None, **kwargs):
385385
"""
386386
return self._getListOrObject(User, id, **kwargs)
387387

388+
def Team(self, id=None, **kwargs):
389+
"""Creates/gets/lists team(s) known by the GitLab server.
390+
391+
If id is None, returns a list of teams.
392+
393+
If id is an integer, returns the matching project (or raise a
394+
GitlabGetError if not found)
395+
396+
If id is a dict, create a new object using attributes provided. The
397+
object is NOT saved on the server. Use the save() method on the object
398+
to write it on the server.
399+
"""
400+
return self._getListOrObject(Team, id, **kwargs)
401+
388402

389403
class GitlabObject(object):
390404
_url = None
@@ -852,3 +866,41 @@ def Tag(self, id=None, **kwargs):
852866
return self._getListOrObject(ProjectTag, id,
853867
project_id=self.id,
854868
**kwargs)
869+
870+
871+
class TeamMember(GitlabObject):
872+
_url = '/user_teams/%(team_id)s/members'
873+
canUpdate = False
874+
requiredCreateAttrs = ['team_id', 'user_id', 'access_level']
875+
requiredDeleteAttrs = ['team_id']
876+
requiredGetAttrs = ['team_id']
877+
requiredListAttrs = ['team_id']
878+
shortPrintAttr = 'username'
879+
880+
881+
class TeamProject(GitlabObject):
882+
_url = '/user_teams/%(team_id)s/projects'
883+
_constructorTypes = {'owner': 'User', 'namespace': 'Group'}
884+
canUpdate = False
885+
requiredCreateAttrs = ['team_id', 'project_id', 'greatest_access_level']
886+
requiredDeleteAttrs = ['team_id', 'project_id']
887+
requiredGetAttrs = ['team_id']
888+
requiredListAttrs = ['team_id']
889+
shortPrintAttr = 'name'
890+
891+
892+
class Team(GitlabObject):
893+
_url = '/user_teams'
894+
shortPrintAttr = 'name'
895+
requiredCreateAttrs = ['name', 'path']
896+
canUpdate = False
897+
898+
def Member(self, id=None, **kwargs):
899+
return self._getListOrObject(TeamMember, id,
900+
team_id=self.id,
901+
**kwargs)
902+
903+
def Project(self, id=None, **kwargs):
904+
return self._getListOrObject(TeamProject, id,
905+
team_id=self.id,
906+
**kwargs)

0 commit comments

Comments
 (0)