Example #1
0
    def on_updated(self, updates, original):
        get_component(ItemAutosave).clear(original['_id'])
        on_update_media_archive()

        if '_version' in updates:
            add_activity('created new version {{ version }} for item {{ type }} about {{ subject }}',
                         version=updates['_version'], subject=get_subject(updates, original))
Example #2
0
    def on_updated(self, updates, original):
        get_component(ItemAutosave).clear(original['_id'])

        if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE:
            self.packageService.on_updated(updates, original)

        updated = copy(original)
        updated.update(updates)

        if config.VERSION in updates:
            add_activity(
                ACTIVITY_UPDATE,
                'created new version {{ version }} for item {{ type }} about "{{ subject }}"',
                self.datasource,
                item=updated,
                version=updates[config.VERSION],
                subject=get_subject(updates, original),
                type=updated[ITEM_TYPE])

        push_content_notification([updated, original])
        get_resource_service('archive_broadcast').reset_broadcast_status(
            updates, original)

        if updates.get('profile'):
            get_resource_service('content_types').set_used(
                [updates.get('profile')])

        self.cropService.update_media_references(updates, original)
Example #3
0
 def on_replaced(self, document, original):
     get_component(ItemAutosave).clear(original['_id'])
     add_activity(ACTIVITY_UPDATE, 'replaced item {{ type }} about {{ subject }}',
                  self.datasource, item=original,
                  type=original['type'], subject=get_subject(original))
     user = get_user()
     push_notification('item:replaced', item=str(original['_id']), user=str(user.get('_id')))
Example #4
0
 def on_replaced(self, document, original):
     get_component(ItemAutosave).clear(original['_id'])
     add_activity(ACTIVITY_UPDATE, 'replaced item {{ type }} about {{ subject }}',
                  self.datasource, item=original,
                  type=original['type'], subject=get_subject(original))
     push_content_notification([document, original])
     self.cropService.update_media_references(document, original)
Example #5
0
 def on_replaced(self, document, original):
     get_component(ItemAutosave).clear(original['_id'])
     add_activity(ACTIVITY_UPDATE, 'replaced item {{ type }} about {{ subject }}',
                  self.datasource, item=original,
                  type=original['type'], subject=get_subject(original))
     push_content_notification([document, original])
     self.cropService.update_media_references(document, original)
 def create(self, items):
     citems = deepcopy(items)
     for citem in citems:
         citem['_id_document'] = citem['_id']
         del citem['_id']
     try:
         return get_model(LegalArchiveModel).create(citems)
     except Exception as e:
         get_component(Error).create(LegalArchiveModel.name(), items, str(e))
 def create(self, docs, **kwargs):
     if not docs:
         raise SuperdeskApiError.notFoundError('Content is missing')
     req = parse_request(self.datasource)
     try:
         get_component(ItemAutosave).autosave(docs[0]['_id'], docs[0], get_user(required=True), req.if_match)
     except InvalidEtag:
         raise SuperdeskApiError.preconditionFailedError('Client and server etags don\'t match')
     return [docs[0]['_id']]
 def update(self, original, updates):
     updated = copy(original)
     updated.update(updates)
     updated['_id_document'] = original['_id']
     del updated['_id']
     try:
         return get_model(LegalArchiveModel).create([updated])
     except Exception as e:
         get_component(Error).create(LegalArchiveModel.name(), [updated], str(e))
Example #9
0
 def on_created(self, docs):
     on_create_media_archive()
     get_component(LegalArchiveProxy).create(docs)
     for doc in docs:
         add_activity(ACTIVITY_CREATE,
                      'added new item {{ type }} about {{ subject }}',
                      item=doc,
                      type=doc['type'],
                      subject=get_subject(doc))
Example #10
0
 def create(self, docs, **kwargs):
     if not docs:
         raise SuperdeskApiError.notFoundError('Content is missing')
     req = parse_request(self.datasource)
     try:
         get_component(ItemAutosave).autosave(docs[0]['_id'], docs[0], get_user(required=True), req.if_match)
     except InvalidEtag:
         raise SuperdeskApiError.preconditionFailedError('Client and server etags don\'t match')
     return [docs[0]['_id']]
