Skip to content

Commit

Permalink
implement json schema for rest of endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Mar 31, 2017
1 parent f8de8de commit ba8d138
Show file tree
Hide file tree
Showing 21 changed files with 326 additions and 105 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
@@ -1,6 +1,9 @@
1.0.0a4 (unreleased)
--------------------

- rename `subjects` to `tags` for IDublinCore behavior
[vangheem]

- rename permissions:
`guillotina.AddPortal` -> `guillotina.AddContainer`
`guillotina.DeletePortals` -> `guillotina.DeleteContainers`
Expand Down
2 changes: 1 addition & 1 deletion guillotina/api/__init__.py
Expand Up @@ -5,9 +5,9 @@
from . import container # noqa
from . import content # noqa
from . import files # noqa
from . import jsonschema # noqa
from . import registry # noqa
from . import search # noqa
from . import types # noqa
from . import user # noqa
from . import ws # noqa
from guillotina.json import definitions # noqa
12 changes: 6 additions & 6 deletions guillotina/api/addons.py
Expand Up @@ -12,8 +12,8 @@


@configure.service(
context=IContainer, name='@addons', method='POST',
permission='guillotina.ManageAddons',
context=IContainer, method='POST',
permission='guillotina.ManageAddons', name='@addons',
summary='Install addon to container',
parameters=[{
"name": "body",
Expand Down Expand Up @@ -44,8 +44,8 @@ async def install(context, request):


@configure.service(
context=IContainer, name='@addons', method='DELETE',
permission='guillotina.ManageAddons',
context=IContainer, method='DELETE',
permission='guillotina.ManageAddons', name='@addons',
summary='Uninstall an addon from container',
parameters=[{
"name": "body",
Expand Down Expand Up @@ -76,8 +76,8 @@ async def uninstall(context, request):


@configure.service(
context=IContainer, name='@addons', method='GET',
permission='guillotina.ManageAddons',
context=IContainer, method='GET',
permission='guillotina.ManageAddons', name='@addons',
summary='List available addons',
responses={
"200": {
Expand Down
4 changes: 2 additions & 2 deletions guillotina/api/app.py
Expand Up @@ -26,8 +26,8 @@ async def get(context, request):


@configure.service(
context=IApplication, method='GET', permission='guillotina.GetContainers',
name='@apidefinition',
context=IApplication, method='GET',
permission='guillotina.GetContainers', name='@apidefinition',
summary="Get API Definition",
description="Retrieves information on API configuration")
async def get_api_definition(context, request):
Expand Down
12 changes: 6 additions & 6 deletions guillotina/api/behaviors.py
Expand Up @@ -11,8 +11,8 @@


@configure.service(
context=IResource, method='PATCH', permission='guillotina.ModifyContent',
name='@behaviors',
context=IResource, method='PATCH',
permission='guillotina.ModifyContent', name='@behaviors',
summary="Add behavior to resource",
parameters=[{
"name": "body",
Expand All @@ -39,8 +39,8 @@ async def default_patch(context, request):


@configure.service(
context=IResource, method='DELETE', permission='guillotina.ModifyContent',
name='@behaviors',
context=IResource, method='DELETE',
permission='guillotina.ModifyContent', name='@behaviors',
summary="Remove behavior from resource",
parameters=[{
"name": "body",
Expand All @@ -67,8 +67,8 @@ async def default_delete(context, request):


@configure.service(
context=IResource, method='GET', permission='guillotina.AccessContent',
name='@behaviors',
context=IResource, method='GET',
permission='guillotina.AccessContent', name='@behaviors',
summary='Get information on behaviors for this resource',
responses={
"200": {
Expand Down
6 changes: 4 additions & 2 deletions guillotina/api/container.py
Expand Up @@ -139,8 +139,10 @@ class DefaultDELETE(content.DefaultDELETE):
pass


@configure.service(context=IDatabase, method='DELETE', permission='guillotina.UmountDatabase')
@configure.service(context=IApplication, method='PUT', permission='guillotina.MountDatabase')
@configure.service(
context=IDatabase, method='DELETE', permission='guillotina.UmountDatabase', ignore=True)
@configure.service(
context=IApplication, method='PUT', permission='guillotina.MountDatabase', ignore=True)
class NotImplemented(Service):
async def __call__(self):
return ErrorResponse(
Expand Down
45 changes: 31 additions & 14 deletions guillotina/api/content.py
Expand Up @@ -14,6 +14,7 @@
from guillotina.component import getMultiAdapter
from guillotina.component import queryMultiAdapter
from guillotina.content import create_content_in_container
from guillotina.content import get_all_behavior_interfaces
from guillotina.event import notify
from guillotina.events import BeforeObjectRemovedEvent
from guillotina.events import ObjectAddedEvent
Expand All @@ -36,24 +37,40 @@
from guillotina.interfaces import IRolePermissionManager
from guillotina.interfaces import IRolePermissionMap
from guillotina.json.exceptions import DeserializationError
from guillotina.json.utils import convert_interface_to_schema
from guillotina.utils import get_authenticated_user_id
from guillotina.utils import get_class_dotted_name
from guillotina.utils import iter_parents


_zone = tzlocal()


@configure.service(
context=IResource, method='GET', permission='guillotina.ViewContent',
summary="Retrieves serialization of resource",
responses={
def get_content_json_schema_responses(content):
properties = {}
for iface in get_all_behavior_interfaces(content):
properties[get_class_dotted_name(iface)] = {
"type": "object",
"properties": convert_interface_to_schema(iface)
}

return {
"200": {
"description": "Resource data",
"schema": {
"$ref": "#/definitions/Resource"
"allOf": [
{"$ref": "#/definitions/Resource"},
{"properties": properties}
]
}
}
})
}


@configure.service(
context=IResource, method='GET', permission='guillotina.ViewContent',
summary="Retrieves serialization of resource",
responses=get_content_json_schema_responses)
class DefaultGET(Service):
async def __call__(self):
serializer = getMultiAdapter(
Expand Down Expand Up @@ -220,8 +237,8 @@ async def __call__(self):


@configure.service(
context=IResource, method='GET', permission='guillotina.SeePermissions',
name='@sharing',
context=IResource, method='GET',
permission='guillotina.SeePermissions', name='@sharing',
summary='Get sharing settings for this resource',
responses={
"200": {
Expand Down Expand Up @@ -258,8 +275,8 @@ async def sharing_get(context, request):


@configure.service(
context=IResource, method='GET', permission='guillotina.SeePermissions',
name='@all_permissions',
context=IResource, method='GET',
permission='guillotina.SeePermissions', name='@all_permissions',
summary='See all permission settings for this resource',
responses={
"200": {
Expand Down Expand Up @@ -304,8 +321,8 @@ async def all_permissions(context, request):


@configure.service(
context=IResource, method='POST', permission='guillotina.ChangePermissions',
name='@sharing',
context=IResource, method='POST',
permission='guillotina.ChangePermissions', name='@sharing',
summary='Change permissions for a resource',
parameters=[{
"name": "body",
Expand Down Expand Up @@ -371,8 +388,8 @@ async def sharing_post(context, request):


@configure.service(
context=IResource, method='GET', permission='guillotina.AccessContent',
name='@canido',
context=IResource, method='GET',
permission='guillotina.AccessContent', name='@canido',
parameters=[{
"name": "permission",
"in": "query",
Expand Down
12 changes: 6 additions & 6 deletions guillotina/api/registry.py
Expand Up @@ -24,8 +24,8 @@


@configure.service(
context=IContainer, method='GET', permission='guillotina.ReadConfiguration',
name='@registry',
context=IContainer, method='GET',
permission='guillotina.ReadConfiguration', name='@registry',
summary='Read container registry settings',
responses={
"200": {
Expand Down Expand Up @@ -74,8 +74,8 @@ async def __call__(self):


@configure.service(
context=IContainer, method='POST', permission='guillotina.RegisterConfigurations',
name='@registry',
context=IContainer, method='POST',
permission='guillotina.RegisterConfigurations', name='@registry',
summary='Register a new interface to for registry settings',
parameters=[{
"name": "body",
Expand Down Expand Up @@ -132,8 +132,8 @@ async def __call__(self):


@configure.service(
context=IContainer, method='PATCH', permission='guillotina.WriteConfiguration',
name='@registry',
context=IContainer, method='PATCH',
permission='guillotina.WriteConfiguration', name='@registry',
summary='Update registry setting',
parameters={
"name": "body",
Expand Down
84 changes: 72 additions & 12 deletions guillotina/api/search.py
Expand Up @@ -8,8 +8,24 @@
from guillotina.utils import get_content_path


@configure.service(context=IResource, method='GET', permission='guillotina.SearchContent',
name='@search')
@configure.service(
context=IResource, method='GET', permission='guillotina.SearchContent', name='@search',
summary='Make search request',
parameters=[{
"name": "q",
"in": "query",
"required": True,
"type": "string"
}],
responses={
"200": {
"description": "Search results",
"type": "object",
"schema": {
"$ref": "#/definitions/SearchResults"
}
}
})
async def search_get(context, request):
q = request.GET.get('q')
search = queryUtility(ICatalogUtility)
Expand All @@ -25,8 +41,24 @@ async def search_get(context, request):
query=q)


@configure.service(context=IResource, method='POST', permission='guillotina.RawSearchContent',
name='@search')
@configure.service(
context=IResource, method='POST',
permission='guillotina.RawSearchContent', name='@search',
summary='Make a complex search query',
parameters=[{
"name": "body",
"in": "body",
"type": "object"
}],
responses={
"200": {
"description": "Search results",
"type": "object",
"schema": {
"$ref": "#/definitions/SearchResults"
}
}
})
async def search_post(context, request):
q = await request.json()
search = queryUtility(ICatalogUtility)
Expand All @@ -39,8 +71,15 @@ async def search_post(context, request):
return await search.query(context, q)


@configure.service(context=IResource, method='POST', permission='guillotina.ReindexContent',
name='@catalog-reindex')
@configure.service(
context=IResource, method='POST',
permission='guillotina.ReindexContent', name='@catalog-reindex',
summary='Reindex entire container content',
responses={
"200": {
"description": "Successfully reindexed content"
}
})
class CatalogReindex(Service):

def __init__(self, context, request, security=False):
Expand All @@ -53,8 +92,15 @@ async def __call__(self):
return {}


@configure.service(context=IResource, method='POST', permission='guillotina.ReindexContent',
name='@async-catalog-reindex')
@configure.service(
context=IResource, method='POST',
permission='guillotina.ReindexContent', name='@async-catalog-reindex',
summary='Asynchronously reindex entire container content',
responses={
"200": {
"description": "Successfully initiated reindexing"
}
})
class AsyncCatalogReindex(Service):

def __init__(self, context, request, security=False):
Expand All @@ -69,16 +115,30 @@ async def __call__(self):
return {}


@configure.service(context=IResource, method='POST', permission='guillotina.ManageCatalog',
name='@catalog')
@configure.service(
context=IResource, method='POST',
permission='guillotina.ManageCatalog', name='@catalog',
summary='Initialize catalog',
responses={
"200": {
"description": "Successfully initialized catalog"
}
})
async def catalog_post(context, request):
search = queryUtility(ICatalogUtility)
await search.initialize_catalog(context)
return {}


@configure.service(context=IResource, method='DELETE', permission='guillotina.ManageCatalog',
name='@catalog')
@configure.service(
context=IResource, method='DELETE',
permission='guillotina.ManageCatalog', name='@catalog',
summary='Delete search catalog',
responses={
"200": {
"description": "Successfully deleted catalog"
}
})
async def catalog_delete(context, request):
search = queryUtility(ICatalogUtility)
await search.remove_catalog(context)
Expand Down
12 changes: 9 additions & 3 deletions guillotina/api/types.py
Expand Up @@ -10,9 +10,15 @@


@configure.service(
context=IContainer, method='GET', permission='guillotina.AccessContent',
name='@types',
description='Read information on available types')
context=IContainer, method='GET',
permission='guillotina.AccessContent', name='@types',
summary='Read information on available types',
responses={
"200": {
"description": "Result results on types",
"type": "object"
}
})
class Read(TraversableService):

async def publish_traverse(self, traverse):
Expand Down

0 comments on commit ba8d138

Please sign in to comment.