def get_one_by_id(self, team_id): """Retrieve information about the given team. :param team_id: Team ID. """ team = teams_api.team_get(team_id) if team: return wmodels.Team.from_db_model(team) else: raise exc.NotFound(_("Team %s not found") % team_id)
def get(self, team_id): """Get users inside a team. :param team_id: An ID of the team. """ team = teams_api.team_get(team_id) if not team: raise exc.NotFound(_("Team %s not found") % team_id) return [wmodels.User.from_db_model(user) for user in team.users]
def get(self, marker=None, offset=None, limit=None, name=None, description=None, sort_field='id', sort_dir='asc'): """Retrieve a list of teams. Example:: curl https://my.example.org/api/v1/teams :param offset: The offset at which to start the page. :param marker: The resource id where the page should begin. :param limit: The number of teams to retrieve. :param name: A string to filter the name by. :param description: A string to filter the description by. :param sort_field: The name of the field to sort on. :param sort_dir: Sort direction for results (asc, desc). """ # Boundary check on limit. if limit is not None: limit = max(0, limit) # Resolve the marker record. marker_team = teams_api.team_get(marker) teams = teams_api.team_get_all(marker=marker_team, offset=offset, limit=limit, name=name, description=description, sort_field=sort_field, sort_dir=sort_dir) team_count = teams_api.team_get_count(name=name, description=description) # Apply the query response headers. if limit: response.headers['X-Limit'] = str(limit) response.headers['X-Total'] = str(team_count) if marker_team: response.headers['X-Marker'] = str(marker_team.id) if offset is not None: response.headers['X-Offset'] = str(offset) return [wmodels.Team.from_db_model(t) for t in teams]
def get(self, team_id): """Get users inside a team. Example:: curl https://my.example.org/api/v1/teams/1/users :param team_id: An ID of the team. """ team = teams_api.team_get(team_id) if not team: raise exc.NotFound(_("Team %s not found") % team_id) users = [api_base._filter_non_public_fields(user, user._public_fields) for user in team.users] return [wmodels.User.from_db_model(user) for user in users]
def create_permission(story, users, teams, session=None): story = api_base.model_query(models.Story, session) \ .options(subqueryload(models.Story.tags)) \ .filter_by(id=story.id).first() permission_dict = { 'name': 'view_story_%d' % story.id, 'codename': 'view_story' } permission = api_base.entity_create(models.Permission, permission_dict) story.permissions.append(permission) if users is not None: for user in users: user = users_api.user_get(user.id) user.permissions.append(permission) if teams is not None: for team in teams: team = teams_api.team_get(team.id) team.permissions.append(permission) return permission
def get(self, team_id): """Get users inside a team. Example:: curl https://my.example.org/api/v1/teams/1/users :param team_id: An ID of the team. """ team = teams_api.team_get(team_id) if not team: raise exc.NotFound(_("Team %s not found") % team_id) users = [ api_base._filter_non_public_fields(user, user._public_fields) for user in team.users ] return [wmodels.User.from_db_model(user) for user in users]
def update_permission(story, users, teams, session=None): story = api_base.model_query(models.Story, session) \ .options(subqueryload(models.Story.tags)) \ .filter_by(id=story.id).first() if not story.permissions: raise exc.NotFound(_("Permissions for story %d not found.") % story.id) permission = story.permissions[0] permission_dict = { 'name': permission.name, 'codename': permission.codename } if users is not None: permission_dict['users'] = [ users_api.user_get(user.id) for user in users ] if teams is not None: permission_dict['teams'] = [ teams_api.team_get(team.id) for team in teams ] return api_base.entity_update(models.Permission, permission.id, permission_dict)
def update_permission(story, users, teams, session=None): story = api_base.model_query(models.Story, session) \ .options(subqueryload(models.Story.tags)) \ .filter_by(id=story.id).first() if not story.permissions: raise exc.NotFound(_("Permissions for story %d not found.") % story.id) permission = story.permissions[0] permission_dict = { 'name': permission.name, 'codename': permission.codename } if users is not None: permission_dict['users'] = [users_api.user_get(user.id) for user in users] if teams is not None: permission_dict['teams'] = [teams_api.team_get(team.id) for team in teams] return api_base.entity_update(models.Permission, permission.id, permission_dict)