def _validate_rewrite(self, original, update): """ Validates the article to be rewritten :param original: article to be rewritten :param update: article as the rewrite :raises: SuperdeskApiError """ if not original: raise SuperdeskApiError.notFoundError( message='Cannot find the article') if original.get(EMBARGO): raise SuperdeskApiError.badRequestError( "Rewrite of an Item having embargo isn't possible") if not original.get('event_id'): raise SuperdeskApiError.notFoundError( message='Event id does not exist') if original.get('rewritten_by'): raise SuperdeskApiError.badRequestError( message='Article has been rewritten before !') if not is_workflow_state_transition_valid('rewrite', original[ITEM_STATE]): raise InvalidStateTransitionError() if not TakesPackageService().is_last_takes_package_item(original): raise SuperdeskApiError.badRequestError( message="Only last take of the package can be rewritten.") if original.get('rewrite_of') and not (original.get(ITEM_STATE) in PUBLISH_STATES): raise SuperdeskApiError.badRequestError( message= "Rewrite is not published. Cannot rewrite the story again.") if update: # in case of associate as update if update.get('rewrite_of'): raise SuperdeskApiError.badRequestError( "Rewrite story has been used as update before !") if update.get(ITEM_STATE) in [ CONTENT_STATE.PUBLISHED, CONTENT_STATE.CORRECTED, CONTENT_STATE.KILLED, CONTENT_STATE.SCHEDULED, CONTENT_STATE.SPIKED ]: raise InvalidStateTransitionError() if update.get(ITEM_TYPE) not in [ CONTENT_TYPE.TEXT, CONTENT_TYPE.PREFORMATTED ]: raise SuperdeskApiError.badRequestError( "Rewrite story can only be text or pre-formatted !") if update.get('genre') and \ any(genre.get('value', '').lower() == BROADCAST_GENRE.lower() for genre in update.get('genre')): raise SuperdeskApiError.badRequestError( "Broadcast cannot be a update story !")
def _validate_rewrite(self, original, update): """Validates the article to be rewritten. :param original: article to be rewritten :param update: article as the rewrite :raises: SuperdeskApiError """ if not original: raise SuperdeskApiError.notFoundError(message=_('Cannot find the article')) if original.get(EMBARGO): raise SuperdeskApiError.badRequestError(_("Rewrite of an Item having embargo isn't possible")) if not original.get('event_id'): raise SuperdeskApiError.notFoundError(message=_('Event id does not exist')) if original.get('rewritten_by'): raise SuperdeskApiError.badRequestError(message=_('Article has been rewritten before !')) if (not is_workflow_state_transition_valid('rewrite', original[ITEM_STATE]) and not config.ALLOW_UPDATING_SCHEDULED_ITEMS): raise InvalidStateTransitionError() if ( original.get('rewrite_of') and not (original.get(ITEM_STATE) in PUBLISH_STATES) and not app.config['WORKFLOW_ALLOW_MULTIPLE_UPDATES'] ): raise SuperdeskApiError.badRequestError( message=_("Rewrite is not published. Cannot rewrite the story again.")) if update: # in case of associate as update if update.get('rewrite_of'): raise SuperdeskApiError.badRequestError(_("Rewrite story has been used as update before !")) if update.get(ITEM_STATE) in [CONTENT_STATE.PUBLISHED, CONTENT_STATE.CORRECTED, CONTENT_STATE.KILLED, CONTENT_STATE.RECALLED, CONTENT_STATE.SCHEDULED, CONTENT_STATE.SPIKED]: raise InvalidStateTransitionError() if update.get(ITEM_TYPE) not in [CONTENT_TYPE.TEXT, CONTENT_TYPE.PREFORMATTED]: raise SuperdeskApiError.badRequestError(_("Rewrite story can only be text or pre-formatted !")) if update.get('genre') and \ any(genre.get('value', '').lower() == BROADCAST_GENRE.lower() for genre in update.get('genre')): raise SuperdeskApiError.badRequestError(_("Broadcast cannot be a update story !")) if original.get('profile') and original.get('profile') != update.get('profile'): raise SuperdeskApiError.badRequestError(_("Rewrite item content profile does " "not match with Original item."))
def _validate_rewrite(self, original, update): """Validates the article to be rewritten. :param original: article to be rewritten :param update: article as the rewrite :raises: SuperdeskApiError """ if not original: raise SuperdeskApiError.notFoundError(message='Cannot find the article') if original.get(EMBARGO): raise SuperdeskApiError.badRequestError("Rewrite of an Item having embargo isn't possible") if not original.get('event_id'): raise SuperdeskApiError.notFoundError(message='Event id does not exist') if original.get('rewritten_by'): raise SuperdeskApiError.badRequestError(message='Article has been rewritten before !') if not is_workflow_state_transition_valid('rewrite', original[ITEM_STATE]): raise InvalidStateTransitionError() if original.get('rewrite_of') and not (original.get(ITEM_STATE) in PUBLISH_STATES): raise SuperdeskApiError.badRequestError(message="Rewrite is not published. Cannot rewrite the story again.") if update: # in case of associate as update if update.get('rewrite_of'): raise SuperdeskApiError.badRequestError("Rewrite story has been used as update before !") if update.get(ITEM_STATE) in [CONTENT_STATE.PUBLISHED, CONTENT_STATE.CORRECTED, CONTENT_STATE.KILLED, CONTENT_STATE.RECALLED, CONTENT_STATE.SCHEDULED, CONTENT_STATE.SPIKED]: raise InvalidStateTransitionError() if update.get(ITEM_TYPE) not in [CONTENT_TYPE.TEXT, CONTENT_TYPE.PREFORMATTED]: raise SuperdeskApiError.badRequestError("Rewrite story can only be text or pre-formatted !") if update.get('genre') and \ any(genre.get('value', '').lower() == BROADCAST_GENRE.lower() for genre in update.get('genre')): raise SuperdeskApiError.badRequestError("Broadcast cannot be a update story !") if original.get('profile') and original.get('profile') != update.get('profile'): raise SuperdeskApiError.badRequestError("Rewrite item content profile does " "not match with Original item.")
def _validate_rewrite(self, original, update): """Validates the article to be rewritten. :param original: article to be rewritten :param update: article as the rewrite :raises: SuperdeskApiError """ if not original: raise SuperdeskApiError.notFoundError( message=_("Cannot find the article")) embargo = original.get(SCHEDULE_SETTINGS, {}).get( "utc_{}".format(EMBARGO)) if original.get(EMBARGO) else None if embargo is not None and embargo > utcnow(): raise SuperdeskApiError.badRequestError( _("Rewrite of an Item having embargo isn't possible")) if not original.get("event_id"): raise SuperdeskApiError.notFoundError( message=_("Event id does not exist")) if original.get("rewritten_by"): raise SuperdeskApiError.badRequestError( message=_("Article has been rewritten before !")) if (not is_workflow_state_transition_valid("rewrite", original[ITEM_STATE]) and not config.ALLOW_UPDATING_SCHEDULED_ITEMS): raise InvalidStateTransitionError() if (original.get("rewrite_of") and not (original.get(ITEM_STATE) in PUBLISH_STATES) and not app.config["WORKFLOW_ALLOW_MULTIPLE_UPDATES"]): raise SuperdeskApiError.badRequestError(message=_( "Rewrite is not published. Cannot rewrite the story again.")) if update: # in case of associate as update if update.get("rewrite_of"): raise SuperdeskApiError.badRequestError( _("Rewrite story has been used as update before !")) if update.get(ITEM_STATE) in [ CONTENT_STATE.PUBLISHED, CONTENT_STATE.CORRECTED, CONTENT_STATE.KILLED, CONTENT_STATE.RECALLED, CONTENT_STATE.SCHEDULED, CONTENT_STATE.SPIKED, ]: raise InvalidStateTransitionError() if update.get(ITEM_TYPE) not in [ CONTENT_TYPE.TEXT, CONTENT_TYPE.PREFORMATTED ]: raise SuperdeskApiError.badRequestError( _("Rewrite story can only be text or pre-formatted !")) if update.get("genre") and any( genre.get("value", "").lower() == BROADCAST_GENRE.lower() for genre in update.get("genre")): raise SuperdeskApiError.badRequestError( _("Broadcast cannot be a update story !")) if original.get("profile") and str(original.get("profile")) != str( update.get("profile")): raise SuperdeskApiError.badRequestError( _("Rewrite item content profile does " "not match with Original item."))