"""Logic Tier for Ad Action Comment.""" from podcast.constants.feature_flag import FEATURE_PODCAST_IA_RESTRUCTURE from podcast.logic import email from podcast.logic import user as user_logic from podcast.logic import user_v2 as user_v2_logic from podcast.models import ad_action_comment as ad_action_comment_model from podcast.utils import feature_flag_utils def create_ad_action_comment(data): """Create ad action comment. Args: data (dict): The data to create Returns: dict: containing a dict with the created ad action. """ current_user = user_logic.get_current_user() user_logic.current_user_has_read_only_access_then_raise(current_user['role']) if feature_flag_utils.get_feature_flag(FEATURE_PODCAST_IA_RESTRUCTURE): user_v2_logic.current_user_has_access_to_ad_action_or_raise(data['ad_action_id'], current_user) else: user_logic.current_user_has_access_to_ad_action_or_raise(data['ad_action_id'], current_user) ad_action_new_comment = ad_action_comment_model.create_ad_action_comment(data, current_user['id']) email.send_new_ad_action_comment(data['ad_action_id'], ad_action_new_comment, current_user['id']) return ad_action_new_comment def delete_ad_action_comment(ad_action_comment_id): """Delete ad action comment. Args: ad_action_comment_id (int): The id to delete Returns: dict: containing a dict with the deleted ad action. """ current_user = user_logic.get_current_user() user_logic.current_user_has_read_only_access_then_raise(current_user['role']) return ad_action_comment_model.delete_ad_action_comment(ad_action_comment_id, current_user['id']) def get_ad_action_comments(ad_action_id, limit, offset): """Get ad action comments. Args: ad_action_id (int): The id for the ad action for which we want to fetch comments. limit (int): Number of records to return per page. offset (int): The page numbner. Returns: list(dict): the ad action comments. """ current_user = user_logic.get_current_user() if feature_flag_utils.get_feature_flag(FEATURE_PODCAST_IA_RESTRUCTURE): user_v2_logic.current_user_has_access_to_ad_action_or_raise(ad_action_id, current_user) else: user_logic.current_user_has_access_to_ad_action_or_raise(ad_action_id, current_user) ad_action_comments = ad_action_comment_model.get_ad_action_comments( ad_action_id, limit, offset) return ad_action_comments def get_ad_action_comments_count(ad_action_ids): """Get ad action comments count by ad action ids. Args: ad_action_ids (list of int): The ids for the ad actions for which we want to fetch comments. Returns: list(dict): the ad action comments count. """ # validate the user user_logic.get_current_user() return ad_action_comment_model.get_ad_action_comments_count(ad_action_ids)