Skip to content

Commit

Permalink
Merge pull request #563 from marwoodandrew/sd-5414
Browse files Browse the repository at this point in the history
[SD-5414] Spike expiry config setting
  • Loading branch information
ioanpocol committed Sep 6, 2016
2 parents bbd0b60 + 84f0e33 commit 6b47760
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
17 changes: 16 additions & 1 deletion apps/archive/archive_spike.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from apps.packages import PackageService, TakesPackageService
from apps.archive.archive_rewrite import ArchiveRewriteService
from superdesk.metadata.packages import LINKED_IN_PACKAGES, PACKAGE
from superdesk.utc import get_expiry_date

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -151,6 +152,20 @@ def _removed_refs_from_package(self, item):
"""
PackageService().remove_spiked_refs_from_package(item)

def _get_spike_expiry(self, desk_id, stage_id):
"""
If there is a SPIKE_EXPIRY_MINUTES setting then that is used to set the spike expiry.
If a None value is configured then the desk/stage value is returned.
:param desk_id:
:param stage_id:
:return:
"""
# If no maximum spike expiry is set then return the desk/stage values
if app.settings['SPIKE_EXPIRY_MINUTES'] is None:
return get_expiry(desk_id=desk_id, stage_id=stage_id)
else:
return get_expiry_date(app.settings['SPIKE_EXPIRY_MINUTES'])

def update(self, id, updates, original):
original_state = original[ITEM_STATE]
if not is_workflow_state_transition_valid('spike', original_state):
Expand All @@ -160,7 +175,7 @@ def update(self, id, updates, original):
item = get_resource_service(ARCHIVE).find_one(req=None, _id=id)
task = item.get('task', {})

updates[EXPIRY] = get_expiry(desk_id=task.get('desk'), stage_id=task.get('stage'))
updates[EXPIRY] = self._get_spike_expiry(desk_id=task.get('desk'), stage_id=task.get('stage'))
updates[REVERT_STATE] = item.get(ITEM_STATE, None)

if original.get('rewrite_of'):
Expand Down
25 changes: 25 additions & 0 deletions features/content_spike.feature
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,28 @@ Feature: Content Spiking
"""
When we spike "item-1"
Then we get OK response

@auth
Scenario: Spike a desk content with configured spike expiry
Given empty "desks"
Given empty "archive"
Given empty "stages"
Given "desks"
"""
[{"name": "Sports Desk", "content_expiry": 60}]
"""
Given "archive"
"""
[{"_id": "item-1", "guid": "item-1", "_current_version": 1, "headline": "test", "task":{"desk":"#desks._id#", "stage" :"#desks.incoming_stage#"}}]
"""
Then we set spike exipry "70"
When we spike "item-1"
Then we get OK response
And we get spiked content "item-1"
And we get version 2
And we get desk spike expiry after "70"
When we get "/archive/item-1"
Then we get existing resource
"""
{"_id": "item-1", "state": "spiked", "sign_off": "abc"}
"""
3 changes: 3 additions & 0 deletions superdesk/factory/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,6 @@ def env(variable, fallback_value=None):

# default timeout for ftp connections
FTP_TIMEOUT = 300

# This setting is used to overide the desk/stage expiry for items to expire from the spike
SPIKE_EXPIRY_MINUTES = None
5 changes: 5 additions & 0 deletions superdesk/tests/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2129,3 +2129,8 @@ def we_find_no_reference_of_package_in_item(context, reference):
linked_in_packages = resp.get('linked_in_packages', [])
assert reference not in [p.get('package') for p in linked_in_packages], \
'Package reference {} found in item'.format(reference)


@then('we set spike exipry "{expiry}"')
def we_set_spike_exipry(context, expiry):
context.app.settings['SPIKE_EXPIRY_MINUTES'] = int(expiry)
3 changes: 3 additions & 0 deletions superdesk/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,6 @@ def env(variable, fallback_value=None):

# customer repo specific templates path
CUSTOM_TEMPLATE_PATH = []

# This setting is used to overide the desk/stage expiry for items to expire from the spike
SPIKE_EXPIRY_MINUTES = None

0 comments on commit 6b47760

Please sign in to comment.