Coverage for girder/api/v1/group : 97%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # -*- coding: utf-8 -*-
############################################################################### # Copyright 2013 Kitware Inc. # # Licensed under the Apache License, Version 2.0 ( the "License" ); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ###############################################################################
"""API Endpoint for groups."""
""" List or search for groups.
:param params: Request query parameters. :type params: dict :returns: A page of matching Group documents. """
limit=limit, sort=sort)
Description('Search for groups or list all groups.') .param('text', "Pass this to perform a full-text search for groups.", required=False) .param('limit', "Result set size limit (default=50).", required=False, dataType='int') .param('offset', "Offset into result set (default=0).", required=False, dataType='int') .param('sort', "Field to sort the group list by (default=name)", required=False) .param('sortdir', "1 for ascending, -1 for descending (default=1)", required=False, dataType='int') .errorResponse())
""" Create a new group.
:param params: Request query parameters. :type params: dict :returns: The created group document. """
name=name, creator=user, description=description, public=public)
Description('Create a new group.') .responseClass('Group') .notes('Must be logged in.') .param('name', 'Unique name for the group.') .param('description', 'Description of the group.', required=False) .param('public', """Whether the group should be public or private. The default is private.""", required=False, dataType='boolean') .errorResponse() .errorResponse('Write access was denied on the parent', 403))
def getGroup(self, group, params): Description('Get a group by ID.') .responseClass('Group') .param('id', 'The ID of the group.', paramType='path') .errorResponse('ID was invalid.') .errorResponse('Read access was denied for the group.', 403))
def getGroupAccess(self, group, params): user = self.getCurrentUser() return self.model('group').filter(group, user, accessList=True, requests=True) Description('Get the access control list for a group.') .responseClass('Group') .param('id', 'The ID of the group.', paramType='path') .errorResponse('ID was invalid.') .errorResponse('Read access was denied for the group.', 403))
def getGroupInvitations(self, group, params): Description('Show outstanding invitations for a group.') .responseClass('Group') .param('id', 'The ID of the group.', paramType='path') .param('limit', "Result set size limit (default=50).", required=False, dataType='int') .param('offset', "Offset into result set (default=0).", required=False, dataType='int') .param('sort', "Field to sort the invitee list by (default=lastName)", required=False) .param('sortdir', "1 for ascending, -1 for descending (default=1)", required=False, dataType='int') .errorResponse() .errorResponse('Read access was denied for the group.', 403))
def updateGroup(self, group, params):
'description', group['description']).strip()
Description('Update a group by ID.') .param('id', 'The ID of the group.', paramType='path') .param('name', 'The name to set on the group.', required=False) .param('description', 'Description for the group.', required=False) .param('public', 'Whether the group should be publicly visible', dataType='boolean', required=False) .errorResponse() .errorResponse('Write access was denied for the group.', 403))
def joinGroup(self, group, params): """ Accept a group invitation. If you have not been invited, this will instead request an invitation.
:param group: The group to join. :type group: dict :param user: The current user. :type user: dict :returns: The updated group document. """ requests=True) Description('Request to join a group, or accept an invitation to join.') .responseClass('Group') .param('id', 'The ID of the group.', paramType='path') .errorResponse('ID was invalid.') .errorResponse('You were not invited to this group, or do not have ' 'read access to it.', 403))
def listMembers(self, group, params): """ Paginated member list of group members.
:returns: A page of User documents representing members of the group. """
group, offset=offset, limit=limit, sort=sort)] Description('List members of a group.') .param('id', 'The ID of the group.', paramType='path') .param('limit', "Result set size limit (default=50).", required=False, dataType='int') .param('offset', "Offset into result set (default=0).", required=False, dataType='int') .param('sort', "Field to sort the member list by (default=lastName)", required=False) .param('sortdir', "1 for ascending, -1 for descending (default=1)", required=False, dataType='int') .errorResponse('ID was invalid.') .errorResponse('Read access was denied for the group.', 403))
def inviteToGroup(self, group, params): """Invite the user to join the group."""
id=params['userId'], user=user, level=AccessType.READ, exc=True)
# Can only invite into access levels that you yourself have
'userToInvite': userToInvite, 'user': user, 'group': group }) to=userToInvite['email'], text=html, subject="Girder: You've been invited to a group")
requests=True) Description("Invite a user to join a group, or accept a user's request " " to join.") .responseClass('Group') .param('id', 'The ID of the group.', paramType='path') .param('userId', 'The ID of the user to invite or accept.') .param('level', 'The access level the user will be given when they ' 'accept the invitation. Defaults to read access (0).', required=False, dataType='int') .param('quiet', 'If you do not wish this action to send an email, ' 'set this parameter to "true".', required=False) .errorResponse() .errorResponse('Write access was denied for the group.', 403))
def promoteToModerator(self, group, params): Description('Promote a member to be a moderator of the group.') .responseClass('Group') .param('id', 'The ID of the group.', paramType='path') .param('userId', 'The ID of the user to promote.') .errorResponse('ID was invalid.') .errorResponse("You don't have permission to promote users.", 403))
def promoteToAdmin(self, group, params): Description('Promote a member to be an administrator of the group.') .responseClass('Group') .param('id', 'The ID of the group.', paramType='path') .param('userId', 'The ID of the user to promote.') .errorResponse('ID was invalid.') .errorResponse("You don't have permission to promote users.", 403))
""" Promote a user to moderator or administrator. :param group: The group to promote within. :param params: Request parameters. :param level: Either WRITE or ADMIN, for moderator or administrator. :type level: AccessType :returns: The updated group document. """
id=params['userId'], user=user, level=AccessType.READ, exc=True)
raise AccessException('That user is not a group member.')
group, userToPromote, level=level, save=True)
def demote(self, group, params): """ Demote a user down to a normal member.
:returns: The updated group document. """
id=params['userId'], user=user, level=AccessType.READ, exc=True)
group, userToDemote, level=AccessType.READ, save=True) requests=True) Description('Demote a user to a normal group member.') .responseClass('Group') .param('id', 'The ID of the group.', paramType='path') .param('userId', 'The ID of the user to demote.') .errorResponse() .errorResponse("You don't have permission to demote users.", 403))
def removeFromGroup(self, group, params): """ Remove a user from a group. Pass a 'userId' key in params to remove a specific user; otherwise will remove this user.
:param group: The group to remove the user from. :type group: dict :param user: The current user (not the user being removed). :type user: dict :param params: Request query parameters. :type params: dict :returns: The updated group document. """
id=params['userId'], user=user, level=AccessType.READ, exc=True) else: # Assume user is removing himself from the group
# If removing someone else, you must have at least as high an # access level as they do, and you must have at least write access # to remove any user other than yourself. AccessType.ADMIN): else:
accessList=True) Description('Remove a user from a group, or uninvite them.') .responseClass('Group') .notes("""If the specified user is not yet a member of the group, this will delete any oustanding invitation or membership request for the user. Passing no userId parameter will assume that the current user is removing himself.""") .param('id', 'The ID of the group.', paramType='path') .param('userId', 'The ID of the user to remove. If not passed, will ' 'remove yourself from the group.', required=False) .errorResponse() .errorResponse("You don't have permission to remove that user.", 403))
def deleteGroup(self, group, params): Description('Delete a group by ID.') .param('id', 'The ID of the group.', paramType='path') .errorResponse('ID was invalid.') .errorResponse('Admin access was denied for the group.', 403)) |