Commit 9a47141e authored by Łukasz Nowak's avatar Łukasz Nowak

Use modern technology.

Convert tool into container of various versions of API.
Move API to Document and use portal_components.
parent b7aa466a
......@@ -40,7 +40,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>vifib_rest_api_v1_preference</string> </value>
<value> <string>vifib_rest_api_preference</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
......@@ -60,7 +60,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Vifib Rest API V1</string> </value>
<value> <string>Vifib Rest API</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
......@@ -77,7 +77,7 @@
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/SystemPreference_viewVifibRestAPIV1</string> </value>
<value> <string>string:${object_url}/SystemPreference_viewVifibRestAPI</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -32,7 +32,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>VifibRestAPIV1SystemPreference</string> </value>
<value> <string>VifibRestAPISystemPreference</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
......
......@@ -37,7 +37,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>preferred_rest_api_v1_token_server_url_property</string> </value>
<value> <string>preferred_rest_api_token_server_url_property</string> </value>
</item>
<item>
<key> <string>mode</string> </key>
......
......@@ -35,7 +35,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>vifib_slapos_rest_api_v1</string> </value>
<value> <string>vifib_slapos_rest_api</string> </value>
</item>
<item>
<key> <string>title</string> </key>
......
......@@ -93,7 +93,7 @@
<key> <string>left</string> </key>
<value>
<list>
<string>my_preferred_rest_api_v1_token_server_url</string>
<string>my_preferred_rest_api_token_server_url</string>
</list>
</value>
</item>
......@@ -108,7 +108,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SystemPreference_viewVifibRestAPIV1</string> </value>
<value> <string>SystemPreference_viewVifibRestAPI</string> </value>
</item>
<item>
<key> <string>method</string> </key>
......@@ -116,7 +116,7 @@
</item>
<item>
<key> <string>name</string> </key>
<value> <string>SystemPreference_viewVifibRestAPIV1</string> </value>
<value> <string>SystemPreference_viewVifibRestAPI</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
......@@ -132,7 +132,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Vifib Rest API V1</string> </value>
<value> <string>Vifib Rest API</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
......
......@@ -17,7 +17,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_preferred_rest_api_v1_token_server_url</string> </value>
<value> <string>my_preferred_rest_api_token_server_url</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
......
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Vifib Rest API V1 Tool" module="erp5.portal_type"/>
<global name="Vifib Rest API Tool" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......@@ -33,7 +33,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>portal_vifib_rest_api_v1</string> </value>
<value> <string>portal_vifib_rest_api</string> </value>
</item>
</dictionary>
</pickle>
......
vifib_slapos_core
vifib_slapos_rest_api_tool_portal_type
\ No newline at end of file
Tool and shared code for all versions of API.
\ No newline at end of file
System Preference | vifib_rest_api_preference
\ No newline at end of file
VifibRestAPISystemPreference
\ No newline at end of file
vifib_slapos_rest_api
\ No newline at end of file
portal_vifib_rest_api
\ No newline at end of file
vifib_slapos_rest_api
\ No newline at end of file
......@@ -20,7 +20,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Vifib Rest API V1 Tool</string> </value>
<value> <string>Vifib Rest API Tool</string> </value>
</item>
<item>
<key> <string>init_script</string> </key>
......@@ -40,7 +40,7 @@
</item>
<item>
<key> <string>type_class</string> </key>
<value> <string>VifibRestApiV1Tool</string> </value>
<value> <string>VifibRestApiTool</string> </value>
</item>
<item>
<key> <string>type_interface</string> </key>
......
vifib_slapos_rest_api_tool_portal_type
\ No newline at end of file
......@@ -29,10 +29,8 @@
##############################################################################
from Acquisition import Implicit
from Products.ERP5Type.Tool.BaseTool import BaseTool
from AccessControl import ClassSecurityInfo, getSecurityManager, Unauthorized
from Products.Vifib.VifibMachineAuthenticationPlugin import getUserByLogin
from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type import Permissions
from ComputedAttribute import ComputedAttribute
from zLOG import LOG, ERROR
......@@ -180,7 +178,7 @@ def responseSupport(anonymous=False):
self.REQUEST.response.setHeader('WWW-Authenticate', 'Bearer realm="%s"'%
self.absolute_url())
self.REQUEST.response.setHeader('Location', self.getPortalObject()\
.portal_preferences.getPreferredRestApiV1TokenServerUrl())
.portal_preferences.getPreferredRestApiTokenServerUrl())
return self.REQUEST.response
else:
user_name = self.getPortalObject().portal_membership\
......@@ -508,16 +506,9 @@ class ComputerPublisher(GenericPublisher):
return self.REQUEST.response
class VifibRestApiV1Tool(BaseTool):
"""SlapOS REST API V1 Tool"""
id = 'portal_vifib_rest_api_v1'
meta_type = 'ERP5 Vifib Rest API V1 Tool'
portal_type = 'Vifib Rest API V1 Tool'
class VifibRestAPIV1(Implicit):
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
allowed_types = ()
security.declarePublic('instance')
@ComputedAttribute
def instance(self):
......@@ -530,23 +521,6 @@ class VifibRestApiV1Tool(BaseTool):
"""Computer publisher"""
return ComputerPublisher().__of__(self)
security.declarePrivate('manage_afterAdd')
def manage_afterAdd(self, item, container) :
"""Init permissions right after creation.
Permissions in slap tool are simple:
o Each member can access the tool.
o Only manager can view and create.
o Anonymous can not access
"""
item.manage_permission(Permissions.AddPortalContent,
['Manager'])
item.manage_permission(Permissions.AccessContentsInformation,
['Member', 'Manager'])
item.manage_permission(Permissions.View,
['Manager',])
BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container)
# set this date to moment of API modification
api_modification_date = DateTime('2012/05/24 10:00 GMT+2')
......@@ -648,5 +622,3 @@ class VifibRestApiV1Tool(BaseTool):
return self.__api_discovery()
self.REQUEST.response.setStatus(400)
return self.REQUEST.response
InitializeClass(VifibRestApiV1Tool)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Document Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>VifibRestAPIV1</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>VifibRestAPIV1</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Document Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
vifib_slapos_core
vifib_slapos_rest_api_v1_portal_type
\ No newline at end of file
vifib_slapos_rest_api
\ No newline at end of file
Restful API V1 for Vifib
\ No newline at end of file
Version 1 of REST API.
\ No newline at end of file
8
\ No newline at end of file
9
\ No newline at end of file
System Preference | vifib_rest_api_v1_preference
\ No newline at end of file
VifibRestAPIV1SystemPreference
\ No newline at end of file
vifib_slapos_rest_api_v1
\ No newline at end of file
portal_vifib_rest_api_v1
\ No newline at end of file
vifib_slapos_rest_api_v1_portal_type
\ No newline at end of file
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2012 Nexedi SA and Contributors. All Rights Reserved.
# Łukasz Nowak <luke@nexedi.com>
# Romain Courteaud <romain@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Products.ERP5Type.Tool.BaseTool import BaseTool
from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type import Permissions
from ComputedAttribute import ComputedAttribute
class VifibRestApiTool(BaseTool):
"""SlapOS REST API Tool
This is container for multiple versions of API.
"""
id = 'portal_vifib_rest_api'
meta_type = 'ERP5 Vifib Rest API Tool'
portal_type = 'Vifib Rest API Tool'
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
allowed_types = ()
security.declarePublic('v1')
@ComputedAttribute
def v1(self):
"""API hooked"""
# XXX: It could be done better (more dynamic, configurable from UI)
try:
from erp5.component.document.VifibRestAPIV1 import VifibRestAPIV1
except ImportError:
return ''
else:
return VifibRestAPIV1().__of__(self)
security.declarePrivate('manage_afterAdd')
def manage_afterAdd(self, item, container) :
"""Init permissions right after creation.
Permissions in slap tool are simple:
o Each member can access the tool.
o Only manager can view and create.
o Anonymous can not access
"""
item.manage_permission(Permissions.AddPortalContent,
['Manager'])
item.manage_permission(Permissions.AccessContentsInformation,
['Member', 'Manager'])
item.manage_permission(Permissions.View,
['Manager',])
BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container)
InitializeClass(VifibRestApiTool)
......@@ -37,8 +37,8 @@ document_classes = updateGlobals(this_module, globals(),
object_classes = ()
content_classes = ()
content_constructors = ()
from Tool import SlapTool, VifibRestApiV1Tool
portal_tools = ( SlapTool.SlapTool, VifibRestApiV1Tool.VifibRestApiV1Tool)
from Tool import SlapTool, VifibRestApiTool
portal_tools = ( SlapTool.SlapTool, VifibRestApiTool.VifibRestApiTool)
from Products.PluggableAuthService.PluggableAuthService import registerMultiPlugin
import VifibMachineAuthenticationPlugin
......
......@@ -98,7 +98,8 @@ class testVifibMixin(ERP5TypeTestCase):
'erp5_ui_test',
'vifib_slapos_core',
'vifib_slapos_core_test',
'vifib_slapos_rest_api_v1_portal_type',
'vifib_slapos_rest_api_tool_portal_type',
'vifib_slapos_rest_api',
'vifib_slapos_rest_api_v1',
'vifib_slapos_accounting',
'vifib_mysql_innodb_catalog',
......
......@@ -123,7 +123,7 @@ vifib_open_trade
vifib_payzen
vifib_simulation
vifib_slap
vifib_slapos_rest_api_v1
vifib_slapos_rest_api
vifib_software_pdm
vifib_test
vifib_web
......@@ -223,7 +223,7 @@ vifib_open_trade
vifib_payzen
vifib_simulation
vifib_slap
vifib_slapos_rest_api_v1
vifib_slapos_rest_api
vifib_software_pdm
vifib_test
vifib_web
......@@ -325,7 +325,7 @@ vifib_open_trade
vifib_payzen
vifib_simulation
vifib_slap
vifib_slapos_rest_api_v1
vifib_slapos_rest_api
vifib_software_pdm
vifib_test
vifib_web
......@@ -422,7 +422,7 @@ vifib_open_trade
vifib_payzen
vifib_simulation
vifib_slap
vifib_slapos_rest_api_v1
vifib_slapos_rest_api
vifib_software_pdm
vifib_test
vifib_web_ui_test
......@@ -516,7 +516,7 @@ vifib_open_trade
vifib_payzen
vifib_simulation
vifib_slap
vifib_slapos_rest_api_v1
vifib_slapos_rest_api
vifib_software_pdm
vifib_test
vifib_web_ui_test
......@@ -610,7 +610,7 @@ vifib_open_trade
vifib_payzen
vifib_simulation
vifib_slap
vifib_slapos_rest_api_v1
vifib_slapos_rest_api
vifib_software_pdm
vifib_test
vifib_web
......@@ -708,7 +708,7 @@ vifib_open_trade
vifib_payzen
vifib_simulation
vifib_slap
vifib_slapos_rest_api_v1
vifib_slapos_rest_api
vifib_software_pdm
vifib_test
vifib_web_ui_test
......@@ -805,7 +805,7 @@ vifib_open_trade
vifib_payzen
vifib_simulation
vifib_slap
vifib_slapos_rest_api_v1
vifib_slapos_rest_api
vifib_software_pdm
vifib_test
vifib_web_ui_test
......@@ -899,7 +899,7 @@ vifib_open_trade
vifib_payzen
vifib_simulation
vifib_slap
vifib_slapos_rest_api_v1
vifib_slapos_rest_api
vifib_software_pdm
vifib_test
vifib_web_ui_test
......@@ -992,7 +992,7 @@ vifib_open_trade
vifib_payzen
vifib_simulation
vifib_slap
vifib_slapos_rest_api_v1
vifib_slapos_rest_api
vifib_software_pdm
vifib_test
vifib_web_ui_test
......
......@@ -6,8 +6,9 @@ class VIFIB(SavedTestSuite, ProjectTestSuite):
_bt_list = [
'vifib_slapos_core',
'vifib_slapos_core_test',
'vifib_slapos_rest_api',
'vifib_slapos_rest_api_v1',
'vifib_slapos_rest_api_v1_portal_type',
'vifib_slapos_rest_api_tool_portal_type',
'vifib_slapos_rest_api_v1_test',
'vifib_base',
'vifib_core',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment