Skip to content
Snippets Groups Projects
Commit 3795cd099628 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Implement a rel="search" link for related entities (WIP)

parent e0a092696d39
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
""" """
from cubicweb import neg_role
from cubicweb.appobject import AppObject from cubicweb.appobject import AppObject
from cubicweb.predicates import ( from cubicweb.predicates import (
has_permission, has_permission,
...@@ -188,3 +189,32 @@ ...@@ -188,3 +189,32 @@
ldo['targetSchema']['$ref'] = request.resource_path( ldo['targetSchema']['$ref'] = request.resource_path(
resource, 'schema', query={'role': VIEW_ROLE}) resource, 'schema', query={'role': VIEW_ROLE})
return ldo return ldo
class SearchRelatedLink(EntityLink):
__regid__ = 'jsonschema.search'
__select__ = EntityLink.__select__ & match_kwargs('rtype', 'role')
def description_object(self, resource):
request = resource.request
entity = resource.__parent__.rset.one()
rschema = entity.e_schema.rdef(resource.rtype, resource.role)
target_type = getattr(rschema, neg_role(resource.role))
mapper = self._cw.vreg['mappers'].select(
'jsonschema.entity', self._cw, etype=target_type,
rtype=resource.rtype, role=resource.role,
target_types={entity.cw_etype},
)
search_terms = mapper.json_schema(VIEW_ROLE)['properties']
href = (
request.resource_path(resource)
+ '?searchBy=' + ','.join(
'%s:{%s}' % (p, p) for p in search_terms)
)
return {
'rel': 'search',
'href': href,
'hrefSchema': {
'properties': search_terms,
},
}
...@@ -571,6 +571,18 @@ ...@@ -571,6 +571,18 @@
"submissionSchema": { "submissionSchema": {
"$ref": "/book/.../topics/schema?role=creation" "$ref": "/book/.../topics/schema?role=creation"
} }
},
{
"rel": "search",
"href": "/book/.../topics/?searchBy=name:{name}",
"hrefSchema": {
"properties": {
"name": {
"type": "string",
"title": "name"
}
}
}
} }
] ]
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment