Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/2.8' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Sep 19, 2024
2 parents 587f5af + ae9e2bd commit ed1c8cf
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 21 deletions.
100 changes: 91 additions & 9 deletions server/features/content_profiles_coverage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
Expand All @@ -118,7 +113,7 @@ Feature: Coverage Content Profiles
Given "planning_types"
"""
[{
"_id": 1,
"_id": "coverage",
"name": "coverage",
"editor": {
"language": {
Expand All @@ -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"
}
}
}]
"""
Expand Down Expand Up @@ -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"}
}
}]}
"""
32 changes: 20 additions & 12 deletions server/planning/content_profiles/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -50,23 +54,20 @@ 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,
)

# 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):
Expand Down Expand Up @@ -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)

0 comments on commit ed1c8cf

Please sign in to comment.