Link the org api calls to their related user resources.

This commit is contained in:
jakedt 2014-03-14 17:35:52 -04:00
parent 4d551a079b
commit 83bc965556
8 changed files with 36 additions and 25 deletions

View file

@ -58,7 +58,7 @@ def method_metadata(func, name):
nickname = partial(add_method_metadata, 'nickname')
internal_api = add_method_metadata('internal_api', True)
related_user_resource = partial(add_method_metadata, 'related_user_resource')
def query_param(name, help_str, type=reqparse.text_type, default=None,

View file

@ -4,7 +4,8 @@ import stripe
from flask import request
from flask.ext.restful import abort
from endpoints.api import resource, nickname, ApiResource, validate_json_request, log_action
from endpoints.api import (resource, nickname, ApiResource, validate_json_request, log_action,
related_user_resource)
from endpoints.api.subscribe import subscribe, subscription_view
from auth.permissions import AdministerOrganizationPermission
from auth.auth_context import get_authenticated_user
@ -126,6 +127,7 @@ class UserCard(ApiResource):
@resource('/v1/organization/<orgname>/card')
@related_user_resource(UserCard)
class OrganizationCard(ApiResource):
""" Resource for managing an organization's credit card. """
schemas = {
@ -145,7 +147,6 @@ class OrganizationCard(ApiResource):
}
@nickname('getOrgCard')
# @org_api_call('getOrgCard')
def get(self, orgname):
""" Get the organization's credit card. """
permission = AdministerOrganizationPermission(orgname)
@ -156,7 +157,6 @@ class OrganizationCard(ApiResource):
abort(403)
@nickname('setOrgCard')
# @org_api_call('set_user_card')
@validate_json_request('OrgCard')
def post(self, orgname):
""" Update the orgnaization's credit card. """
@ -223,6 +223,7 @@ class UserPlan(ApiResource):
@resource('/v1/organization/<orgname>/plan')
@related_user_resource(UserPlan)
class OrganizationPlan(ApiResource):
""" Resource for managing a org's subscription. """
schemas = {
@ -246,7 +247,6 @@ class OrganizationPlan(ApiResource):
}
@nickname('updateOrgSubscription')
# @org_api_call('update_user_subscription')
@validate_json_request('OrgSubscription')
def put(self, orgname):
""" Create or update the org's subscription. """
@ -261,7 +261,6 @@ class OrganizationPlan(ApiResource):
abort(403)
@nickname('getOrgSubscription')
# @org_api_call('get_user_subscription')
def get(self, orgname):
""" Fetch any existing subscription for the org. """
permission = AdministerOrganizationPermission(orgname)
@ -296,10 +295,10 @@ class UserInvoiceList(ApiResource):
@resource('/v1/organization/<orgname>/invoices')
@related_user_resource(UserInvoiceList)
class OrgnaizationInvoiceList(ApiResource):
""" Resource for listing an orgnaization's invoices. """
@nickname('listOrgInvoices')
# @org_api_call('list_user_invoices')
def get(self, orgname):
""" List the invoices for the specified orgnaization. """
permission = AdministerOrganizationPermission(orgname)

View file

@ -23,6 +23,11 @@ TYPE_CONVERTER = {
}
def fully_qualified_name(method_view_class):
inst = method_view_class()
return '%s.%s' % (inst.__module__, inst.__class__.__name__)
def swagger_route_data():
apis = []
models = {}
@ -47,7 +52,9 @@ def swagger_route_data():
'required': True,
})
if method is not None:
if method is None:
logger.debug('Unable to find method for %s in class %s', method_name, view_class)
else:
req_schema_name = method_metadata(method, 'request_schema')
if req_schema_name:
parameters.append({
@ -93,11 +100,17 @@ def swagger_route_data():
operations.append(new_operation)
swagger_path = PARAM_REGEX.sub(r'{\2}', rule.rule)
apis.append({
new_resource = {
'path': swagger_path,
'description': view_class.__doc__ if view_class.__doc__ else "",
'operations': operations,
})
'name': fully_qualified_name(view_class),
}
related_user_res = method_metadata(view_class, 'related_user_resource')
if related_user_res is not None:
new_resource['related'] = fully_qualified_name(related_user_res)
apis.append(new_resource)
swagger_data = {
'apiVersion': 'v1',

View file

@ -4,7 +4,7 @@ from datetime import datetime, timedelta
from flask.ext.restful import abort
from endpoints.api import (resource, nickname, ApiResource, query_param, parse_args,
RepositoryParamResource, require_repo_admin)
RepositoryParamResource, require_repo_admin, related_user_resource)
from auth.permissions import AdministerOrganizationPermission, AdministerOrganizationPermission
from auth.auth_context import get_authenticated_user
from data import model
@ -82,6 +82,7 @@ class RepositoryLogs(RepositoryParamResource):
@resource('/v1/organization/<orgname>/logs')
@related_user_resource(UserLogs)
class OrgLogs(ApiResource):
""" Resource for fetching logs for the entire organization. """
@nickname('listOrgLogs')
@ -89,7 +90,6 @@ class OrgLogs(ApiResource):
@query_param('starttime', 'Earliest time from which to get logs. (%m/%d/%Y %Z)', type=str)
@query_param('endtime', 'Latest time to which to get logs. (%m/%d/%Y %Z)', type=str)
@query_param('performer', 'Username for which to filter logs.', type=str)
# @org_api_call('list_user_logs')
def get(self, args, orgname):
""" List the logs for the specified organization. """
permission = AdministerOrganizationPermission(orgname)

View file

@ -4,8 +4,10 @@ import stripe
from flask import request
from flask.ext.restful import abort
from endpoints.api import resource, nickname, ApiResource, validate_json_request, request_error
from endpoints.api import (resource, nickname, ApiResource, validate_json_request, request_error,
related_user_resource)
from endpoints.api.team import team_view
from endpoints.api.user import User, PrivateRepositories
from auth.permissions import (AdministerOrganizationPermission, OrganizationMemberPermission,
CreateRepositoryPermission)
from auth.auth_context import get_authenticated_user
@ -35,7 +37,7 @@ def org_view(o, teams):
return view
@resource('/v1/organization/', methods=['POST'])
@resource('/v1/organization/')
class OrganizationList(ApiResource):
""" Resource for creating organizations. """
schemas = {
@ -88,7 +90,8 @@ class OrganizationList(ApiResource):
return request_error(exception=ex)
@resource('/v1/organization/<orgname>', methods=['GET'])
@resource('/v1/organization/<orgname>')
@related_user_resource(User)
class Organization(ApiResource):
""" Resource for managing organizations. """
schemas = {
@ -124,7 +127,6 @@ class Organization(ApiResource):
abort(403)
# @org_api_call('change_user_details')
@nickname('changeOrganizationDetails')
@validate_json_request('UpdateOrg')
def put(self, orgname):
@ -152,9 +154,9 @@ class Organization(ApiResource):
@resource('/v1/organization/<orgname>/private')
@related_user_resource(PrivateRepositories)
class OrgPrivateRepositories(ApiResource):
""" Custom verb to compute whether additional private repositories are available. """
# @org_api_call('get_user_private_allowed')
@nickname('getOrganizationPrivateAllowed')
def get(self, orgname):
""" Return whether or not this org is allowed to create new private repositories. """

View file

@ -79,8 +79,7 @@ class RepositoryUserPermissionList(RepositoryParamResource):
}
@resource('/v1/repository/<path:repository>/permissions/user/<username>',
methods=['GET'])
@resource('/v1/repository/<path:repository>/permissions/user/<username>')
class RepositoryUserPermission(RepositoryParamResource):
""" Resource for managing individual user permissions. """
schemas = {

View file

@ -1,6 +1,6 @@
from flask.ext.restful import abort
from endpoints.api import resource, nickname, ApiResource, log_action
from endpoints.api import resource, nickname, ApiResource, log_action, related_user_resource
from auth.permissions import AdministerOrganizationPermission, OrganizationMemberPermission
from auth.auth_context import get_authenticated_user
from data import model
@ -50,10 +50,10 @@ class UserRobot(ApiResource):
@resource('/v1/organization/<orgname>/robots')
@related_user_resource(UserRobotList)
class OrgRobotList(ApiResource):
""" Resource for listing an organization's robots. """
@nickname('getOrgRobots')
#@org_api_call('get_user_robots')
def get(self, orgname):
""" List the organization's robots. """
permission = OrganizationMemberPermission(orgname)
@ -67,10 +67,10 @@ class OrgRobotList(ApiResource):
@resource('/v1/organization/<orgname>/robots/<robot_shortname>')
@related_user_resource(UserRobot)
class OrgRobot(ApiResource):
""" Resource for managing an organization's robots. """
@nickname('createOrgRobot')
#@org_api_call('create_user_robot')
def put(self, orgname, robot_shortname):
""" Create a new robot in the organization. """
permission = AdministerOrganizationPermission(orgname)
@ -85,7 +85,6 @@ class OrgRobot(ApiResource):
abort(403)
@nickname('deleteOrgRobot')
#@org_api_call('delete_user_robot')
def delete(self, orgname, robot_shortname):
""" Delete an existing organization robot. """
permission = AdministerOrganizationPermission(orgname)

View file

@ -27,8 +27,7 @@ def member_view(member):
}
@resource('/v1/organization/<orgname>/team/<teamname>',
methods=['PUT', 'POST'])
@resource('/v1/organization/<orgname>/team/<teamname>')
class OrganizationTeam(ApiResource):
""" Resource for manging an organization's teams. """
schemas = {