From b50dc89f13f9b672fa679649c460c9bf7d0b590c Mon Sep 17 00:00:00 2001 From: Abdelrahman Moustafa Date: Thu, 30 Jan 2025 11:18:32 +0100 Subject: [PATCH 1/2] Add the folder_content listing to the @listing-custom-fields endpoint --- changes/TI-1895.feature | 1 + docs/public/dev-manual/api/listings.rst | 12 +++- opengever/api/listing_custom_fields.py | 1 + .../api/tests/test_listing_custom_fields.py | 59 ++++++++++++++++++- 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 changes/TI-1895.feature diff --git a/changes/TI-1895.feature b/changes/TI-1895.feature new file mode 100644 index 00000000000..783c1d44723 --- /dev/null +++ b/changes/TI-1895.feature @@ -0,0 +1 @@ +Add folder_content listing to the @listing-custom-fields endpoint. [amo] diff --git a/docs/public/dev-manual/api/listings.rst b/docs/public/dev-manual/api/listings.rst index d1a69289981..b028a366235 100644 --- a/docs/public/dev-manual/api/listings.rst +++ b/docs/public/dev-manual/api/listings.rst @@ -319,7 +319,17 @@ Endpoints verwendet werden. "widget": "date" } } - } + }, + "folder_contents": { + "properties": { + "hasmeetingaccess_custom_field_boolean": { + "name": "hasmeetingaccess_custom_field_boolean", + "title": "can access meetings", + "type": "boolean", + "widget": null + } + } + } } diff --git a/opengever/api/listing_custom_fields.py b/opengever/api/listing_custom_fields.py index 41fd79902ff..416331d0ce6 100644 --- a/opengever/api/listing_custom_fields.py +++ b/opengever/api/listing_custom_fields.py @@ -7,6 +7,7 @@ LISTING_TO_SLOTS = { u'dossiers': get_dossier_assignment_slots, u'documents': get_document_assignment_slots, + u'folder_contents': get_document_assignment_slots, } diff --git a/opengever/api/tests/test_listing_custom_fields.py b/opengever/api/tests/test_listing_custom_fields.py index b0c97dab802..9716ac61e46 100644 --- a/opengever/api/tests/test_listing_custom_fields.py +++ b/opengever/api/tests/test_listing_custom_fields.py @@ -118,9 +118,54 @@ def test_listing_custom_fields_fixture_slots(self, browser): u'widget': None } } + }, + u'folder_contents': { + u'properties': { + u'choose_custom_field_string': { + u'name': u'choose_custom_field_string', + u'title': u'Choose', + u'type': u'string', + u'widget': None + }, + u'choosemulti_custom_field_strings': { + u'name': u'choosemulti_custom_field_strings', + u'title': u'Choose multi', + u'type': u'array', + u'widget': None + }, + u'date_custom_field_date': { + u'name': u'date_custom_field_date', + u'title': u'Choose a date', + u'type': u'string', + u'widget': u'date' + }, + u'f1_custom_field_string': { + u'name': u'f1_custom_field_string', + u'title': u'Field 1', + u'type': u'string', + u'widget': None + }, + u'num_custom_field_int': { + u'name': u'num_custom_field_int', + u'title': u'Number', + u'type': u'integer', + u'widget': None + }, + u'textline_custom_field_string': { + u'name': u'textline_custom_field_string', + u'title': u'A line of text', + u'type': u'string', + u'widget': None + }, + u'yesorno_custom_field_boolean': { + u'name': u'yesorno_custom_field_boolean', + u'title': u'Yes or no', + u'type': u'boolean', + u'widget': None + } + } } - }, - browser.json + }, browser.json ) @browsing @@ -156,6 +201,16 @@ def test_listing_custom_fields_merges_duplicate_slots(self, browser): u"widget": None } } + }, + u"folder_contents": { + u"properties": { + u"yesorno_custom_field_boolean": { + u"name": u"yesorno_custom_field_boolean", + u"title": u"Y/N (regulations)", + u"type": u"boolean", + u"widget": None + } + } } }, browser.json From 2aed98a651d4b19bf36e57f9bc170f9c36014dc8 Mon Sep 17 00:00:00 2001 From: Abdelrahman Moustafa Date: Thu, 30 Jan 2025 11:19:35 +0100 Subject: [PATCH 2/2] Exclude dossier assignment from propertysheet when workspace is active --- changes/TI-1895.other | 1 + opengever/propertysheets/assignment.py | 6 ++-- opengever/propertysheets/definition.py | 9 +++--- .../tests/test_propertysheet_metaschema.py | 31 +++++++++++++++++++ 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 changes/TI-1895.other diff --git a/changes/TI-1895.other b/changes/TI-1895.other new file mode 100644 index 00000000000..d426659c698 --- /dev/null +++ b/changes/TI-1895.other @@ -0,0 +1 @@ +Exclude the dossier assignment slot from propertysheets for teamraum deployments. [amo] diff --git a/opengever/propertysheets/assignment.py b/opengever/propertysheets/assignment.py index d69abb5eed2..1debe44b7f0 100644 --- a/opengever/propertysheets/assignment.py +++ b/opengever/propertysheets/assignment.py @@ -1,4 +1,5 @@ from opengever.propertysheets import _ +from opengever.workspace import is_workspace_feature_enabled from zope.component import getUtility from zope.interface import implementer from zope.schema.interfaces import IVocabularyFactory @@ -21,8 +22,9 @@ def __call__(self, context): for term in get_document_assignment_slots_vocab(): assignment_terms.append(term) - for term in get_dossier_assignment_slots_vocab(): - assignment_terms.append(term) + if not is_workspace_feature_enabled(): + for term in get_dossier_assignment_slots_vocab(): + assignment_terms.append(term) return SimpleVocabulary(assignment_terms) diff --git a/opengever/propertysheets/definition.py b/opengever/propertysheets/definition.py index fe1af4f7ba1..51e954997e4 100644 --- a/opengever/propertysheets/definition.py +++ b/opengever/propertysheets/definition.py @@ -4,7 +4,6 @@ from opengever.propertysheets.default_from_member import attach_member_property_default_factory from opengever.propertysheets.exceptions import InvalidFieldType from opengever.propertysheets.exceptions import InvalidFieldTypeDefinition -from opengever.propertysheets.exceptions import InvalidSchemaAssignment from opengever.propertysheets.helpers import add_current_value_to_allowed_terms from opengever.propertysheets.helpers import is_choice_field from opengever.propertysheets.helpers import is_multiple_choice_field @@ -198,9 +197,11 @@ def assignments(self, values): term = assignment_slots.getTermByToken(token) assignments.append(term.value) except LookupError: - raise InvalidSchemaAssignment( - "The assignment '{}' is invalid.".format(token) - ) + # Missing slots should be ignored without raising an error. + # This allows custom properties to remain usable even if the corresponding slots no longer exist. + # Currently, this mainly occurs during testing or local development + # when switching between Gever and Teamraum. + continue self._assignments = tuple(assignments) diff --git a/opengever/propertysheets/tests/test_propertysheet_metaschema.py b/opengever/propertysheets/tests/test_propertysheet_metaschema.py index 586a3f71486..61253d2483e 100644 --- a/opengever/propertysheets/tests/test_propertysheet_metaschema.py +++ b/opengever/propertysheets/tests/test_propertysheet_metaschema.py @@ -410,3 +410,34 @@ def test_field_descriptions_are_translated(self, browser): ], [prop['description'] for prop in field_properties.values()] ) + + +class TestWorkSpacePropertysheetMetaschemaEndpoint(IntegrationTestCase): + features = ('workspace',) + + @browsing + def test_assignment_vocabularies_excluded_dossier_type(self, browser): + self.login(self.propertysheets_manager, browser) + + headers = self.api_headers.copy() + headers.update({'Accept-Language': 'de-ch'}) + + browser.open( + view="@propertysheet-metaschema", + headers=headers, + ) + + properties = browser.json['properties'] + self.assertEqual( + [ + u'Dokument', + u'Dokument (Typ: Anfrage)', + u'Dokument (Typ: Antrag)', + u'Dokument (Typ: Bericht)', + u'Dokument (Typ: Offerte)', + u'Dokument (Typ: Protokoll)', + u'Dokument (Typ: Reglement)', + u'Dokument (Typ: Vertrag)', + u'Dokument (Typ: Weisung)', + ], + properties['assignments']['items']['enumNames'])