"""Application Unsafe Handlers.""" from oto.adaptors.flask import flaskify from flask import request from product_digital.api import app from product_digital.auth import only_for_identity from product_digital.logic import unsafe_methods from product_digital import config @app.route("/product/upc/", methods=["DELETE"]) @only_for_identity(config.DELETE_PRODUCT_IDENTITY) def UNSAFE_delete_product_by_upc(upc: str): """Delete a product by UPC. This method is only accessible by the DELETE_PRODUCT_IDENTITY. Please research all methods marked UNSAFE before using them in different contexts. This method can only be used to delete products with the `SMEAnalyticsDummy` products. Args: upc (str): the upc of the product to delete Returns: flask.response: success if the request has the correct identity, failure otherwise """ return flaskify(unsafe_methods.UNSAFE_hard_delete_product(upc)) @app.route("/product//display_upc", methods=["PUT"]) @only_for_identity([config.UPDATE_DISPLAY_UPC_GRPS_IDENTITY, config.UPDATE_DISPLAY_UPC_DDEX_IDENTITY]) def UNSAFE_update_display_upc(product_id: int): """Update a products display_upc. This method is only accessible by the DELETE_PRODUCT_IDENTITY. Please research all methods marked UNSAFE before using them in different contexts. Args: product_id (int): the product_id of the product to be updated Returns: flask.response: success if the request has the correct identity, failure otherwise """ display_upc = request.get_json().get("display_upc") return flaskify( unsafe_methods.UNSAFE_update_display_upc(product_id, display_upc)) @app.route("/product//soft_delete", methods=["DELETE"]) @only_for_identity(config.PRODUCT_SOFT_DELETE_IDENTITY) def UNSAFE_soft_delete(product_id: int): """Update a products deletions to Y. This method is only accessible by the PRODUCT_SOFT_DELETE_IDENTITY. Please research all methods marked UNSAFE before using them in different contexts. Args: product_id (int): the product_id of the product to be updated Returns: flask.response: success if the request has the correct identity, failure otherwise """ return flaskify(unsafe_methods.UNSAFE_soft_delete(product_id))