"""Reference Transaction Type Group handlers.""" from flask import Blueprint from flask import request from owsrequest import flask_request from owsresponse import response from owsresponse.adaptors.flask import flaskify from abacus_contract.constants import error from abacus_contract.logic import reference_transaction_type_group as logic from abacus_contract.utils import authorization reference_transaction_type_group_api = Blueprint( 'reference_transaction_type_group_api', __name__, ) @reference_transaction_type_group_api.route( '/reference-transaction-type-group/group-admin/', methods=['GET'] ) def get_transaction_type_groups_by_group_admin(group_admin: str): """Get list of reference_transaction_type_groups by group_admin. Args: group_admin (str): one of REFERENCE_TRANSACTION_TYPE_GROUP_ADMIN """ access_rule_decision = flask_request.verify_rules_access_standalone(request) if not access_rule_decision: authorized = authorization.pdp_authorize_resource( # Id of 0 means "all reference transaction types" # This resource type is all or nothing, permissions-wise. resource_id=0, resource_type='reference_transaction_type', ) if not authorized: return flaskify( response.create_error_response( code=error.ERROR_CODE_FORBIDDEN, message=error.ERROR_MESSAGE_FORBIDDEN_USER, status=403, ) ) return flaskify(logic.get_groups_by_group_admin(group_admin)) @reference_transaction_type_group_api.route( '/reference-transaction-type-group//' 'reference-transaction-types', methods=['GET'] ) def get_transaction_types_by_group(reference_transaction_type_group_id: int): """Get reference_transaction_types by parent reference_transaction_type_group. Args: reference_transaction_type_group_id (int): ID of the parent group """ access_rule_decision = flask_request.verify_rules_access_standalone(request) if not access_rule_decision: authorized = authorization.pdp_authorize_resource( # Id of 0 means "all reference transaction types" # This resource type is all or nothing, permissions-wise. resource_id=0, resource_type='reference_transaction_type', ) if not authorized: return flaskify( response.create_error_response( code=error.ERROR_CODE_FORBIDDEN, message=error.ERROR_MESSAGE_FORBIDDEN_USER, status=403, ) ) return flaskify( logic.get_transaction_types_by_group(reference_transaction_type_group_id) ) @reference_transaction_type_group_api.route( '/reference-transaction-type-group/' 'reference_transaction_type_group_transaction_types', methods=['GET'] ) def get_transaction_type_group_transaction_types(): """Get a list of reference_transaction_types and their transaction_type_group.""" access_rule_decision = flask_request.verify_rules_access_standalone(request) if not access_rule_decision: authorized = authorization.pdp_authorize_resource( # Id of 0 means "all reference transaction types" # This resource type is all or nothing, permissions-wise. resource_id=0, resource_type='reference_transaction_type', ) if not authorized: return flaskify( response.create_error_response( code=error.ERROR_CODE_FORBIDDEN, message=error.ERROR_MESSAGE_FORBIDDEN_USER, status=403, ) ) return flaskify( logic.get_transaction_type_group_transaction_types() ) @reference_transaction_type_group_api.route( '/reference-transaction-type-groups', methods=['GET'] ) def get_transaction_type_groups(): """Get a list of all reference transaction type groups.""" access_rule_decision = flask_request.verify_rules_access_standalone(request) if not access_rule_decision: authorized = authorization.pdp_authorize_resource( # Id of 0 means "all reference transaction types" # This resource type is all or nothing, permissions-wise. resource_id=0, resource_type='reference_transaction_type', ) if not authorized: return flaskify( response.create_error_response( code=error.ERROR_CODE_FORBIDDEN, message=error.ERROR_MESSAGE_FORBIDDEN_USER, status=403, ) ) return flaskify( logic.get_transaction_type_groups() )