[SlapTool] Add getHateoasUrl method.

parent 7c4da172
......@@ -2789,3 +2789,25 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
finally:
if os.path.exists(self.revoke_computer_certificate_simulator):
os.unlink(self.revoke_computer_certificate_simulator)
def test_getHateoasUrl_NotConfigured(self):
for preference in \
self.portal.portal_catalog(portal_type="System Preference"):
preference = preference.getObject()
if preference.getPreferenceState() == 'global':
preference.setPreferredHateoasUrl('')
self.tic()
self.login(self.person_reference)
self.assertRaises(NotFound, self.portal_slap.getHateoasUrl)
def test_getHateoasUrl(self):
for preference in \
self.portal.portal_catalog(portal_type="System Preference"):
preference = preference.getObject()
if preference.getPreferenceState() == 'global':
preference.setPreferredHateoasUrl('foo')
self.tic()
self.login(self.person_reference)
response = self.portal_slap.getHateoasUrl()
self.assertEqual(200, response.status)
self.assertEqual('foo', response.body)
37
\ No newline at end of file
38
\ No newline at end of file
......@@ -425,6 +425,28 @@ class SlapTool(BaseTool):
for software_release in software_release_list
if software_release.getValidationState() == 'published'])
security.declareProtected(Permissions.AccessContentsInformation,
'getHateoasUrl')
def getHateoasUrl(self):
"""
Return preferred HATEOAS URL.
"""
try:
url = self.getPortalObject().portal_preferences.getPreferredHateoasUrl()
except AttributeError:
raise NotFound
if not url:
raise NotFound
# Keep in cache server for 7 days
self.REQUEST.response.setStatus(200)
self.REQUEST.response.setHeader('Cache-Control',
'public, max-age=1, stale-if-error=604800')
self.REQUEST.response.setHeader('Vary',
'REMOTE_USER')
self.REQUEST.response.setHeader('Last-Modified', rfc1123_date(DateTime()))
self.REQUEST.response.setHeader('content-type', 'text; charset=utf-8')
self.REQUEST.response.setBody(url)
return self.REQUEST.response
####################################################
# Public POST methods
......@@ -774,6 +796,7 @@ class SlapTool(BaseTool):
self.REQUEST.response.setBody(result)
return self.REQUEST.response
####################################################
# Internal methods
####################################################
......
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