"""Route handlers for Applications endpoints.""" from account.api import app from account.constants.connectors import NEO4J_DATABASE_NAME from account.constants.tenants import TenantType from account.logic.application import ( application as app_logic, collaborator as collaborator_app_logic, label_participant as label_participant_logic, subaccount as subaccount_app_logic, vendor as vendor_app_logic, ) from account.utils import handler_util from connector_neo4j import Neo4jSession from flask import request from owsresponse import response from owsresponse.adaptors.flask import flaskify @app.route('/vendor//applications', methods=['GET']) @handler_util.check_admin_access(tenant_type=TenantType.ACCOUNT, tenant_uuid_key='vendor_uuid') def get_vendor_applications(vendor_uuid): """Get applications and roles for a Vendor.""" return flaskify(vendor_app_logic.get_vendor_applications(vendor_uuid)) @app.route('/subaccount//applications', methods=['GET']) @handler_util.check_admin_access( tenant_type=TenantType.SUBACCOUNT, tenant_uuid_key='subaccount_uuid' ) def get_subaccount_applications(subaccount_uuid): """Get applications and roles for a Subaccount.""" return flaskify(subaccount_app_logic.get_subaccount_applications(subaccount_uuid)) @app.route('/collaborator//applications', methods=['GET']) @Neo4jSession(use_v2=True, database=NEO4J_DATABASE_NAME) @handler_util.check_admin_access( tenant_type=TenantType.COLLABORATOR, tenant_uuid_key='collaborator_uuid' ) def get_collaborator_applications(collaborator_uuid): """Get applications and roles for a Collaborator.""" return flaskify(collaborator_app_logic.get_collaborator_applications(collaborator_uuid)) @app.route('/label-participant//applications', methods=['GET']) @Neo4jSession(use_v2=True, database=NEO4J_DATABASE_NAME) @handler_util.check_admin_access( tenant_type=TenantType.LABEL_PARTICIPANT, tenant_uuid_key='lp_uuid' ) def get_label_participant_applications(lp_uuid): """Get applications and roles for a label participant.""" applications = label_participant_logic.get_lp_applications(lp_uuid) return flaskify(response.Response({'applications': applications})) @app.route('/applications/dataloader', methods=['POST']) def get_applications_by_ids(): """Endpoint to get applications by ids.""" application_ids = request.get_json() return flaskify(app_logic.get_applications_by_ids(application_ids)) @app.route('/roles/dataloader', methods=['POST']) def get_roles_by_ids(): """Endpoint to get roles by ids.""" role_ids = request.get_json() return flaskify(app_logic.get_roles_by_ids(role_ids))