def delete(self, lookup): target_id = request.view_args["target_id"] archive_service = get_resource_service(ARCHIVE) target = archive_service.find_one(req=None, _id=target_id) updates = {} if target.get("rewrite_of"): # remove the rewrite info ArchiveSpikeService().update_rewrite(target) if not target.get("rewrite_of"): # there is nothing to do raise SuperdeskApiError.badRequestError( _("Only updates can be unlinked!")) if target.get("rewrite_of"): updates["rewrite_of"] = None if target.get("anpa_take_key"): updates["anpa_take_key"] = None if target.get("rewrite_sequence"): updates["rewrite_sequence"] = None if target.get("sequence"): updates["sequence"] = None updates["event_id"] = generate_guid(type=GUID_TAG) archive_service.system_update(target_id, updates, target) user = get_user(required=True) push_notification("item:unlink", item=target_id, user=str(user.get(config.ID_FIELD))) app.on_archive_item_updated(updates, target, ITEM_UNLINK)
def delete(self, lookup): target_id = request.view_args['target_id'] archive_service = get_resource_service(ARCHIVE) target = archive_service.find_one(req=None, _id=target_id) self._validate_unlink(target) updates = {} takes_package = TakesPackageService().get_take_package(target) if takes_package and TakesPackageService().is_last_takes_package_item(target): # remove the take link PackageService().remove_refs_in_package(takes_package, target_id) if target.get('rewrite_of'): # remove the rewrite info ArchiveSpikeService().update_rewrite(target) if not takes_package and not target.get('rewrite_of'): # there is nothing to do raise SuperdeskApiError.badRequestError("Only takes and updates can be unlinked!") if target.get('rewrite_of'): updates['rewrite_of'] = None if target.get('anpa_take_key'): updates['anpa_take_key'] = None if target.get('rewrite_sequence'): updates['rewrite_sequence'] = None if target.get('sequence'): updates['sequence'] = None updates['event_id'] = generate_guid(type=GUID_TAG) archive_service.system_update(target_id, updates, target) user = get_user(required=True) push_notification('item:unlink', item=target_id, user=str(user.get(config.ID_FIELD))) app.on_archive_item_updated(updates, target, ITEM_UNLINK)