Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix updating editor fields removes extra contents #2335

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/archive/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def on_update(self, updates, original):
"""
user = get_user()

editor_utils.generate_fields(updates)
editor_utils.generate_fields(updates, original=original)
if ITEM_TYPE in updates:
del updates[ITEM_TYPE]

Expand Down
2 changes: 1 addition & 1 deletion apps/publish/content/correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def on_update(self, updates, original):
self.change_being_corrected_to_published(updates, original)

def update(self, id, updates, original):
editor_utils.generate_fields(updates)
editor_utils.generate_fields(updates, original=original)
get_resource_service("archive")._handle_media_updates(updates, original, get_user())
super().update(id, updates, original)

Expand Down
69 changes: 69 additions & 0 deletions features/archive.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1216,3 +1216,72 @@ Feature: News Items Archive
}
}
"""

@auth
Scenario: Fix updating editor state removing other keys from extra dict (SDFID-641)

Given "archive"
"""
[{"_id": "test_editor_gen_2", "guid": "test_editor_gen_2", "headline": "test", "extra": {"foo": "foo"}}]
"""

When we patch given
"""
{
"fields_meta" : {
"headline" : {
"draftjsState" : [
{
"blocks" : [
{
"key" : "dphij",
"text" : "editor 3 headline test",
"type" : "unstyled",
"depth" : 0,
"inlineStyleRanges" : [ ],
"entityRanges" : [ ],
"data" : {
"MULTIPLE_HIGHLIGHTS" : {}
}
}
],
"entityMap" : {}
}
]
},
"extra>bar" : {
"draftjsState" : [
{
"blocks" : [
{
"key" : "dphij",
"text" : "bar",
"type" : "unstyled",
"depth" : 0,
"inlineStyleRanges" : [ ],
"entityRanges" : [ ],
"data" : {
"MULTIPLE_HIGHLIGHTS" : {}
}
}
],
"entityMap" : {}
}
]
}
}
}
"""
When we get "/archive/test_editor_gen_2"
Then we get existing resource
"""
{
"_id": "test_editor_gen_2",
"guid": "test_editor_gen_2",
"headline": "editor 3 headline test",
"extra": {
"foo": "foo",
"bar": "<p>bar</p>"
}
}
"""
5 changes: 4 additions & 1 deletion superdesk/editor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def filter_blocks(item, field, filter, is_html=True):
editor.update_item()


def generate_fields(item, fields=None, force=False, reload=False):
def generate_fields(item, fields=None, force=False, reload=False, original=None):
"""Generate item fields from editor states
:param item: item containing Draft.js ContentState
Expand All @@ -788,6 +788,9 @@ def generate_fields(item, fields=None, force=False, reload=False):
if fields is None:
fields = get_content_state_fields(item)

if original is not None and original.get("extra"):
item.setdefault("extra", original["extra"])

for field in fields:
client_value = get_field_value(item, field)
editor = Editor3Content(item, field, is_html=is_html(field), reload=reload)
Expand Down