Ejemplo n.º 1
0
    def update(self, id, updates, original):
        user = get_user(required=True)

        updates['revert_state'] = original[ITEM_STATE]
        updates[ITEM_STATE] = WORKFLOW_STATE.SPIKED
        set_item_expiry(updates)

        # Mark item as unlocked directly in order to avoid more queries and notifications
        # coming from lockservice.
        updates.update({
            LOCK_USER: None,
            LOCK_SESSION: None,
            'lock_time': None,
            'lock_action': None
        })

        remove_autosave_on_spike(original)
        item = self.backend.update(self.datasource, id, updates, original)
        push_notification('planning:spiked',
                          item=str(id),
                          user=str(user.get(config.ID_FIELD)),
                          etag=item['_etag'],
                          revert_state=item['revert_state'])

        coverages = original.get('coverages') or []
        for coverage in coverages:
            assigned_to = coverage.get('assigned_to')
            if assigned_to:
                user = get_user()
                assignment_service = get_resource_service('assignments')
                assignment = assignment_service.find_one(
                    req=None, _id=assigned_to.get('assignment_id'))
                slugline = assignment.get('planning').get('slugline', '')
                coverage_type = assignment.get('planning').get(
                    'g2_content_type', '')
                PlanningNotifications().notify_assignment(
                    coverage_status=coverage.get('workflow_status'),
                    target_user=assignment.get('assigned_to').get('user'),
                    target_desk=assignment.get('assigned_to').get('desk')
                    if not assignment.get('assigned_to').get('user') else None,
                    message='{{actioning_user}} has spiked a {{coverage_type}} '
                    'coverage for \"{{slugline}}\"',
                    slugline=slugline,
                    coverage_type=get_coverage_type_name(coverage_type),
                    actioning_user=user.get('display_name',
                                            user.get('username', 'Unknown')),
                    omit_user=True)

        return item
Ejemplo n.º 2
0
    def update(self, id, updates, original):
        if original.get('pubstatus') or original.get('state') not in\
                [WORKFLOW_STATE.DRAFT, WORKFLOW_STATE.POSTPONED, WORKFLOW_STATE.CANCELLED]:
            raise SuperdeskApiError.badRequestError(
                message=
                "Spike failed. Planning item in invalid state for spiking.")

        user = get_user(required=True)

        updates['revert_state'] = original[ITEM_STATE]
        updates[ITEM_STATE] = WORKFLOW_STATE.SPIKED
        set_item_expiry(updates)

        coverages = deepcopy(original.get('coverages') or [])
        for coverage in coverages:
            if coverage.get('workflow_status') == WORKFLOW_STATE.ACTIVE:
                coverage['workflow_status'] = WORKFLOW_STATE.DRAFT
                coverage['assigned_to'] = {}

        updates['coverages'] = coverages

        # Mark item as unlocked directly in order to avoid more queries and notifications
        # coming from lockservice.
        updates.update({
            LOCK_USER: None,
            LOCK_SESSION: None,
            'lock_time': None,
            'lock_action': None
        })

        remove_autosave_on_spike(original)
        item = self.backend.update(self.datasource, id, updates, original)
        push_notification('planning:spiked',
                          item=str(id),
                          user=str(user.get(config.ID_FIELD)),
                          etag=item['_etag'],
                          revert_state=item['revert_state'])

        for coverage in coverages:
            workflow_status = coverage.get('workflow_status')
            if workflow_status == WORKFLOW_STATE.DRAFT:
                self.notify_draft_coverage_on_spike(coverage)

        return item
Ejemplo n.º 3
0
 def _spike_event(updates, original):
     updates['revert_state'] = original[ITEM_STATE]
     updates[ITEM_STATE] = WORKFLOW_STATE.SPIKED
     set_item_expiry(updates)