Skip to content

Commit

Permalink
Merge pull request #5324 from 4teamwork/es-5283-fix-restapi-types-end…
Browse files Browse the repository at this point in the history
…point

Fix restapi types endpoint
  • Loading branch information
lukasgraf committed Feb 15, 2019
2 parents 82ba5b4 + b9f333d commit 2a96e4e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Changelog
- Fix changing task to or from private via edit form. [deiferni]
- Fix creating private tasks by mistake. [deiferni]
- Add keywords-filter for dossier listings. [elioschmutz]
- Fix restapi /@types endpiont for all portal-types. [elioschmutz]
- Add simple cache invalidation mechanism for javascript included in templates. [deiferni]
- Fix handling of initial version when saving a document as PDF. [njohner]
- Include agenda item description in TOC json. [deiferni]
Expand Down
33 changes: 33 additions & 0 deletions opengever/api/tests/test_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from ftw.testbrowser import browsing
from opengever.testing import IntegrationTestCase
from plone import api


BLACKLIST = []


class TestPloneRestAPI(IntegrationTestCase):

def whitelisted_portal_type_ids(self):
types_tool = api.portal.get_tool('portal_types')
portal_type_ids = [typeinfo.id for typeinfo in types_tool.listTypeInfo()]
return set(portal_type_ids) - set(BLACKLIST)

@browsing
def test_rest_api(self, browser):
broken_types = []
self.login(self.regular_user, browser)
for portal_type_id in self.whitelisted_portal_type_ids():
try:
# Performing the request within a try-except block will ensure
# that the traceback will be logged and that we can continue
# testing the remaining types.
browser.open(
'{}/@types/{}'.format(self.portal.absolute_url(), portal_type_id),
method='GET', headers={'Accept': 'application/json'})
except:
broken_types.append(portal_type_id)

self.assertEqual(
[], broken_types,
"There was an error on requesting these types")
6 changes: 6 additions & 0 deletions opengever/base/restricted_vocab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from opengever.base.acquisition import acquire_field_value
from Products.CMFCore.interfaces import ISiteRoot
from opengever.base.acquisition import NO_VALUE_FOUND
from opengever.base.interfaces import IDuringContentCreation
from plone.app.dexterity.behaviors.metadata import MetadataBase
Expand Down Expand Up @@ -99,6 +100,11 @@ def _acquire_value(self, context):
if IDuringContentCreation.providedBy(request):
# object does not yet exist, context is container (add)
container = context
elif ISiteRoot.providedBy(context):
# The context is the siteroot when using the /@types endpoint
# from the plone rest-api.
# See https://github.com/4teamwork/opengever.core/issues/5283
container = context
else:
# object already exists, container is parent of context (edit)
container = context.aq_inner.aq_parent
Expand Down
2 changes: 1 addition & 1 deletion opengever/meeting/tests/test_vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_contains_proposal_templates(self):
[self.proposal_template.Title(),
self.ad_hoc_agenda_item_template.Title(),
self.recurring_agenda_item_template.Title()],
[term.title for term in factory(context=None)])
[term.title.encode('utf-8') for term in factory(context=None)])

self.assertItemsEqual(
[IUUID(self.proposal_template),
Expand Down
2 changes: 1 addition & 1 deletion opengever/meeting/vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def __call__(self, context):
for brain in api.content.find(object_provides=IProposalTemplate):
terms.append(SimpleTerm(value=brain.UID,
token=brain.UID,
title=brain.Title))
title=safe_unicode(brain.Title)))

terms.sort(key=attrgetter('title'))
return SimpleVocabulary(terms)
5 changes: 5 additions & 0 deletions opengever/repository/behaviors/referenceprefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def reference_number_prefix_default(context):
default factory is called during content creation), unless the factory
is called from an edit or display action (which shouldn't happen).
"""
if not context:
# We don't have any context if using the /@types endpoint from the
# plone rest-api.
# See https://github.com/4teamwork/opengever.core/issues/5283
return u''
return PrefixAdapter(context).get_next_number()


Expand Down
2 changes: 1 addition & 1 deletion versions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ plone.protect = 3.1.2
plone.recipe.command = 1.1
plone.recipe.precompiler = 0.6
plone.rest = 1.2.0
plone.restapi = 3.4.1
plone.restapi = 3.5.2
plone.schema = 1.2.0
plonegov.pdflatex = 1.5.1
plonegov.recipe.pdflatex = 0.5
Expand Down

0 comments on commit 2a96e4e

Please sign in to comment.