Beispiel #1
0
    def _update_single_event(self, updates, original):
        """Updates the metadata of a single event.

        If recurring_rule is provided, we convert this single event into
        a series of recurring events, otherwise we simply update this event.
        """

        if post_required(updates, original):
            merged = deepcopy(original)
            merged.update(updates)
            get_resource_service('events_post').validate_item(merged)

        # Determine if we're to convert this single event to a recurring
        #  of events
        if original.get(LOCK_ACTION) == 'convert_recurring' and \
           updates.get('dates', {}).get('recurring_rule', None) is not None:
            generated_events = self._convert_to_recurring_event(
                updates, original)

            # if the original event was "posted" then post all the generated events
            if original.get('pubstatus') in [
                    POST_STATE.CANCELLED, POST_STATE.USABLE
            ]:
                post = {
                    'event': generated_events[0][config.ID_FIELD],
                    'etag': generated_events[0]['_etag'],
                    'update_method': 'all',
                    'pubstatus': original.get('pubstatus')
                }
                get_resource_service('events_post').post([post])

            push_notification('events:updated:recurring',
                              item=str(original[config.ID_FIELD]),
                              user=str(updates.get('version_creator', '')),
                              recurrence_id=str(
                                  generated_events[0]['recurrence_id']))
        else:
            if original.get('lock_action') == 'mark_completed' and updates.get(
                    'actioned_date'):
                self.mark_event_complete(original, updates, original, None)

            # This updates Event metadata only
            push_notification('events:updated',
                              item=str(original[config.ID_FIELD]),
                              user=str(updates.get('version_creator', '')))
Beispiel #2
0
    def _update_recurring_events(self, updates, original, update_method):
        """Method to update recurring events.

        If the recurring_rule has been removed for this event, process
        it separately, otherwise update the event and/or its recurring rules
        """
        # This method now only handles updating of Event metadata
        # So make sure to remove any date information that might be in
        # the updates
        updates.pop('dates', None)

        if update_method == UPDATE_FUTURE:
            historic, past, future = self.get_recurring_timeline(original)
            events = future
        else:
            historic, past, future = self.get_recurring_timeline(original)
            events = historic + past + future

        events_post_service = get_resource_service('events_post')

        # First we want to validate that all events can be posted
        for e in events:
            if post_required(updates, e):
                merged = deepcopy(e)
                merged.update(updates)
                events_post_service.validate_item(merged)

        for e in events:
            event_id = e[config.ID_FIELD]
            new_updates = deepcopy(updates)
            new_updates['skip_on_update'] = True
            new_updates[config.ID_FIELD] = event_id
            self.patch(event_id, new_updates)
            app.on_updated_events(new_updates, {'_id': event_id})

        # And finally push a notification to connected clients
        push_notification('events:updated:recurring',
                          item=str(original[config.ID_FIELD]),
                          recurrence_id=str(original['recurrence_id']),
                          user=str(updates.get('version_creator', '')))
Beispiel #3
0
    def _update_recurring_events(self, updates, original, update_method):
        """Method to update recurring events.

        If the recurring_rule has been removed for this event, process
        it separately, otherwise update the event and/or its recurring rules
        """
        # This method now only handles updating of Event metadata
        # So make sure to remove any date information that might be in
        # the updates
        updates.pop('dates', None)

        if update_method == UPDATE_FUTURE:
            historic, past, future = self.get_recurring_timeline(original)
            events = future
        else:
            historic, past, future = self.get_recurring_timeline(original)
            events = historic + past + future

        events_post_service = get_resource_service('events_post')

        # First we want to validate that all events can be posted
        for e in events:
            if post_required(updates, e):
                merged = deepcopy(e)
                merged.update(updates)
                events_post_service.validate_item(merged)

        # If this update is from assignToCalendar action
        # Then we only want to update the calendars of each Event
        only_calendars = original.get('lock_action') == 'assign_calendar'
        original_calendar_qcodes = [
            calendar['qcode'] for calendar in original.get('calendars') or []
        ]
        # Get the list of calendars added
        updated_calendars = [
            calendar for calendar in updates.get('calendars') or []
            if calendar['qcode'] not in original_calendar_qcodes
        ]

        mark_completed = original.get(
            'lock_action') == 'mark_completed' and updates.get('actioned_date')
        mark_complete_validated = False
        for e in events:
            event_id = e[config.ID_FIELD]

            new_updates = deepcopy(updates)
            new_updates['skip_on_update'] = True
            new_updates[config.ID_FIELD] = event_id

            if only_calendars:
                # Get the original for this item, and add new calendars to it
                # Skipping calendars already assigned to this item
                original_event = self.find_one(req=None, _id=event_id)
                original_qcodes = [
                    calendar['qcode']
                    for calendar in original_event.get('calendars') or []
                ]

                new_updates['calendars'] = deepcopy(
                    original_event.get('calendars') or [])
                new_updates['calendars'].extend([
                    calendar for calendar in updated_calendars
                    if calendar['qcode'] not in original_qcodes
                ])
            elif mark_completed:
                self.mark_event_complete(original, updates, e,
                                         mark_complete_validated)
                # It is validated if the previous funciton did not raise an error
                mark_complete_validated = True

            self.patch(event_id, new_updates)
            app.on_updated_events(new_updates, {'_id': event_id})

        # And finally push a notification to connected clients
        push_notification('events:updated:recurring',
                          item=str(original[config.ID_FIELD]),
                          recurrence_id=str(original['recurrence_id']),
                          user=str(updates.get('version_creator', '')))