def update_single_event(self, updates, original):
        events_service = get_resource_service('events')
        has_plannings = events_service.has_planning_items(original)

        remove_lock_information(updates)
        reason = updates.pop('reason', None)

        event_in_use = has_plannings or (original.get('pubstatus') or '') != ''
        if event_in_use or original.get('state') == WORKFLOW_STATE.POSTPONED:
            if event_in_use:
                # If the Event is in use, then we will duplicate the original
                # and set the original's status to `rescheduled`
                duplicated_event_id = self._duplicate_event(
                    updates, original, events_service)
                updates['reschedule_to'] = duplicated_event_id
                set_actioned_date_to_event(updates, original)
            else:
                updates['actioned_date'] = None

            self._mark_event_rescheduled(updates, reason, not event_in_use)

            if not event_in_use:
                updates['state'] = WORKFLOW_STATE.DRAFT

            if has_plannings:
                self._reschedule_event_plannings(original, reason)

        self.set_planning_schedule(updates)
Exemple #2
0
    def _set_event_cancelled(updates, original, occur_cancel_state):
        if not EventsCancelService.validate_states(original):
            raise SuperdeskApiError.badRequestError(
                'Event not in valid state for cancellation')

        remove_lock_information(updates)
        updates.update({
            'state': WORKFLOW_STATE.CANCELLED,
            'occur_status': occur_cancel_state,
            'state_reason': updates.get('reason')
        })
        set_actioned_date_to_event(updates, original)
    def update(self, id, updates, original):
        reason = updates.pop('reason', None)
        set_actioned_date_to_event(updates, original)

        item = super().update(id, updates, original)

        # Because we require the original item being actioned against to be locked
        # then we can check the lock information of original and updates to check if this
        # event was the original event.
        if self.is_original_event(original):
            user = get_user(required=True).get(config.ID_FIELD, '')
            session = get_auth().get(config.ID_FIELD, '')

            push_notification('events:postpone',
                              item=str(original[config.ID_FIELD]),
                              user=str(user),
                              session=str(session),
                              reason=reason,
                              actioned_date=updates.get('actioned_date'))

        return item