diff --git a/pyproject.toml b/pyproject.toml index acf9851..dd5818d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ dependencies = [ "pyramid_tm", "waitress", "WebHelpers2", - "WuttJamaican[db]>=0.16.1", + "WuttJamaican[db]>=0.17.1", "zope.sqlalchemy>=1.5", ] diff --git a/src/wuttaweb/forms/schema.py b/src/wuttaweb/forms/schema.py index a43e251..f5f206b 100644 --- a/src/wuttaweb/forms/schema.py +++ b/src/wuttaweb/forms/schema.py @@ -24,6 +24,8 @@ Form schema types """ +import uuid as _uuid + import colander from wuttaweb.db import Session @@ -246,7 +248,14 @@ class ObjectRef(colander.SchemaType): # fetch object from DB model = self.app.model - obj = self.session.get(self.model_class, value) + obj = None + if isinstance(value, _uuid.UUID): + obj = self.session.get(self.model_class, value) + else: + try: + obj = self.session.get(self.model_class, _uuid.UUID(value)) + except ValueError: + pass # raise error if not found if not obj: diff --git a/src/wuttaweb/templates/base.mako b/src/wuttaweb/templates/base.mako index 6e5d004..8da535a 100644 --- a/src/wuttaweb/templates/base.mako +++ b/src/wuttaweb/templates/base.mako @@ -563,7 +563,7 @@ const WuttaFeedbackFormData = { referrer: null, - userUUID: ${json.dumps(request.user.uuid if request.user else None)|n}, + userUUID: ${json.dumps(request.user.uuid.hex if request.user else None)|n}, userName: ${json.dumps(str(request.user) if request.user else None)|n}, showDialog: false, sendingFeedback: false, diff --git a/tests/forms/test_widgets.py b/tests/forms/test_widgets.py index 7df8e18..a51ce79 100644 --- a/tests/forms/test_widgets.py +++ b/tests/forms/test_widgets.py @@ -146,14 +146,14 @@ class TestRoleRefsWidget(WebTestCase): # editable values list *excludes* admin (by default) html = widget.serialize(field, {admin.uuid, blokes.uuid}) - self.assertNotIn(admin.uuid, html) - self.assertIn(blokes.uuid, html) + self.assertNotIn(str(admin.uuid), html) + self.assertIn(str(blokes.uuid), html) # but admin is included for root user self.request.is_root = True html = widget.serialize(field, {admin.uuid, blokes.uuid}) - self.assertIn(admin.uuid, html) - self.assertIn(blokes.uuid, html) + self.assertIn(str(admin.uuid), html) + self.assertIn(str(blokes.uuid), html) class TestUserRefsWidget(WebTestCase): diff --git a/tests/test_auth.py b/tests/test_auth.py index aa77280..f7705c8 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,5 +1,6 @@ # -*- coding: utf-8; -*- +import uuid as _uuid from unittest import TestCase from unittest.mock import MagicMock @@ -90,7 +91,7 @@ class TestWuttaSecurityPolicy(TestCase): # invalid identity yields no user self.policy = self.make_policy() - self.policy.remember(self.request, 'bogus-user-uuid') + self.policy.remember(self.request, _uuid.uuid4()) # random uuid user = self.policy.identity(self.request) self.assertIsNone(user) diff --git a/tests/views/test_common.py b/tests/views/test_common.py index 0da2822..4d86ba6 100644 --- a/tests/views/test_common.py +++ b/tests/views/test_common.py @@ -88,7 +88,7 @@ class TestCommonView(WebTestCase): # basic send, with user self.request.user = user - self.request.POST['user_uuid'] = user.uuid + self.request.POST['user_uuid'] = str(user.uuid) with patch.object(mod, 'Session', return_value=self.session): context = view.feedback() self.assertEqual(context, {'ok': True})