"""Model for Split.io feature flag service.""" from flask import g from owsresponse.status import OK from pythonfeatures import pythonfeatures from product_review.constants.error import SPLITIO_ERROR_CODE from product_review.util import exception as exception_util def _is_enabled(feature_name, attributes): """Check if feature is enabled.""" result = pythonfeatures.get_single_feature_by_attributes(feature_name, attributes) if result.status != OK: exception_util.raise_exception_for_ows_response( status=result.status, code=SPLITIO_ERROR_CODE, message=result.message, ) return result.message == "enabled" def is_enabled_prevent_approval_with_blockers(): """Check if block approval with errors is enabled.""" feature_attributes = {"identity_id": g.request_context.identity_id} return _is_enabled( "content_app_prevent_product_approval_with_blockers", feature_attributes ) def is_enabled_pdp_auth_check(feature_name): """Check if PDP authorization ff is enabled.""" feature_attributes = {"identity_id": g.request_context.identity_id} return _is_enabled(feature_name, feature_attributes) def is_enabled_escalate_to_product_manager(): """Check if escalate to product manager ff is enabled.""" feature_attributes = {"identity_id": g.request_context.identity_id} return _is_enabled("content_review_escalate_to_product_manager", feature_attributes) def is_enabled_complete_review_v2(vendor_id): """Check if complete review v2 ff is enabled.""" feature_attributes = {"vendor_id": str(vendor_id)} return _is_enabled("content_review_complete_review_v2", feature_attributes)