def update(self, id, updates, original): original_state = original[ITEM_STATE] if not is_workflow_state_transition_valid(ITEM_SPIKE, original_state): raise InvalidStateTransitionError() user = get_user(required=True) item = get_resource_service(ARCHIVE).find_one(req=None, _id=id) task = item.get('task', {}) updates[EXPIRY] = self._get_spike_expiry(desk_id=task.get('desk'), stage_id=task.get('stage')) updates[REVERT_STATE] = item.get(ITEM_STATE, None) if original.get('rewrite_of'): updates['rewrite_of'] = None if original.get('rewritten_by'): updates['rewritten_by'] = None if original.get('broadcast'): updates['broadcast'] = None if original.get('rewrite_sequence'): updates['rewrite_sequence'] = None # remove any relation with linked items updates[ITEM_EVENT_ID] = generate_guid(type=GUID_TAG) # remove lock updates.update({ 'lock_user': None, 'lock_session': None, }) if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE: # remove links from items in the package package_service = PackageService() items = package_service.get_item_refs(original) for item in items: package_item = get_resource_service(ARCHIVE).find_one(req=None, _id=item[GUID_FIELD]) if package_item: linked_in_packages = [linked for linked in package_item.get(LINKED_IN_PACKAGES, []) if linked.get(PACKAGE) != original.get(config.ID_FIELD)] super().system_update(package_item[config.ID_FIELD], {LINKED_IN_PACKAGES: linked_in_packages}, package_item) # keep the structure of old group in order to be able to unspike the package updates[DELETED_GROUPS] = original[GROUPS] # and remove all the items from the package updates['groups'] = [] item = self.backend.update(self.datasource, id, updates, original) push_notification('item:spike', item=str(id), user=str(user.get(config.ID_FIELD))) history_updates = dict(updates) if original.get('task'): history_updates['task'] = original.get('task') app.on_archive_item_updated(history_updates, original, ITEM_SPIKE) self._removed_refs_from_package(id) return item
def update(self, id, updates, original): original_state = original[ITEM_STATE] if not is_workflow_state_transition_valid(ITEM_SPIKE, original_state): raise InvalidStateTransitionError() user = get_user(required=True) item = get_resource_service(ARCHIVE).find_one(req=None, _id=id) task = item.get('task', {}) updates[EXPIRY] = self._get_spike_expiry(desk_id=task.get('desk'), stage_id=task.get('stage')) updates[REVERT_STATE] = item.get(ITEM_STATE, None) if original.get('rewrite_of'): updates['rewrite_of'] = None if original.get('rewritten_by'): updates['rewritten_by'] = None if original.get('broadcast'): updates['broadcast'] = None if original.get('rewrite_sequence'): updates['rewrite_sequence'] = None # remove any relation with linked items updates[ITEM_EVENT_ID] = generate_guid(type=GUID_TAG) if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE: # remove links from items in the package package_service = PackageService() items = package_service.get_item_refs(original) for item in items: package_item = get_resource_service(ARCHIVE).find_one( req=None, _id=item[GUID_FIELD]) if package_item: linked_in_packages = [ linked for linked in package_item.get(LINKED_IN_PACKAGES, []) if linked.get(PACKAGE) != original.get(config.ID_FIELD) ] super().system_update( package_item[config.ID_FIELD], {LINKED_IN_PACKAGES: linked_in_packages}, package_item) # and remove all the items from the package updates['groups'] = [] item = self.backend.update(self.datasource, id, updates, original) push_notification('item:spike', item=str(id), user=str(user.get(config.ID_FIELD))) history_updates = dict(updates) if original.get('task'): history_updates['task'] = original.get('task') app.on_archive_item_updated(history_updates, original, ITEM_SPIKE) self._removed_refs_from_package(id) return item
def on_create(self, docs): package_service = PackageService() for doc in docs: doc.pop('lock_user', None) doc.pop('lock_time', None) doc.pop('lock_session', None) doc['archived_id'] = self._get_archived_id(doc.get('item_id'), doc.get(config.VERSION)) if doc.get(ITEM_TYPE) == CONTENT_TYPE.COMPOSITE: is_takes_package = doc.get(PACKAGE_TYPE) == TAKES_PACKAGE for ref in package_service.get_item_refs(doc): ref['location'] = 'archived' if is_takes_package and not ref.get('is_published'): # if take is not published package_service.remove_ref_from_inmem_package(doc, ref.get(RESIDREF)) if is_takes_package: doc[SEQUENCE] = len(package_service.get_item_refs(doc))
def on_create(self, docs): package_service = PackageService() for doc in docs: doc.pop('lock_user', None) doc.pop('lock_time', None) doc.pop('lock_session', None) doc['archived_id'] = self._get_archived_id(doc.get('item_id'), doc.get(config.VERSION)) if doc.get(ITEM_TYPE) == CONTENT_TYPE.COMPOSITE: is_takes_package = doc.get(PACKAGE_TYPE) == TAKES_PACKAGE for ref in package_service.get_item_refs(doc): ref['location'] = 'archived' if is_takes_package and not ref.get('is_published'): # if take is not published package_service.remove_ref_from_inmem_package( doc, ref.get(RESIDREF)) if is_takes_package: doc[SEQUENCE] = len(package_service.get_item_refs(doc))
def on_updated(self, updates, original): if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE and updates.get(GROUPS, None): # restore the deleted items from package package_service = PackageService() items = package_service.get_item_refs(updates) for item in items: package_item = get_resource_service(ARCHIVE).find_one(req=None, _id=item[GUID_FIELD]) if package_item: linked_in_packages = [linked for linked in package_item.get(LINKED_IN_PACKAGES, []) if linked.get(PACKAGE) != original.get(config.ID_FIELD)] linked_in_packages.append({PACKAGE: original.get(config.ID_FIELD)}) super().system_update(package_item[config.ID_FIELD], {LINKED_IN_PACKAGES: linked_in_packages}, package_item)
def on_create(self, docs): package_service = PackageService() for doc in docs: doc.pop('lock_user', None) doc.pop('lock_time', None) doc.pop('lock_action', None) doc.pop('lock_session', None) doc.pop('highlights', None) doc.pop('marked_desks', None) doc['archived_id'] = self._get_archived_id(doc.get('item_id'), doc.get(config.VERSION)) if doc.get(ITEM_TYPE) == CONTENT_TYPE.COMPOSITE: for ref in package_service.get_item_refs(doc): ref['location'] = 'archived'
def on_create(self, docs): package_service = PackageService() for doc in docs: doc.pop("lock_user", None) doc.pop("lock_time", None) doc.pop("lock_action", None) doc.pop("lock_session", None) doc.pop("highlights", None) doc.pop("marked_desks", None) doc["archived_id"] = self._get_archived_id(doc.get("item_id"), doc.get(config.VERSION)) if doc.get(ITEM_TYPE) == CONTENT_TYPE.COMPOSITE: for ref in package_service.get_item_refs(doc): ref["location"] = "archived"
def on_updated(self, updates, original): if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE and updates.get(GROUPS, None): # restore the deleted items from package package_service = PackageService() items = package_service.get_item_refs(updates) for item in items: package_item = get_resource_service(ARCHIVE).find_one(req=None, _id=item[GUID_FIELD]) if package_item: linked_in_packages = [ linked for linked in package_item.get(LINKED_IN_PACKAGES, []) if linked.get(PACKAGE) != original.get(config.ID_FIELD) ] linked_in_packages.append({PACKAGE: original.get(config.ID_FIELD)}) super().system_update( package_item[config.ID_FIELD], {LINKED_IN_PACKAGES: linked_in_packages}, package_item )
def update(self, id, updates, original): original_state = original[ITEM_STATE] if not is_workflow_state_transition_valid('spike', original_state): raise InvalidStateTransitionError() user = get_user(required=True) item = get_resource_service(ARCHIVE).find_one(req=None, _id=id) task = item.get('task', {}) updates[EXPIRY] = self._get_spike_expiry(desk_id=task.get('desk'), stage_id=task.get('stage')) updates[REVERT_STATE] = item.get(ITEM_STATE, None) if original.get('rewrite_of'): updates['rewrite_of'] = None if original.get('rewritten_by'): updates['rewritten_by'] = None if original.get('broadcast'): updates['broadcast'] = None if original.get('rewrite_sequence'): updates['rewrite_sequence'] = None if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE: # remove links from items in the package package_service = PackageService() items = package_service.get_item_refs(original) for item in items: package_item = get_resource_service(ARCHIVE).find_one(req=None, _id=item['guid']) if package_item: linked_in_packages = [linked for linked in package_item.get(LINKED_IN_PACKAGES, []) if linked.get(PACKAGE) != original.get(config.ID_FIELD)] super().system_update(package_item[config.ID_FIELD], {LINKED_IN_PACKAGES: linked_in_packages}, package_item) # and remove all the items from the package updates['groups'] = [] item = self.backend.update(self.datasource, id, updates, original) push_notification('item:spike', item=str(id), user=str(user.get(config.ID_FIELD))) self._removed_refs_from_package(id) return item
def _remove_and_set_kill_properties(self, article, articles_to_kill, updates): """Removes the irrelevant properties from the given article and sets the properties for kill operation. :param article: article from the archived repo :type article: dict :param articles_to_kill: list of articles which were about to kill from dusty archive :type articles_to_kill: list :param updates: updates to be applied on the article before saving :type updates: dict """ article.pop("archived_id", None) article.pop("_type", None) article.pop("_links", None) article.pop("queue_state", None) article.pop(config.ETAG, None) for field in ["headline", "abstract", "body_html"]: article[field] = updates.get(field, article.get(field, "")) article[ITEM_STATE] = CONTENT_STATE.KILLED if updates[ ITEM_OPERATION] == ITEM_KILL else CONTENT_STATE.RECALLED article[ITEM_OPERATION] = updates[ITEM_OPERATION] article["pubstatus"] = PUB_STATUS.CANCELED article[config.LAST_UPDATED] = utcnow() user = get_user() article["version_creator"] = str(user[config.ID_FIELD]) resolve_document_version(article, ARCHIVE, "PATCH", article) if article[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE: package_service = PackageService() item_refs = package_service.get_item_refs(article) for ref in item_refs: item_in_package = [ item for item in articles_to_kill if item.get( "item_id", item.get(config.ID_FIELD)) == ref[RESIDREF] ] ref["location"] = ARCHIVE ref[config.VERSION] = item_in_package[0][config.VERSION]
def _remove_and_set_kill_properties(self, article, articles_to_kill, updates): """ Removes the irrelevant properties from the given article and sets the properties for kill operation. :param article: article from the archived repo :type article: dict :param articles_to_kill: list of articles which were about to kill from dusty archive :type articles_to_kill: list :param updates: updates to be applied on the article before saving :type updates: dict """ article.pop('archived_id', None) article.pop('_type', None) article.pop('_links', None) article.pop('queue_state', None) article.pop(config.ETAG, None) for field in ['headline', 'abstract', 'body_html']: article[field] = updates.get(field, article.get(field, '')) article[ITEM_STATE] = CONTENT_STATE.KILLED article[ITEM_OPERATION] = ITEM_KILL article['pubstatus'] = PUB_STATUS.CANCELED article[config.LAST_UPDATED] = utcnow() user = get_user() article['version_creator'] = str(user[config.ID_FIELD]) resolve_document_version(article, ARCHIVE, 'PATCH', article) if article[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE: package_service = PackageService() item_refs = package_service.get_item_refs(article) for ref in item_refs: item_in_package = [item for item in articles_to_kill if item.get('item_id', item.get(config.ID_FIELD)) == ref[RESIDREF]] ref['location'] = ARCHIVE ref[config.VERSION] = item_in_package[0][config.VERSION]
def update(self, id, updates, original): original_state = original[ITEM_STATE] if not is_workflow_state_transition_valid(ITEM_SPIKE, original_state): raise InvalidStateTransitionError() archive_service = get_resource_service(ARCHIVE) published_service = get_resource_service("published") user = get_user(required=True) item = archive_service.find_one(req=None, _id=id) task = item.get("task", {}) updates[EXPIRY] = self._get_spike_expiry(desk_id=task.get("desk"), stage_id=task.get("stage")) updates[REVERT_STATE] = item.get(ITEM_STATE, None) if original.get("rewrite_of"): updates["rewrite_of"] = None if original.get("rewritten_by"): updates["rewritten_by"] = None if original.get("broadcast"): updates["broadcast"] = None if original.get("rewrite_sequence"): updates["rewrite_sequence"] = None if original.get("marked_for_user"): # remove marked_for_user on spike and keep it as previous_marked_user for history updates["previous_marked_user"] = original["marked_for_user"] updates["marked_for_user"] = None updates["marked_for_sign_off"] = None if original.get("translation_id") and original.get("translated_from"): # remove translations info from the translated item on spike updates["translated_from"] = None updates["translation_id"] = None id_to_remove = original.get(config.ID_FIELD) # Remove the translated item from the list of translations in the original item # where orignal item can be in archive or in both archive and published resource as well translated_from = archive_service.find_one( req=None, _id=original.get("translated_from")) translated_from_id = translated_from.get(config.ID_FIELD) self._remove_translations(archive_service, translated_from, id_to_remove) if translated_from.get("state") in PUBLISH_STATES: published_items = list( published_service.get_from_mongo( req=None, lookup={"item_id": translated_from_id})) if published_items: for item in published_items: self._remove_translations(published_service, item, id_to_remove) # remove any relation with linked items updates[ITEM_EVENT_ID] = generate_guid(type=GUID_TAG) # remove lock updates.update({ "lock_user": None, "lock_session": None, }) if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE: # remove links from items in the package package_service = PackageService() items = package_service.get_item_refs(original) for item in items: package_item = archive_service.find_one(req=None, _id=item[GUID_FIELD]) if package_item: linked_in_packages = [ linked for linked in package_item.get(LINKED_IN_PACKAGES, []) if linked.get(PACKAGE) != original.get(config.ID_FIELD) ] super().system_update( package_item[config.ID_FIELD], {LINKED_IN_PACKAGES: linked_in_packages}, package_item) # keep the structure of old group in order to be able to unspike the package updates[DELETED_GROUPS] = original[GROUPS] # and remove all the items from the package updates["groups"] = [] item = self.backend.update(self.datasource, id, updates, original) push_notification("item:spike", item=str(id), user=str(user.get(config.ID_FIELD))) history_updates = dict(updates) if original.get("task"): history_updates["task"] = original.get("task") app.on_archive_item_updated(history_updates, original, ITEM_SPIKE) self._removed_refs_from_package(id) return item