示例#1
0
    def test_get_jsonschema_for_portal_type(self):
        portal = self.portal
        request = self.request
        jsonschema = get_jsonschema_for_portal_type("Document", portal, request)
        self.assertEqual(jsonschema["title"], "Page")
        self.assertEqual(jsonschema["type"], "object")
        self.assertIn("title", list(jsonschema["properties"]))
        self.assertIn("title", jsonschema["required"])
        self.assertEqual("default", jsonschema["fieldsets"][0]["id"])
        self.assertIn("title", jsonschema["fieldsets"][0]["fields"])

        jsonschema = get_jsonschema_for_portal_type(
            "Document", portal, request, excluded_fields=["title"]
        )
        self.assertNotIn("title", list(jsonschema["properties"]))
示例#2
0
    def test_get_jsonschema_for_portal_type(self):
        portal = self.portal
        request = self.request
        jsonschema = get_jsonschema_for_portal_type(
            'Document', portal, request)
        self.assertEqual(jsonschema['title'], 'Page')
        self.assertEqual(jsonschema['type'], 'object')
        self.assertIn('title', jsonschema['properties'].keys())
        self.assertIn('title', jsonschema['required'])
        self.assertEquals('default', jsonschema['fieldsets'][0]['id'])
        self.assertIn('title', jsonschema['fieldsets'][0]['fields'])

        jsonschema = get_jsonschema_for_portal_type(
            'Document', portal, request, excluded_fields=['title'])
        self.assertNotIn('title', jsonschema['properties'].keys())
示例#3
0
    def reply(self):
        self.check_security()

        if self.params and len(self.params) > 0:
            self.content_type = "application/json+schema"
            try:
                portal_type = self.params.pop()
                return get_jsonschema_for_portal_type(
                    portal_type,
                    self.context,
                    self.request
                )
            except KeyError:
                self.content_type = "application/json"
                self.request.response.setStatus(404)
                return {
                    'type': 'NotFound',
                    'message': 'Type "{}" could not be found.'.format(
                        portal_type
                    )
                }
        vocab_factory = getUtility(
            IVocabularyFactory,
            name="plone.app.vocabularies.ReallyUserFriendlyTypes"
        )
        return [
            {
                '@id': '{}/@types/{}'.format(
                    self.context.absolute_url(),
                    x.token
                ),
                'title': x.value
            } for x in vocab_factory(self.context)
        ]
示例#4
0
    def reply(self):
        if len(self.params) == 0:
            # Edit intent
            self.intent = 'edit'
            portal_type = self.context.portal_type

        elif len(self.params) == 1:
            # Add intent
            self.intent = 'add'
            portal_type = self.params[0]
            request_annotations = IAnnotations(self.request)
            request_annotations[TYPE_TO_BE_ADDED_KEY] = portal_type

        else:
            return self._error(
                400, "Bad Request",
                "Must supply either zero or one (portal_type) parameters")

        check_security(self.context)
        self.content_type = "application/json+schema"
        try:
            return get_jsonschema_for_portal_type(portal_type, self.context,
                                                  self.request)
        except KeyError:
            self.content_type = "application/json"
            self.request.response.setStatus(404)
            return {
                "type": "NotFound",
                "message": 'Type "{}" could not be found.'.format(portal_type),
            }
示例#5
0
    def test_get_jsonschema_for_portal_type(self):
        portal = self.portal
        request = self.request
        jsonschema = get_jsonschema_for_portal_type('Document', portal,
                                                    request)
        self.assertEqual(jsonschema['title'], 'Page')
        self.assertEqual(jsonschema['type'], 'object')
        self.assertIn('title', list(jsonschema['properties']))
        self.assertIn('title', jsonschema['required'])
        self.assertEqual('default', jsonschema['fieldsets'][0]['id'])
        self.assertIn('title', jsonschema['fieldsets'][0]['fields'])

        jsonschema = get_jsonschema_for_portal_type('Document',
                                                    portal,
                                                    request,
                                                    excluded_fields=['title'])
        self.assertNotIn('title', list(jsonschema['properties']))
示例#6
0
    def reply(self):
        self.check_security()

        if self.params and len(self.params) > 0:
            self.content_type = "application/json+schema"
            try:
                portal_type = self.params.pop()
                return get_jsonschema_for_portal_type(portal_type,
                                                      self.context,
                                                      self.request)
            except KeyError:
                self.content_type = "application/json"
                self.request.response.setStatus(404)
                return {
                    'type': 'NotFound',
                    'message':
                    'Type "{}" could not be found.'.format(portal_type)
                }
        vocab_factory = getUtility(
            IVocabularyFactory,
            name="plone.app.vocabularies.ReallyUserFriendlyTypes")

        portal_types = getToolByName(self.context, 'portal_types')

        # allowedContentTypes already checks for permissions
        allowed_types = [x.getId() for x in self.context.allowedContentTypes()]

        portal = getMultiAdapter((self.context, self.request),
                                 name='plone_portal_state').portal()
        portal_url = portal.absolute_url()

        # only addables if the content type is folderish
        can_add = IFolderish.providedBy(self.context)

        # Filter out any type that doesn't have lookupSchema. We are depended
        # on that in lower level code.
        ftis = [portal_types[x.value] for x in vocab_factory(self.context)]
        ftis = [fti for fti in ftis if getattr(fti, 'lookupSchema', None)]

        return [{
            '@id': '{}/@types/{}'.format(portal_url, fti.getId()),
            'title': translate(fti.Title(), context=self.request),
            'addable': fti.getId() in allowed_types if can_add else False,
        } for fti in ftis]
示例#7
0
    def reply(self):
        if self.params and len(self.params) > 0:
            # Return schema for a specific type
            check_security(self.context)
            self.content_type = "application/json+schema"
            try:
                portal_type = self.params.pop()
                return get_jsonschema_for_portal_type(
                    portal_type, self.context, self.request
                )
            except KeyError:
                self.content_type = "application/json"
                self.request.response.setStatus(404)
                return {
                    "type": "NotFound",
                    "message": 'Type "{}" could not be found.'.format(portal_type),
                }

        # List type info, including addable_types
        info = TypesInfo(self.context, self.request)
        return info(expand=True)["types"]
示例#8
0
    def reply(self):
        self.check_security()

        if self.params and len(self.params) > 0:
            self.content_type = "application/json+schema"
            try:
                portal_type = self.params.pop()
                return get_jsonschema_for_portal_type(portal_type,
                                                      self.context,
                                                      self.request)
            except KeyError:
                self.content_type = "application/json"
                self.request.response.setStatus(404)
                return {
                    'type': 'NotFound',
                    'message':
                    'Type "{}" could not be found.'.format(portal_type)
                }
        vocab_factory = getUtility(
            IVocabularyFactory,
            name="plone.app.vocabularies.ReallyUserFriendlyTypes")

        # allowedContentTypes already checks for permissions
        allowed_types = [x.getId() for x in self.context.allowedContentTypes()]

        portal = getMultiAdapter((self.context, self.request),
                                 name='plone_portal_state').portal()
        portal_url = portal.absolute_url()

        # only addables if the content type is folderish
        can_add = IFolderish.providedBy(self.context)

        return [{
            '@id': '{}/@types/{}'.format(portal_url, x.token),
            'title': x.value,
            'addable': x.token in allowed_types if can_add else False,
        } for x in vocab_factory(self.context)]