From fba9db1a3e5b9b7c3487eb6bef3b26ae489de9cc Mon Sep 17 00:00:00 2001 From: Rafael Monnerat <rafael@nexedi.com> Date: Thu, 7 Apr 2016 14:49:12 +0000 Subject: [PATCH] slapos_hypermedia: Get News from Software Installation too. --- .../get_hateoas_news.xml | 85 +++++++++++++ .../SoftwareInstallation_getHateoasNews.xml | 114 ++++++++++++++++++ .../bt/template_action_path_list | 3 +- 3 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 master/bt5/slapos_hypermedia/ActionTemplateItem/portal_types/Software%20Installation/get_hateoas_news.xml create mode 100644 master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/SoftwareInstallation_getHateoasNews.xml diff --git a/master/bt5/slapos_hypermedia/ActionTemplateItem/portal_types/Software%20Installation/get_hateoas_news.xml b/master/bt5/slapos_hypermedia/ActionTemplateItem/portal_types/Software%20Installation/get_hateoas_news.xml new file mode 100644 index 000000000..680376577 --- /dev/null +++ b/master/bt5/slapos_hypermedia/ActionTemplateItem/portal_types/Software%20Installation/get_hateoas_news.xml @@ -0,0 +1,85 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ActionInformation" module="Products.CMFCore.ActionInformation"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>action</string> </key> + <value> + <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> + </value> + </item> + <item> + <key> <string>categories</string> </key> + <value> + <tuple> + <string>action_type/object_slap</string> + </tuple> + </value> + </item> + <item> + <key> <string>category</string> </key> + <value> <string>object_slap</string> </value> + </item> + <item> + <key> <string>condition</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>description</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>icon</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>get_hateoas_news</string> </value> + </item> + <item> + <key> <string>permissions</string> </key> + <value> + <tuple> + <string>View</string> + </tuple> + </value> + </item> + <item> + <key> <string>portal_type</string> </key> + <value> <string>Action Information</string> </value> + </item> + <item> + <key> <string>priority</string> </key> + <value> <float>2.0</float> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string>getHateoasNews</string> </value> + </item> + <item> + <key> <string>visible</string> </key> + <value> <int>1</int> </value> + </item> + </dictionary> + </pickle> + </record> + <record id="2" aka="AAAAAAAAAAI="> + <pickle> + <global name="Expression" module="Products.CMFCore.Expression"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>text</string> </key> + <value> <string>string:${object_url}/SoftwareInstallation_getHateoasNews</string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/SoftwareInstallation_getHateoasNews.xml b/master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/SoftwareInstallation_getHateoasNews.xml new file mode 100644 index 000000000..86474053f --- /dev/null +++ b/master/bt5/slapos_hypermedia/SkinTemplateItem/portal_skins/slapos_hypermedia/SoftwareInstallation_getHateoasNews.xml @@ -0,0 +1,114 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="PythonScript" module="Products.PythonScripts.PythonScript"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>Script_magic</string> </key> + <value> <int>3</int> </value> + </item> + <item> + <key> <string>_bind_names</string> </key> + <value> + <object> + <klass> + <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_asgns</string> </key> + <value> + <dictionary> + <item> + <key> <string>name_container</string> </key> + <value> <string>container</string> </value> + </item> + <item> + <key> <string>name_context</string> </key> + <value> <string>context</string> </value> + </item> + <item> + <key> <string>name_m_self</string> </key> + <value> <string>script</string> </value> + </item> + <item> + <key> <string>name_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>_body</string> </key> + <value> <string>from zExceptions import Unauthorized\n +from AccessControl import getSecurityManager\n +if REQUEST is None:\n + raise Unauthorized\n +\n +response = REQUEST.RESPONSE\n +mime_type = \'application/hal+json\'\n +\n +if REQUEST.other[\'method\'] != "GET":\n + response.setStatus(405)\n + return ""\n +elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n + response.setStatus(406)\n + return ""\n +elif context.getPortalType() not in ["Software Installation"]:\n + raise\n + response.setStatus(403)\n + return ""\n +\n +import json\n +\n +memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n + key_prefix=\'slap_tool\',\n + plugin_path=\'portal_memcached/default_memcached_plugin\')\n +try:\n + d = memcached_dict[context.getReference()]\n +except KeyError:\n + d = {\n + "user": "SlapOS Master",\n + "text": "#error no data found for %s" % context.getReference()\n + }\n +else:\n + d = json.loads(d)\n +\n +result_dict = {\n + \'news\': [d],\n + \'_links\': {\n + "self": { "href": context.Base_getRequestUrl() },\n + # XXX current type\n + "index": {\n + "href": "urn:jio:get:%s" % context.getRelativeUrl(),\n + "title": "Software Instance"\n + },\n + },\n +}\n +\n +response.setHeader(\'Content-Type\', mime_type)\n +return json.dumps(result_dict, indent=2)\n +</string> </value> + </item> + <item> + <key> <string>_params</string> </key> + <value> <string>REQUEST=None</string> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>SoftwareInstallation_getHateoasNews</string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/master/bt5/slapos_hypermedia/bt/template_action_path_list b/master/bt5/slapos_hypermedia/bt/template_action_path_list index eb603c1ff..3d99d3dd2 100644 --- a/master/bt5/slapos_hypermedia/bt/template_action_path_list +++ b/master/bt5/slapos_hypermedia/bt/template_action_path_list @@ -6,7 +6,8 @@ Person | get_hateoas_hosting_subscription_list Person | get_hateoas_information Person | request_hateoas_hosting_subscription Software Installation | get_hateoas_information +Software Installation | get_hateoas_news Software Instance | get_hateoas_information Software Instance | get_hateoas_news Software Instance | get_hateoas_related_hosting_subscription -System Preference | slapos_hypermedia_preference +System Preference | slapos_hypermedia_preference \ No newline at end of file -- 2.30.9