From ca20994ae7fe5db65efd0245c18ac3375a344be6 Mon Sep 17 00:00:00 2001 From: Abdelrahman Moustafa Date: Tue, 28 Jan 2025 14:53:08 +0100 Subject: [PATCH] exclude dossier assignment from propertysheet when workspace is active and provide folder_contents slot for listing --- changes/TI-1895.other | 1 + docs/public/dev-manual/api/listings.rst | 12 +++- opengever/api/listing_custom_fields.py | 1 + .../api/tests/test_listing_custom_fields.py | 59 ++++++++++++++++++- opengever/propertysheets/assignment.py | 6 +- opengever/propertysheets/definition.py | 8 +-- .../tests/test_propertysheet_metaschema.py | 31 ++++++++++ 7 files changed, 109 insertions(+), 9 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..adbe45f16b4 --- /dev/null +++ b/changes/TI-1895.other @@ -0,0 +1 @@ +Exclude the Dossier assignment slot from propertysheets if workspace is active. [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 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..47d12427cf8 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,10 @@ def assignments(self, values): term = assignment_slots.getTermByToken(token) assignments.append(term.value) except LookupError: - raise InvalidSchemaAssignment( - "The assignment '{}' is invalid.".format(token) - ) + # We remove the lookup error here as we exclude now + # the IDossier from the slots if we have workspace feature + # Which act as a multi mandant + 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'])