Example #11
0
 def on_created(self, docs):
     on_create_media_archive()
     get_component(LegalArchiveProxy).create(docs)
     for doc in docs:
         subject = get_subject(doc)
         if subject:
             msg = 'added new {{ type }} item about "{{ subject }}"'
         else:
             msg = 'added new {{ type }} item with empty header/title'
         add_activity(ACTIVITY_CREATE, msg, item=doc, type=doc['type'], subject=subject)
Example #12
0
    def on_updated(self, updates, original):
        get_component(ItemAutosave).clear(original['_id'])
        get_component(LegalArchiveProxy).update(original, updates)
        on_update_media_archive()

        if '_version' in updates:
            updated = copy(original)
            updated.update(updates)
            add_activity(ACTIVITY_UPDATE, 'created new version {{ version }} for item {{ type }} about {{ subject }}',
                         item=updated, version=updates['_version'], subject=get_subject(updates, original))
Example #13
0
 def on_created(self, docs):
     on_create_media_archive()
     get_component(LegalArchiveProxy).create(docs)
     for doc in docs:
         subject = get_subject(doc)
         if subject:
             msg = 'added new {{ type }} item about "{{ subject }}"'
         else:
             msg = 'added new {{ type }} item with empty header/title'
         add_activity(ACTIVITY_CREATE, msg, item=doc, type=doc['type'], subject=subject)
Example #14
0
    def on_updated(self, updates, original):
        get_component(ItemAutosave).clear(original['_id'])
        get_component(LegalArchiveProxy).update(original, updates)
        on_update_media_archive(item=original['_id'])

        if '_version' in updates:
            updated = copy(original)
            updated.update(updates)
            add_activity(ACTIVITY_UPDATE, 'created new version {{ version }} for item {{ type }} about "{{ subject }}"',
                         item=updated, version=updates['_version'], subject=get_subject(updates, original),
                         type=updated['type'])
Example #15
0
 def create(self, docs, **kwargs):
     if not docs:
         raise SuperdeskApiError.notFoundError("Content is missing")
     req = parse_request(self.datasource)
     try:
         get_component(ItemAutosave).autosave(docs[0]["_id"], docs[0], get_user(required=True), req.if_match)
     except InvalidEtag:
         raise SuperdeskApiError.preconditionFailedError("Client and server etags don't match")
     except KeyError:
         raise SuperdeskApiError.badRequestError("Request for Auto-save must have _id")
     return [docs[0]["_id"]]
