"""Features Utils.""" from flask import g from flask import request from owsrequest.context import get_request_context_from_headers from pythonfeatures import pythonfeatures from pythonfeatures.constants import split as split_constants from project_manager.constant import feature_flag from project_manager.models import ows_account as ows_account_model def get_rejections_from_cr_ff_status(vendor_id, distribution_format_id): """Get FF status.""" company_brand = ows_account_model.get_vendor_company_brand(vendor_id) vendor_data = ows_account_model.get_vendor(vendor_id) assigned_reviewer = vendor_data.get('assigned_reviewer') if vendor_data else None attributes = { 'vendor_id': str(vendor_id), 'company_brand_name': company_brand, 'distribution_format_id': str(distribution_format_id), 'owner': vendor_data.get('owner') if vendor_data else None, 'assigned_to': vendor_data.get('assigned_to') if vendor_data else None, 'assigned_reviewer': str(assigned_reviewer) if assigned_reviewer else None } feature_status = pythonfeatures.get_single_feature_by_attributes( feature_flag.REJECTIONS_FROM_CONTENTREVIEW, attributes, ).message return feature_status == split_constants.FEATURE_ENABLED def is_feature_flag_enabled(flag_name, use_account_context=False): """Check if users requested feature flag is enabled. Args: flag_name (str): name of the flag to be checked. use_account_context (boolean): use account context (if present) """ context = g.request_context if use_account_context: # if account headers are present it will use account context context = get_request_context_from_headers(request.headers) is_enabled = pythonfeatures.get_single_feature( flag_name, context ).message == split_constants.FEATURE_ENABLED g.ows.log.info(f'split {flag_name}: called with \ context_type {context.context_type} is {is_enabled}') return is_enabled