def on_update(self, updates, original): # check if we are trying to kill and item that is contained in normal non takes package if is_item_in_package(original): raise SuperdeskApiError.badRequestError(message='This item is in a package' + ' it needs to be removed before the item can be killed') updates[ITEM_OPERATION] = ITEM_KILL super().on_update(updates, original) self.takes_package_service.process_killed_takes_package(original)
def on_update(self, updates, original): # check if we are trying to kill and item that is contained in normal non takes package if is_item_in_package(original): raise SuperdeskApiError.badRequestError(message='This item is in a package' + ' it needs to be removed before the item can be killed') updates['pubstatus'] = PUB_STATUS.CANCELED super().on_update(updates, original) updates[ITEM_OPERATION] = ITEM_KILL self.takes_package_service.process_killed_takes_package(original) get_resource_service('archive_broadcast').spike_item(original)
def _validate_item(self, original): """ Raises an exception if the item is linked in a non-take package, the idea being that you don't whant to inadvertently remove thing from packages, this force that to be done as a conscious action. :param original: :raise: An exception or nothing """ if is_item_in_package(original): raise SuperdeskApiError.badRequestError(message="This item is in a package" + " it needs to be removed before the item can be spiked")
def _validate_item(self, original): """ Raises an exception if the item is linked in a non-take package, the idea being that you don't whant to inadvertently remove thing from packages, this force that to be done as a conscious action. :param original: :raise: An exception or nothing """ if is_item_in_package(original): raise SuperdeskApiError.badRequestError( message="This item is in a package" + " it needs to be removed before the item can be spiked")
def on_update(self, updates, original): # check if we are trying to kill and item that is contained in normal non takes package if is_item_in_package(original): raise SuperdeskApiError.badRequestError( message='This item is in a package' + ' it needs to be removed before the item can be killed') updates['pubstatus'] = PUB_STATUS.CANCELED super().on_update(updates, original) updates[ITEM_OPERATION] = ITEM_KILL self.takes_package_service.process_killed_takes_package(original) get_resource_service('archive_broadcast').spike_item(original)
def validate_delete_action(self, doc, allow_all_types=False): """Runs on delete of archive item. Overriding to validate the item being killed is actually eligible for kill. Validates the following: 1. Is item of type Text? 2. Is item a Broadcast Script? 3. Does item acts as a Master Story for any of the existing broadcasts? 4. Is item available in production or part of a normal package? 5. Is the associated Digital Story is available in production or part of normal package? 6. If item is a Take then is any take available in production or part of normal package? :param doc: represents the article in archived collection :type doc: dict :param allow_all_types: represents if different types of documents are allowed to be killed :type doc: bool :raises SuperdeskApiError.badRequestError() if any of the above validation conditions fail. """ bad_req_error = SuperdeskApiError.badRequestError id_field = doc[config.ID_FIELD] item_id = doc["item_id"] doc["item_id"] = id_field doc[config.ID_FIELD] = item_id if not allow_all_types and doc[ITEM_TYPE] != CONTENT_TYPE.TEXT: raise bad_req_error(message=_( "Only Text articles are allowed to be Killed in Archived repo") ) if is_genre(doc, BROADCAST_GENRE): raise bad_req_error(message=_( "Killing of Broadcast Items isn't allowed in Archived repo")) if get_resource_service( "archive_broadcast").get_broadcast_items_from_master_story( doc, True): raise bad_req_error(message=_( "Can't kill as this article acts as a Master Story for existing broadcast(s)" )) if get_resource_service(ARCHIVE).find_one(req=None, _id=doc[GUID_FIELD]): raise bad_req_error(message=_( "Can't Kill as article is still available in production")) if not allow_all_types and is_item_in_package(doc): raise bad_req_error( message=_("Can't kill as article is part of a Package")) takes_package_id = self._get_take_package_id(doc) if takes_package_id: if get_resource_service(ARCHIVE).find_one(req=None, _id=takes_package_id): raise bad_req_error(message=_( "Can't Kill as the Digital Story is still available in production" )) req = ParsedRequest() req.sort = '[("%s", -1)]' % config.VERSION takes_package = list( self.get(req=req, lookup={"item_id": takes_package_id})) if not takes_package: raise bad_req_error(message=_( "Digital Story of the article not found in Archived repo")) takes_package = takes_package[0] if not allow_all_types and is_item_in_package(takes_package): raise bad_req_error(message=_( "Can't kill as Digital Story is part of a Package")) for takes_ref in self._get_package_refs(takes_package): if takes_ref[RESIDREF] != doc[GUID_FIELD]: if get_resource_service(ARCHIVE).find_one( req=None, _id=takes_ref[RESIDREF]): raise bad_req_error(message=_( "Can't Kill as Take(s) are still available in production" )) take = list( self.get(req=None, lookup={"item_id": takes_ref[RESIDREF]})) if not take: raise bad_req_error(message=_( "One of Take(s) not found in Archived repo")) if not allow_all_types and is_item_in_package(take[0]): raise bad_req_error(message=_( "Can't kill as one of Take(s) is part of a Package" )) doc["item_id"] = item_id doc[config.ID_FIELD] = id_field
def on_delete(self, doc): """ Overriding to validate the item being killed is actually eligible for kill. Validates the following: 1. Is item of type Text? 2. Is item a Broadcast Script? 3. Does item acts as a Master Story for any of the existing broadcasts? 4. Is item available in production or part of a normal package? 5. Is the associated Digital Story is available in production or part of normal package? 6. If item is a Take then is any take available in production or part of normal package? :param doc: represents the article in archived collection :type doc: dict :raises SuperdeskApiError.badRequestError() if any of the above validation conditions fail. """ bad_req_error = SuperdeskApiError.badRequestError id_field = doc[config.ID_FIELD] item_id = doc['item_id'] doc['item_id'] = id_field doc[config.ID_FIELD] = item_id if doc[ITEM_TYPE] != CONTENT_TYPE.TEXT: raise bad_req_error(message='Only Text articles are allowed to Kill in Archived repo') if is_genre(doc, BROADCAST_GENRE): raise bad_req_error(message="Killing of Broadcast Items isn't allowed in Archived repo") if get_resource_service('archive_broadcast').get_broadcast_items_from_master_story(doc, True): raise bad_req_error(message="Can't kill as this article acts as a Master Story for existing broadcast(s)") if get_resource_service(ARCHIVE).find_one(req=None, _id=doc[GUID_FIELD]): raise bad_req_error(message="Can't Kill as article is still available in production") if is_item_in_package(doc): raise bad_req_error(message="Can't kill as article is part of a Package") takes_package_service = TakesPackageService() takes_package_id = takes_package_service.get_take_package_id(doc) if takes_package_id: if get_resource_service(ARCHIVE).find_one(req=None, _id=takes_package_id): raise bad_req_error(message="Can't Kill as the Digital Story is still available in production") req = ParsedRequest() req.sort = '[("%s", -1)]' % config.VERSION takes_package = list(self.get(req=req, lookup={'item_id': takes_package_id})) if not takes_package: raise bad_req_error(message='Digital Story of the article not found in Archived repo') takes_package = takes_package[0] if is_item_in_package(takes_package): raise bad_req_error(message="Can't kill as Digital Story is part of a Package") for takes_ref in takes_package_service.get_package_refs(takes_package): if takes_ref[RESIDREF] != doc[GUID_FIELD]: if get_resource_service(ARCHIVE).find_one(req=None, _id=takes_ref[RESIDREF]): raise bad_req_error(message="Can't Kill as Take(s) are still available in production") take = list(self.get(req=None, lookup={'item_id': takes_ref[RESIDREF]})) if not take: raise bad_req_error(message='One of Take(s) not found in Archived repo') if is_item_in_package(take[0]): raise bad_req_error(message="Can't kill as one of Take(s) is part of a Package") doc['item_id'] = item_id doc[config.ID_FIELD] = id_field