diff --git a/server/features/content_profiles_coverage.feature b/server/features/content_profiles_coverage.feature index 338fced73..9cbbf4153 100644 --- a/server/features/content_profiles_coverage.feature +++ b/server/features/content_profiles_coverage.feature @@ -45,8 +45,7 @@ Feature: Coverage Content Profiles "xmp_file": {"enabled": false}, "headline": {"enabled": false}, "keyword": {"enabled": false}, - "files": {"enabled": false}, - "no_content_linking": {"enabled": false} + "files": {"enabled": false} }, "schema": { "contact_info": { @@ -101,10 +100,6 @@ Feature: Coverage Content Profiles "required": false, "type": "dict" }, - "no_content_linking": { - "required": false, - "type": "boolean" - }, "scheduled_updates": { "required": false, "type": "list" @@ -118,7 +113,7 @@ Feature: Coverage Content Profiles Given "planning_types" """ [{ - "_id": 1, + "_id": "coverage", "name": "coverage", "editor": { "language": { @@ -129,11 +124,16 @@ Feature: Coverage Content Profiles "headline": { "enabled": true, "index": 3 - } + }, + "no_content_linking": {"enabled": true} }, "schema": { "language": {"required": true}, - "headline": {"required": true} + "headline": {"required": true}, + "no_content_linking": { + "required": false, + "type": "boolean" + } } }] """ @@ -168,3 +168,85 @@ Feature: Coverage Content Profiles } }]} """ + + @auth + Scenario: no_content_linking only available if PLANNING_LINK_UPDATES_TO_COVERAGES is enabled + # Test with default values + When we get "/planning_types" + Then we get existing resource + """ + {"_items": [{ + "name": "coverage", + "editor": { + "no_content_linking": "__no_value__" + }, + "schema": { + "no_content_linking": "__no_value__" + } + }]} + """ + Given config update + """ + {"PLANNING_LINK_UPDATES_TO_COVERAGES": true} + """ + When we get "/planning_types" + Then we get existing resource + """ + {"_items": [{ + "name": "coverage", + "editor": { + "no_content_linking": {"enabled": false} + }, + "schema": { + "no_content_linking": {"required": false, "type": "boolean"} + } + }]} + """ + # Now test with custom config + Given config update + """ + {"PLANNING_LINK_UPDATES_TO_COVERAGES": false} + """ + Given "planning_types" + """ + [{ + "_id": "coverage", + "name": "coverage", + "editor": { + "no_content_linking": {"enabled": true} + }, + "schema": { + "no_content_linking": {"required": false, "type": "boolean"} + } + }] + """ + When we get "/planning_types" + Then we get existing resource + """ + {"_items": [{ + "name": "coverage", + "editor": { + "no_content_linking": "__no_value__" + }, + "schema": { + "no_content_linking": "__no_value__" + } + }]} + """ + Given config update + """ + {"PLANNING_LINK_UPDATES_TO_COVERAGES": true} + """ + When we get "/planning_types" + Then we get existing resource + """ + {"_items": [{ + "name": "coverage", + "editor": { + "no_content_linking": {"enabled": true} + }, + "schema": { + "no_content_linking": {"required": false, "type": "boolean"} + } + }]} + """ diff --git a/server/planning/content_profiles/service.py b/server/planning/content_profiles/service.py index 55e29d222..de9269472 100644 --- a/server/planning/content_profiles/service.py +++ b/server/planning/content_profiles/service.py @@ -8,6 +8,7 @@ # AUTHORS and LICENSE files distributed with this source code, or # at https://www.sourcefabric.org/superdesk/license +from typing import Dict, Any from copy import deepcopy import superdesk @@ -34,11 +35,14 @@ def find_one(self, req, **lookup): if not lookup_name and planning_type: lookup_name = planning_type.get("name") - default_planning_type = next( - (ptype for ptype in DEFAULT_PROFILES if ptype.get("name") == lookup_name), - None, + default_planning_type = deepcopy( + next( + (ptype for ptype in DEFAULT_PROFILES if ptype.get("name") == lookup_name), + {}, + ) ) if not planning_type: + self._remove_unsupported_fields(default_planning_type) return default_planning_type self.merge_planning_type(planning_type, default_planning_type) @@ -50,7 +54,7 @@ def get(self, req, lookup): planning_types = list(super().get(req, lookup)) merged_planning_types = [] - for default_planning_type in DEFAULT_PROFILES: + for default_planning_type in deepcopy(DEFAULT_PROFILES): planning_type = next( (p for p in planning_types if p.get("name") == default_planning_type.get("name")), None, @@ -58,15 +62,12 @@ def get(self, req, lookup): # If nothing is defined in database for this planning_type, use default if planning_type is None: + self._remove_unsupported_fields(default_planning_type) merged_planning_types.append(default_planning_type) else: self.merge_planning_type(planning_type, default_planning_type) merged_planning_types.append(planning_type) - if not planning_link_updates_to_coverage(): - coverage_type = [t for t in merged_planning_types if t["name"] == "coverage"][0] - coverage_type["editor"]["no_content_linking"]["enabled"] = False - return ListCursor(merged_planning_types) def merge_planning_type(self, planning_type, default_planning_type): @@ -97,10 +98,17 @@ def merge_planning_type(self, planning_type, default_planning_type): planning_type["schema"] = updated_planning_type["schema"] planning_type["editor"] = updated_planning_type["editor"] planning_type["groups"] = updated_planning_type["groups"] + self._remove_unsupported_fields(planning_type) + def _remove_unsupported_fields(self, planning_type: Dict[str, Any]): # Disable Event ``related_items`` field # if ``EVENT_RELATED_ITEM_SEARCH_PROVIDER_NAME`` config is not set - if planning_type["name"] == "event": - if not get_config_event_related_item_search_provider_name(): - planning_type["editor"].pop("related_items", None) - planning_type["schema"].pop("related_items", None) + if planning_type.get("name") == "event" and not get_config_event_related_item_search_provider_name(): + planning_type["editor"].pop("related_items", None) + planning_type["schema"].pop("related_items", None) + + # Disable Coverage ``no_content_linking`` field + # if ``PLANNING_LINK_UPDATES_TO_COVERAGES`` config is not ``True`` + if planning_type.get("name") == "coverage" and not planning_link_updates_to_coverage(): + planning_type["editor"].pop("no_content_linking", None) + planning_type["schema"].pop("no_content_linking", None)