Skip to content

Commit

Permalink
fix unpublish for old articles (#2476)
Browse files Browse the repository at this point in the history
* fix unpublish for old articles

when there is no record in publish queue. make it possible
to turn this off if needed.

SDESK-6922
  • Loading branch information
petrjasek authored Sep 26, 2023
1 parent 8aadf68 commit cd0f0ae
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
5 changes: 5 additions & 0 deletions apps/publish/enqueue/enqueue_killed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import logging

from eve.utils import config
from flask import current_app as app

from apps.archive.common import ITEM_OPERATION
from apps.publish.content.kill import ITEM_KILL
Expand Down Expand Up @@ -45,6 +46,10 @@ def get_subscribers(self, doc, target_media_type):
}
subscribers, subscriber_codes, associations = self._get_subscribers_for_previously_sent_items(query)

if not subscribers and app.config.get("UNPUBLISH_TO_MATCHING_SUBSCRIBERS", False):
active_subscribers = get_resource_service("subscribers").get_active()
subscribers, subscriber_codes = self.filter_subscribers(doc, active_subscribers, target_media_type)

return subscribers, subscriber_codes, associations

def enqueue_archived_kill_item(self, item, transmission_details):
Expand Down
63 changes: 63 additions & 0 deletions features/unpublish.feature
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,66 @@ Feature: Unpublish content
"""
{"state": "published", "pubstatus": "usable"}
"""

@auth
Scenario: Unpublish single item without record in publish queue
Given "desks"
"""
[{"name": "Sports", "members":[{"user":"#CONTEXT_USER_ID#"}]}]
"""
And "archive"
"""
[{"guid": "123", "headline": "test", "_current_version": 0, "state": "fetched",
"task": {"desk": "#desks._id#", "stage": "#desks.incoming_stage#", "user": "#CONTEXT_USER_ID#"},
"subject":[{"qcode": "17004000", "name": "Statistics"}],
"slugline": "test", "type": "text",
"body_html": "<p>Test Document body</p>\n<p>with a \"quote\"</p>"}]
"""
And config update
"""
{
"UNPUBLISH_TO_MATCHING_SUBSCRIBERS": true
}
"""
When we post to "/products" with success
"""
{
"name":"prod-1","codes":"abc,xyz", "product_type": "both"
}
"""
And we post to "/subscribers" with success
"""
{
"name":"Channel 3","media_type":"media", "subscriber_type": "wire", "sequence_num_settings":{"min" : 1, "max" : 10}, "email": "test@test.com",
"products": ["#products._id#"], "is_active": true,
"destinations":[{"name":"Test","format": "nitf", "delivery_type":"email","config":{"recipients":"test@test.com"}}],
"api_products": ["#products._id#"]
}
"""
And we publish "#archive._id#" with "publish" type and "published" state
Then we get OK response
When we enqueue published
Then we assert the content api item "123" is published to subscriber "#subscribers._id#"
When we get "/items/123"

Given empty "publish_queue"

When we publish "#archive._id#" with "unpublish" type and "unpublished" state
Then we get OK response
And we get existing resource
"""
{"state": "unpublished", "pubstatus": "canceled"}
"""
When we enqueue published
Then we assert the content api item "123" is published to subscriber "#subscribers._id#"

When we get "/publish_queue"
Then we get list with 2 items
"""
{
"_items": [
{"publishing_action": "unpublished"},
{"publishing_action": "unpublished"}
]
}
"""
7 changes: 7 additions & 0 deletions superdesk/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,3 +1100,10 @@ def local_to_utc_hour(hour):
#: .. versionadded:: 2.5.4
#:
EMBED_PRODUCT_FILTERING = strtobool(env("EMBED_PRODUCT_FILTERING", "false"))

#: When enabled it will unpublish article to matching subscribers
#: if there are no records in publish queue for it.
#:
#: .. versionadded:: 2.7
#:
UNPUBLISH_TO_MATCHING_SUBSCRIBERS = True
5 changes: 3 additions & 2 deletions tests/io/feeding_services/ftp_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import os
import shutil
import tempfile
from unittest import mock
import datetime
import pytz

from unittest import mock
from superdesk.tests import setup
from superdesk.tests import TestCase as CoreTestCase
from superdesk.io.feeding_services import ftp
Expand Down Expand Up @@ -92,7 +92,8 @@ class FakeFTPRecentFiles(FakeFTP):
files = [
ftp_file("old_file.xml", "20170517164756"),
# we need a file ingested now, before INGEST_OLD_CONTENT_MINUTES is expired
ftp_file("recent_file.xml", datetime.datetime.today().strftime("%Y%m%d%H%M%S")),
# adding extra time to make sure that the file won't expire before the test runs
ftp_file("recent_file.xml", (datetime.datetime.today() + datetime.timedelta(hours=1)).strftime("%Y%m%d%H%M%S")),
]


Expand Down

0 comments on commit cd0f0ae

Please sign in to comment.