Пример #1
0
    def on_update(self, updates, original):
        """
        Process the action on the event provided

        Automatically sets the `version_creator`, then calls the appropriate method
        for single event (`update_single_event`) or a series of events (`update_recurring_events`)
        """
        user_id = get_user_id()
        if user_id:
            updates['version_creator'] = user_id
            set_ingested_event_state(updates, original)

        # If `skip_on_update` is provided in the updates
        # Then return here so no further processing is performed on this event.
        if 'skip_on_update' in updates:
            return

        # We only validate the original event,
        # not the events that are automatically updated by the system
        self.validate(updates, original)

        # Run the specific method based on if the original is a single or a series of recurring events
        # Or if the 'update_method' is 'UPDATE_SINGLE'
        update_method = self.get_update_method(original, updates)
        if update_method == UPDATE_SINGLE:
            self.update_single_event(updates, original)
        else:
            self.update_recurring_events(updates, original, update_method)
Пример #2
0
    def on_update(self, updates, original):
        """Update single or series of recurring events.

        Determine if the supplied event is a single event or a
        series of recurring events, and call the appropriate method
        for the event type.
        """
        if 'skip_on_update' in updates:
            # this is a recursive update (see below)
            del updates['skip_on_update']
            return

        update_method = updates.pop('update_method', UPDATE_SINGLE)

        user = get_user()
        user_id = user.get(config.ID_FIELD) if user else None

        if user_id:
            updates['version_creator'] = user_id
            set_ingested_event_state(updates, original)

        lock_user = original.get('lock_user', None)
        str_user_id = str(user.get(config.ID_FIELD)) if user_id else None

        if lock_user and str(lock_user) != str_user_id:
            print(lock_user, str_user_id)
            raise SuperdeskApiError.forbiddenError(
                'The item was locked by another user')

        # validate event
        self.validate_event(updates, original)

        # Run the specific methods based on if the original is a
        # single or a series of recurring events
        if not original.get('dates', {}).get(
                'recurring_rule', None) or update_method == UPDATE_SINGLE:
            self._update_single_event(updates, original)
        else:
            self._update_recurring_events(updates, original, update_method)