Example #16
0
    def on_deleted(self, doc):
        get_component(ItemAutosave).clear(doc['_id'])
        if doc[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE:
            self.packageService.on_deleted(doc)

        remove_media_files(doc)

        add_activity(ACTIVITY_DELETE, 'removed item {{ type }} about {{ subject }}',
                     self.datasource, item=doc,
                     type=doc[ITEM_TYPE], subject=get_subject(doc))
        push_expired_notification([doc.get(config.ID_FIELD)])
        app.on_archive_item_deleted(doc)
Example #17
0
    def on_deleted(self, doc):
        get_component(ItemAutosave).clear(doc['_id'])
        if doc[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE:
            self.packageService.on_deleted(doc)

        remove_media_files(doc)

        add_activity(ACTIVITY_DELETE, 'removed item {{ type }} about {{ subject }}',
                     self.datasource, item=doc,
                     type=doc[ITEM_TYPE], subject=get_subject(doc))
        push_expired_notification([doc.get(config.ID_FIELD)])
        app.on_archive_item_deleted(doc)
Example #18
0
 def on_replaced(self, document, original):
     get_component(ItemAutosave).clear(original['_id'])
     add_activity(ACTIVITY_UPDATE,
                  'replaced item {{ type }} about {{ subject }}',
                  self.datasource,
                  item=original,
                  type=original['type'],
                  subject=get_subject(original))
     user = get_user()
     push_notification('item:replaced',
                       item=str(original['_id']),
                       user=str(user.get('_id')))
Example #19
0
 def on_replaced(self, document, original):
     get_component(ItemAutosave).clear(original["_id"])
     add_activity(
         ACTIVITY_UPDATE,
         "replaced item {{ type }} about {{ subject }}",
         self.datasource,
         item=original,
         type=original["type"],
         subject=get_subject(original),
     )
     user = get_user()
     push_notification("item:replaced", item=str(original["_id"]), user=str(user.get("_id")))
Example #20
0
 def create(self, docs, **kwargs):
     user = get_user(required=True)
     auth = get_auth()
     item_id = request.view_args["item_id"]
     lock_action = docs[0].get("lock_action", "edit")
     item = get_component(ItemLock).lock({"_id": item_id}, user["_id"], auth["_id"], lock_action)
     return _update_returned_document(docs[0], item)
 def create(self, docs, **kwargs):
     user = get_user(required=True)
     auth = get_auth()
     item_id = request.view_args['item_id']
     lock_action = docs[0].get('lock_action', 'edit')
     item = get_component(ItemLock).lock({'_id': item_id}, user['_id'], auth['_id'], lock_action)
     return _update_returned_document(docs[0], item)
Example #22
0
    def on_created(self, docs):
        packages = [doc for doc in docs if doc['type'] == 'composite']
        if packages:
            self.packageService.on_created(packages)

        get_component(LegalArchiveProxy).create(docs)
        user = get_user()
        for doc in docs:
            subject = get_subject(doc)
            if subject:
                msg = 'added new {{ type }} item about "{{ subject }}"'
            else:
                msg = 'added new {{ type }} item with empty header/title'
            add_activity(ACTIVITY_CREATE, msg,
                         self.datasource, item=doc, type=doc['type'], subject=subject)
            push_notification('item:created', item=str(doc['_id']), user=str(user.get('_id')))
Example #23
0
 def create(self, docs, **kwargs):
     user = get_user(required=True)
     auth = get_auth()
     item_id = request.view_args['item_id']
     item = get_component(ItemLock).unlock({'_id': item_id}, user['_id'],
                                           auth['_id'], None)
     return _update_returned_document(docs[0], item)
Example #24
0
    def on_updated(self, updates, original):
        get_component(ItemAutosave).clear(original['_id'])
        get_component(LegalArchiveProxy).update(original, updates)

        if original['type'] == 'composite':
            self.packageService.on_updated(updates, original)

        user = get_user()
        if '_version' in updates:
            updated = copy(original)
            updated.update(updates)
            add_activity(ACTIVITY_UPDATE, 'created new version {{ version }} for item {{ type }} about "{{ subject }}"',
                         self.datasource, item=updated,
                         version=updates['_version'], subject=get_subject(updates, original),
                         type=updated['type'])
            push_notification('item:updated', item=str(original['_id']), user=str(user.get('_id')))
Example #25
0
def update_legal_archive(self, ids):
    for _id in ids:
        archived_doc = get_resource_service(
            'archive').find_one_in_base_backend(req=None, _id=_id)
        if not archived_doc:
            continue
        return get_component(LegalArchive).create([archived_doc])
Example #26
0
 def create(self, docs, **kwargs):
     user = get_user(required=True)
     auth = get_auth()
     item_id = request.view_args['item_id']
     item = get_component(ItemHold).hold({'_id': item_id}, user['_id'], auth['_id'])
     build_custom_hateoas(custom_hateoas, item)
     return [item['_id']]
Example #27
0
 def create(self, docs, **kwargs):
     user = get_user(required=True)
     auth = get_auth()
     item_id = request.view_args['item_id']
     lock_action = docs[0].get('lock_action', 'edit')
     item = get_component(ItemLock).lock({'_id': item_id}, user['_id'],
                                         auth['_id'], lock_action)
     return _update_returned_document(docs[0], item)
Example #28
0
    def _update_archive(self, original, updates, versioned_doc=None, should_insert_into_versions=True):
        """
        Updates the articles into archive collection and inserts the latest into archive_versions.
        Also clears autosaved versions if any.
        :param: versioned_doc: doc which can be inserted into archive_versions
        :param: should_insert_into_versions if True inserts the latest document into versions collection
        """

        self.backend.update(self.datasource, original[config.ID_FIELD], updates, original)

        if should_insert_into_versions:
            if versioned_doc is None:
                insert_into_versions(id_=original[config.ID_FIELD])
            else:
                insert_into_versions(doc=versioned_doc)

        get_component(ItemAutosave).clear(original[config.ID_FIELD])
Example #29
0
 def create(self, docs, **kwargs):
     user = get_user(required=True)
     auth = get_auth()
     item_id = request.view_args['item_id']
     item = get_component(ItemHold).hold({'_id': item_id}, user['_id'],
                                         auth['_id'])
     build_custom_hateoas(custom_hateoas, item)
     return [item['_id']]
Example #30
0
    def update(self, id, updates, original):
        archived_item = super().find_one(req=None, _id=id)
        try:
            any_channel_closed = False

            if archived_item['type'] == 'composite':
                self.__publish_package_items(archived_item, updates[config.LAST_UPDATED])

            # document is saved to keep the initial changes
            set_sign_off(updates, original)
            self.backend.update(self.datasource, id, updates, original)

            # document is saved to change the status
            if (original.get('publish_schedule') or updates.get('publish_schedule')) \
                    and original[config.CONTENT_STATE] not in ['published', 'killed', 'scheduled']:
                updates[config.CONTENT_STATE] = 'scheduled'
            else:
                updates[config.CONTENT_STATE] = self.published_state

            original.update(updates)
            get_component(ItemAutosave).clear(original['_id'])

            if archived_item['type'] != 'composite':
                # queue only text items
                any_channel_closed = self.queue_transmission(original)
                task = self.__send_to_publish_stage(original)
                if task:
                    updates['task'] = task

            self.backend.update(self.datasource, id, updates, original)
            user = get_user()
            push_notification('item:publish:closed:channels' if any_channel_closed else 'item:publish',
                              item=str(id), unique_name=archived_item['unique_name'],
                              desk=str(archived_item['task']['desk']), user=str(user.get('_id', '')))
            original.update(super().find_one(req=None, _id=id))
        except SuperdeskApiError as e:
            raise e
        except KeyError as e:
            raise SuperdeskApiError.badRequestError(
                message="Key is missing on article to be published: {}"
                .format(str(e)))
        except Exception as e:
            logger.error("Something bad happened while publishing %s".format(id), e)
            raise SuperdeskApiError.internalError(message="Failed to publish the item: {}"
                                                  .format(str(e)))
Example #31
0
 def unlock_item(self, item_id, doc):
     user_id = get_user(required=True)['_id']
     session_id = get_auth()['_id']
     lock_service = get_component(LockService)
     resource_service = get_resource_service('events')
     item = resource_service.find_one(req=None, _id=item_id)
     updated_item = lock_service.unlock(item, user_id, session_id, 'events')
     return update_returned_document(doc, updated_item,
                                     CUSTOM_HATEOAS_EVENTS)
Example #32
0
    def on_updated(self, updates, original):
        get_component(ItemAutosave).clear(original['_id'])

        if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE:
            self.packageService.on_updated(updates, original)

        ArchiveCropService().delete_replaced_crop_files(updates, original)

        updated = copy(original)
        updated.update(updates)

        if config.VERSION in updates:
            add_activity(ACTIVITY_UPDATE, 'created new version {{ version }} for item {{ type }} about "{{ subject }}"',
                         self.datasource, item=updated,
                         version=updates[config.VERSION], subject=get_subject(updates, original),
                         type=updated[ITEM_TYPE])

        push_content_notification([updated, original])
Example #33
0
 def create(self, docs, **kwargs):
     user_id = get_user(required=True)['_id']
     session_id = get_auth()['_id']
     item_id = request.view_args['item_id']
     lock_service = get_component(LockService)
     resource_service = get_resource_service('planning')
     item = resource_service.find_one(req=None, _id=item_id)
     updated_item = lock_service.unlock(item, user_id, session_id, 'planning')
     return update_returned_document(docs[0], updated_item, CUSTOM_HATEOAS_PLANNING)
Example #34
0
 def on_create(self, docs):
     if not docs:
         raise SuperdeskError('Content is missing', 400)
     req = parse_request(self.endpoint_name)
     c = get_component(ItemAutosave)
     try:
         c.autosave(docs[0]['_id'], docs[0], get_user(required=True), req.if_match)
     except InvalidEtag:
         raise SuperdeskError('Client and server etags don\'t match', 412)
Example #35
0
 def sync_assignment_unlock(self, item, user_id):
     if item.get('assignment_id'):
         assignment_update_data = self._get_assignment_data_on_archive_update(
             {}, item)
         if assignment_update_data.get('assignment'):
             assignment = assignment_update_data.get('assignment')
             if assignment.get(LOCK_USER):
                 lock_service = get_component(LockService)
                 lock_service.unlock(assignment, user_id,
                                     get_auth()['_id'], 'assignments')
Example #36
0
    def on_updated(self, updates, original):
        c = get_component(ItemAutosave)
        c.clear(original['_id'])
        on_update_media_archive()

        if '_version' in updates:
            add_activity(
                'created new version {{ version }} for item {{ type }} about {{ subject }}',
                version=updates['_version'],
                subject=get_subject(updates, original))
Example #37
0
 def on_create(self, docs):
     if not docs:
         raise SuperdeskError('Content is missing', 400)
     req = parse_request(self.endpoint_name)
     c = get_component(ItemAutosave)
     try:
         c.autosave(docs[0]['_id'], docs[0], get_user(required=True),
                    req.if_match)
     except InvalidEtag:
         raise SuperdeskError('Client and server etags don\'t match', 412)
Example #38
0
    def create(self, docs, **kwargs):
        user = get_user(required=True)
        auth = get_auth()
        item_id = request.view_args['item_id']
        item = get_component(ItemLock).unlock({'_id': item_id}, user['_id'], auth['_id'], None)

        if item is None:
            # version 1 item must have been deleted by now
            return [0]

        return _update_returned_document(docs[0], item)
Example #39
0
    def create(self, docs, **kwargs):
        user = get_user(required=True)
        auth = get_auth()
        item_id = request.view_args["item_id"]
        item = get_component(ItemLock).unlock({"_id": item_id}, user["_id"], auth["_id"], None)

        if item is None:
            # version 1 item must have been deleted by now
            return [0]

        return _update_returned_document(docs[0], item)
Example #40
0
    def create(self, docs, **kwargs):
        user_id = get_user(required=True)['_id']
        session_id = get_auth()['_id']
        lock_service = get_component(LockService)

        # If the event is a recurrent event, unlock all other events in this series
        item_id = request.view_args['item_id']
        resource_service = get_resource_service('events')
        item = resource_service.find_one(req=None, _id=item_id)
        updated_item = lock_service.unlock(item, user_id, session_id, 'events')
        return update_returned_document(docs[0], updated_item,
                                        CUSTOM_HATEOAS_EVENTS)
Example #41
0
    def on_updated(self, updates, original):
        get_component(ItemAutosave).clear(original['_id'])

        if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE:
            self.packageService.on_updated(updates, original)

        ArchiveCropService().delete_replaced_crop_files(updates, original)

        updated = copy(original)
        updated.update(updates)

        if config.VERSION in updates:
            add_activity(
                ACTIVITY_UPDATE,
                'created new version {{ version }} for item {{ type }} about "{{ subject }}"',
                self.datasource,
                item=updated,
                version=updates[config.VERSION],
                subject=get_subject(updates, original),
                type=updated[ITEM_TYPE])

        push_content_notification([updated, original])
Example #42
0
    def create(self, docs, **kwargs):
        user_id = get_user(required=True)['_id']
        session_id = get_auth()['_id']
        item_id = request.view_args['item_id']
        lock_action = docs[0].get('lock_action', 'edit')
        lock_service = get_component(LockService)
        item = get_resource_service('planning').find_one(req=None, _id=item_id)

        if item and item.get('event_item'):
            lock_service.validate_relationship_locks(item, 'planning')

        updated_item = lock_service.lock(item, user_id, session_id, lock_action, 'planning')
        return update_returned_document(docs[0], updated_item, CUSTOM_HATEOAS_PLANNING)
Example #43
0
    def on_updated(self, updates, original):
        get_component(ItemAutosave).clear(original['_id'])
        get_component(LegalArchiveProxy).update(original, updates)

        if original['type'] == 'composite':
            self.packageService.on_updated(updates, original)

        user = get_user()
        if '_version' in updates:
            updated = copy(original)
            updated.update(updates)
            add_activity(
                ACTIVITY_UPDATE,
                'created new version {{ version }} for item {{ type }} about "{{ subject }}"',
                self.datasource,
                item=updated,
                version=updates['_version'],
                subject=get_subject(updates, original),
                type=updated['type'])
            push_notification('item:updated',
                              item=str(original['_id']),
                              user=str(user.get('_id')))
Example #44
0
    def on_created(self, docs):
        packages = [doc for doc in docs if doc['type'] == 'composite']
        if packages:
            self.packageService.on_created(packages)

        get_component(LegalArchiveProxy).create(docs)
        user = get_user()
        for doc in docs:
            subject = get_subject(doc)
            if subject:
                msg = 'added new {{ type }} item about "{{ subject }}"'
            else:
                msg = 'added new {{ type }} item with empty header/title'
            add_activity(ACTIVITY_CREATE,
                         msg,
                         self.datasource,
                         item=doc,
                         type=doc['type'],
                         subject=subject)
            push_notification('item:created',
                              item=str(doc['_id']),
                              user=str(user.get('_id')))
Example #45
0
    def lock_item(self, item_id, action, doc):
        user_id = get_user(required=True)['_id']
        session_id = get_auth()['_id']
        lock_action = action
        lock_service = get_component(LockService)
        item = get_resource_service('events').find_one(req=None, _id=item_id)

        lock_service.validate_relationship_locks(item, 'events')
        updated_item = lock_service.lock(item, user_id, session_id,
                                         lock_action, 'events')

        return update_returned_document(doc, updated_item,
                                        CUSTOM_HATEOAS_EVENTS)
Example #46
0
    def on_updated(self, updates, original):
        get_component(ItemAutosave).clear(original["_id"])

        if original["type"] == "composite":
            self.packageService.on_updated(updates, original)

        user = get_user()

        if config.VERSION in updates:
            updated = copy(original)
            updated.update(updates)
            add_activity(
                ACTIVITY_UPDATE,
                'created new version {{ version }} for item {{ type }} about "{{ subject }}"',
                self.datasource,
                item=updated,
                version=updates[config.VERSION],
                subject=get_subject(updates, original),
                type=updated["type"],
            )

        push_notification("item:updated", item=str(original["_id"]), user=str(user.get("_id")))
    def create(self, docs, **kwargs):
        user_id = get_user(required=True)['_id']
        session_id = get_auth()['_id']

        lock_action = docs[0].get('lock_action', 'edit')
        lock_service = get_component(LockService)

        item_id = request.view_args['item_id']
        item = get_resource_service('assignments').find_one(req=None, _id=item_id)

        self.validate(item, user_id)
        updated_item = lock_service.lock(item, user_id, session_id, lock_action, 'assignments')

        return _update_returned_document(docs[0], updated_item)
Example #48
0
    def on_updated(self, updates, original):
        get_component(ItemAutosave).clear(original['_id'])

        if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE:
            self.packageService.on_updated(updates, original)

        updated = copy(original)
        updated.update(updates)

        if config.VERSION in updates:
            add_activity(ACTIVITY_UPDATE,
                         'created new version {{ version }} for item {{ type }} about "{{ subject }}"',
                         self.datasource, item=updated,
                         version=updates[config.VERSION], subject=get_subject(updates, original),
                         type=updated[ITEM_TYPE])

        push_content_notification([updated, original])
        get_resource_service('archive_broadcast').reset_broadcast_status(updates, original)

        if updates.get('profile'):
            get_resource_service('content_types').set_used([updates.get('profile')])

        self.cropService.update_media_references(updates, original)
    def create(self, docs, **kwargs):
        user_id = get_user(required=True)['_id']
        session_id = get_auth()['_id']
        lock_service = get_component(LockService)

        # If the event is a recurrent event, unlock all other events in this series
        item_id = request.view_args['item_id']
        resource_service = get_resource_service('assignments')
        item = resource_service.find_one(req=None, _id=item_id)

        if not self.is_assignment_locked_by_user(item, user_id):
            updated_item = lock_service.unlock(item, user_id, session_id, 'assignments')
            return _update_returned_document(docs[0], updated_item)

        return _update_returned_document(docs[0], item)
Example #50
0
    def hold(self, filter, user_id, session):
        item_model = get_model(ItemModel)
        item = item_model.find_one(filter)
        if not item:
            raise SuperdeskApiError.notFoundError()

        can_user_lock, error_message = get_component(ItemLock).can_lock(item, user_id, session)

        if can_user_lock:
            updates = {"state": "on-hold"}
            item_model.update(filter, updates)
            push_notification("item:hold", item=str(item.get("_id")), user=str(user_id))
        else:
            raise SuperdeskApiError.forbiddenError(message=error_message)

        item = item_model.find_one(filter)
        return item
 def create(self, docs, **kwargs):
     user = get_user(required=True)
     auth = get_auth()
     item_id = request.view_args['item_id']
     item = get_component(ItemLock).unlock({'_id': item_id}, user['_id'], auth['_id'], None)
     return _update_returned_document(docs[0], item)
Example #52
0
 def on_created(self, docs):
     on_create_media_archive()
     get_component(LegalArchiveProxy).create(docs)
     for doc in docs:
         add_activity(ACTIVITY_CREATE, 'added new item {{ type }} about {{ subject }}', item=doc,
                      type=doc['type'], subject=get_subject(doc))
Example #53
0
 def delete(self, lookup):
     user = get_user(required=True)
     item_id = request.view_args['item_id']
     get_component(ItemHold).restore({'_id': item_id}, user['_id'])
Example #54
0
    def update(self, id, updates, original):
        archived_item = super().find_one(req=None, _id=id)

        try:
            any_channel_closed = False

            if archived_item['type'] == 'composite':
                self.__publish_package_items(archived_item, updates[config.LAST_UPDATED])

            # document is saved to keep the initial changes
            set_sign_off(updates, original)
            self.backend.update(self.datasource, id, updates, original)

            # document is saved to change the status
            if (original.get('publish_schedule') or updates.get('publish_schedule')) \
                    and original[config.CONTENT_STATE] not in PUBLISH_STATES:
                updates[config.CONTENT_STATE] = 'scheduled'
            else:
                updates['publish_schedule'] = None
                updates[config.CONTENT_STATE] = self.published_state

            original.update(updates)
            get_component(ItemAutosave).clear(original['_id'])

            if archived_item['type'] != 'composite':
                # check if item is in a digital package
                package_id = TakesPackageService().get_take_package_id(original)
                if package_id:
                    # process the takes to form digital master file content
                    package, package_updates = self.process_takes(take=original, package_id=package_id)
                    package_updates[config.CONTENT_STATE] = self.published_state
                    resolve_document_version(document=package_updates,
                                             resource=ARCHIVE, method='PATCH',
                                             latest_doc=package)
                    self.backend.update(self.datasource, package['_id'], package_updates, package)
                    package.update(package_updates)
                    insert_into_versions(doc=package)

                    # send it to the digital channels
                    any_channel_closed_digital, queued_digital = \
                        self.publish(doc=package, updates=None, target_output_channels=DIGITAL)

                    self.update_published_collection(published_item=package)
                else:
                    any_channel_closed_digital = False
                    queued_digital = False

                # queue only text items
                any_channel_closed_wire, queued_wire = \
                    self.publish(doc=original, updates=updates, target_output_channels=WIRE if package_id else None)

                any_channel_closed = any_channel_closed_digital or any_channel_closed_wire
                queued = queued_digital or queued_wire

                if not queued:
                    raise PublishQueueError.item_not_queued_error(Exception('Nothing is saved to publish queue'), None)

            self.backend.update(self.datasource, id, updates, original)
            user = get_user()
            push_notification('item:publish:closed:channels' if any_channel_closed else 'item:publish',
                              item=str(id), unique_name=archived_item['unique_name'],
                              desk=str(archived_item.get('task', {}).get('desk', '')),
                              user=str(user.get('_id', '')))
            original.update(super().find_one(req=None, _id=id))
        except SuperdeskApiError as e:
            raise e
        except KeyError as e:
            raise SuperdeskApiError.badRequestError(
                message="Key is missing on article to be published: {}"
                .format(str(e)))
        except Exception as e:
            logger.error("Something bad happened while publishing %s".format(id), e)
            raise SuperdeskApiError.internalError(message="Failed to publish the item: {}"
                                                  .format(str(e)))
 def create(self, docs, **kwargs):
     user = get_user(required=True)
     item_id = request.view_args['item_id']
     item = get_component(ItemSpike).spike({'_id': item_id}, user['_id'])
     build_custom_hateoas(custom_hateoas, item)
     return [item['_id']]
Example #56
0
 def on_replaced(self, document, original):
     get_component(ItemAutosave).clear(original['_id'])
     on_update_media_archive(item=original['_id'])
Example #57
0
def update_legal_archive(self, ids):
    for _id in ids:
        archived_doc = get_resource_service('archive').find_one_in_base_backend(req=None, _id=_id)
        if not archived_doc:
            continue
        return get_component(LegalArchive).create([archived_doc])