"""Vendor model in Neo4j.""" import textwrap import uuid from permissions.connectors import neo4j as neo4j_connector from permissions.constants import constants from permissions.types import Vendor def get_directly_accessible_vendors_by_profile( identity_id: uuid.UUID, profile_id: int, profile_type: str, ) -> list[Vendor]: """Get accessible vendors for the identity and profile. Args: identity_id (str): identity uuid profile_id (str): profile id profile_type (str): profile type Returns: list[Vendor]: list of accessible vendors. """ # query params kwargs = { 'profile_id': profile_id, 'profile_type': profile_type, 'identity_id': str(identity_id), } query = textwrap.dedent(""" MATCH (i:Identity {id: $identity_id})-[:HAS_PROFILE]-> (p:Profile {profileType: $profile_type, profileId: $profile_id}) MATCH (p)-[:HAS_ACCESS_TO|HAS_ADMIN_ACCESS_TO]->(v:Vendor) RETURN v.uuid as vendor_uuid, v.vendorId as vendor_id""") with neo4j_connector.db_session(access_mode=constants.NEO4j_READ_ACCESS) as session: result = session.run(query, **kwargs) return [Vendor(vendor_uuid=r['vendor_uuid'], vendor_id=r['vendor_id']) for r in result]