From 5388d19f8885d3ca2f93c5e07ed58a1b84a87475 Mon Sep 17 00:00:00 2001 From: samcday Date: Thu, 9 May 2013 16:09:56 +1000 Subject: [PATCH 1/2] Basic team support. --- gitlab.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/gitlab.py b/gitlab.py index 11ed95061..c1f2813b0 100644 --- a/gitlab.py +++ b/gitlab.py @@ -345,6 +345,20 @@ def User(self, id=None, **kwargs): """ return self._getListOrObject(User, id, **kwargs) + def Team(self, id=None, **kwargs): + """Creates/gets/lists team(s) known by the GitLab server. + + If id is None, returns a list of teams. + + If id is an integer, returns the matching project (or raise a + GitlabGetError if not found) + + If id is a dict, create a new object using attributes provided. The + object is NOT saved on the server. Use the save() method on the object + to write it on the server. + """ + return self._getListOrObject(Team, id, **kwargs) + class GitlabObject(object): _url = None @@ -705,3 +719,31 @@ def Tag(self, id=None, **kwargs): return self._getListOrObject(ProjectTag, id, project_id=self.id, **kwargs) + + +class TeamMember(GitlabObject): + _url = '/user_teams/%(team_id)d/members' + requiredCreateAttrs = ['user_id', 'access_level'] + canUpdate = False + + +class TeamProject(GitlabObject): + _url = '/user_teams/%(team_id)d/projects' + _constructorTypes = {'owner': 'User', 'namespace': 'Group'} + requiredCreateAttrs = ['project_id', 'greatest_access_level'] + canUpdate = False + + +class Team(GitlabObject): + _url = '/user_teams' + requiredCreateAttrs = ['name', 'path'] + + def Member(self, id=None, **kwargs): + return self._getListOrObject(TeamMember, id, + team_id=self.id, + **kwargs) + + def Project(self, id=None, **kwargs): + return self._getListOrObject(TeamProject, id, + team_id=self.id, + **kwargs) From 8a22958e20a622400daecb288135793544ad01ad Mon Sep 17 00:00:00 2001 From: Daniel Kimsey Date: Tue, 2 Jul 2013 16:15:06 -0400 Subject: [PATCH 2/2] Addded API for team access. --- gitlab.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gitlab.py b/gitlab.py index 71771781a..522bf189c 100644 --- a/gitlab.py +++ b/gitlab.py @@ -852,3 +852,42 @@ def Tag(self, id=None, **kwargs): return self._getListOrObject(ProjectTag, id, project_id=self.id, **kwargs) + + +class TeamMember(GitlabObject): + _url = '/user_teams/%(team_id)s/members' + canUpdate = False + requiredCreateAttrs = ['team_id', 'user_id', 'access_level'] + requiredDeleteAttrs = ['team_id'] + requiredGetAttrs = ['team_id'] + requiredListAttrs = ['team_id'] + shortPrintAttr = 'username' + + +class TeamProject(GitlabObject): + _url = '/user_teams/%(team_id)s/projects' + _constructorTypes = {'owner': 'User'} + canUpdate = False + requiredCreateAttrs = ['team_id', 'project_id', 'greatest_access_level'] + requiredDeleteAttrs = ['team_id', 'project_id'] + requiredGetAttrs = ['team_id'] + requiredListAttrs = ['team_id'] + shortPrintAttr = 'name' + + +class Team(GitlabObject): + _url = '/user_teams' + shortPrintAttr = 'name' + requiredCreateAttrs = ['name', 'path'] + canUpdate = False + + def Members(self, id=None, **kwargs): + return self._getListOrObject(TeamMember, id, + team_id=self.id, + **kwargs) + + def Projects(self, id=None, **kwargs): + return self._getListOrObject(TeamProject, id, + team_id=self.id, + **kwargs) +