from internal.helpers import rds_query from product_packages.exceptions import InvalidRight def check_quota_for_right(current_package_id, right_name, current_value) -> int: for line in rds_query(f"""select quota from commons.package_rights pr where pr.package_id = %(current_package_id)s AND pr.right_id = (SELECT id FROM commons.rights WHERE name = %(right_name)s) """, {'right_name': right_name, 'current_package_id': current_package_id}): quota_value = line['quota'] return quota_value == -1 or quota_value > current_value raise InvalidRight(f"Don't know how to check for {right_name}")