Re: Announcement of a little browser demo of plone.jsonapi.* in action

Ramon Bartl <ramon.bartl-gM/[email protected]>
Newsgroups gmane.comp.web.zope.plone.devel
Message-ID <[email protected]>
Hi Matthew,

> This looks awesome.
> +1 for security review asap
> +1 for moving into core pending security review
> I haven't tried it yet, so I have a couple functionality questions:
> 	• is it good-to-go with Dexterity content types?
> 		• If no Dexterity yet, then +1 for extending it to Dexterity content types...and I will use post-haste
> 	• I didn't see an example for collections...can these be set also?
> Great job...super useful!
> 
> Can't wait to play. 

Thanks a lot:) and good questions.

You can basically add any custom route for Plone 3/4 sites with `plone.jsonapi.core`,
it is as easy as this:

from plone.jsonapi.core import router

@router.add_route("/hello/<string:name>", "hello", methods=["GET"])
def hello(context, request, name="world"):
    return { ... }
        "url": router.url_for("hello", values={"name": name}, force_external=True),
        "hello": name,
    }

Since you get the context and request, you can grab any tool you need
to fetch the informations you want to expose to the user.

The `plone.jsonapi.routes` package is just a *route provider* which specifies
such routes for the standard Plone (AT) content types -- yes, and also for collections:)

It uses the portal catalog to search for the content with the permissions
of the current logged in user, so you only get what you are allowed to see.

If the user requests a detail URL (one with the UID at the end), the object gets waked up
and an adapter (IInfo) provides the dictionary representation of the content type through
Schema introspection.

So basically I'm not bypassing Plone security in any way. You are only allowed to
get/create/update/delete these contents where you have the right permission to do so.

I ported the `plone.jsonapi.routes` package from a Dexterity based Project to be
suitable for Plone AT content types.
So unfortunately you can *not* simply use the CRUD API interface of the routes package:

https://github.com/ramonski/plone.jsonapi.routes/blob/develop/src/plone/jsonapi/routes/api.py 

or to be more precise, the "Create" and "Update" portions of it.

To simply GET the contents informations of Dexterity based CT, simply provide an `IInfo` adapter
and specify a route for them, like so:

from plone.jsonapi.routes import add_plone_route
from plone.jsonapi.routes.api import get_items

@add_plone_route("/mydexteritytype/<string:uid>", "mydexteritytype", methods=["GET"])
def get(context, request, uid=None):
    """ get mydexteritytype
    """
    items = get_items("my.dexterity.type", request, uid=uid, endpoint="mydexteritytype")
    return {
        "url": url_for("mydexteritytype"),
        "count": len(items),
        "items": items,
    }


Have a look into the `providers` module of the package to see how it works:

https://github.com/ramonski/plone.jsonapi.routes/tree/develop/src/plone/jsonapi/routes/providers

Greets Ramon

-- 
Ramon Bartl

ramon.bartl-gM/[email protected]

https://github.com/ramonski

------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk

_______________________________________________
Plone-developers mailing list
Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/plone-developers
signature.asc (application/pgp-signature, 235 B)
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iF4EAREIAAYFAlLstnwACgkQW+yPiOIAg2rwrQEAzHwea/3SBR+poVFeVT/MOqLZ
7hcYpDRVr33usTpOPDMBAOLxjK6dJzNJcSVx5WhWD5tkM3gbmDOUU0LNwCW+sYf6
=qBjL
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.