Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the /@types endpoint publicly available #56

Merged
merged 3 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/src/ploneorg/src/ploneorg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
_ = MessageFactory("ploneorg")

logger = logging.getLogger("ploneorg")


from . import patches # noqa
19 changes: 19 additions & 0 deletions backend/src/ploneorg/src/ploneorg/patches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# We need to bypass the check for logged-in users in the /@types endpoint
# because it is used for rendering the default view.
# This is not a security problem, because the schemas are already
# public in the plone.org repository.

from plone.restapi.services.types import get

import logging


logger = logging.getLogger(__name__)


def bypass_security_check(context):
pass


logger.info("Patching plone.restapi.services.types.get.check_security")
get.check_security = bypass_security_check
22 changes: 22 additions & 0 deletions backend/src/ploneorg/tests/test_types_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Tests for /@types service patch."""
from plone.restapi.testing import RelativeSession
from ploneorg.testing import PLONEORG_FUNCTIONAL_TESTING

import unittest


class TestTypesService(unittest.TestCase):
"""Test /@types API service."""

layer = PLONEORG_FUNCTIONAL_TESTING

def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer["portal"]
self.portal_url = self.portal.absolute_url()
self.api_session = RelativeSession(self.portal_url)
self.api_session.headers.update({"Accept": "application/json"})

def test_anonymous_user_can_view_types_service(self):
response = self.api_session.get("/@types")
self.assertEqual(200, response.status_code)