"""Cypher for permission operations.""" VENDOR_ACCESS = """ MATCH(profile:Profile {profileId: toInteger($profile_id), profileType: toString($profile_type)}) OPTIONAL MATCH (profile)-[:HAS_ACCESS_TO|HAS_ADMIN_ACCESS_TO]->(vStar:Vendor {id: '*'}) CALL apoc.when( vStar IS NOT NULL, ' RETURN true AS has_access ', ' MATCH (profile)-[:HAS_ACCESS_TO|HAS_ADMIN_ACCESS_TO]->(v:Vendor) WHERE v.id IN resourceIds WITH COUNT(DISTINCT(v.id)) as cnt, SIZE(resourceIds) as sz RETURN cnt = sz AS has_access ', { profile: profile, vStart: vStar, resourceIds: $resource_ids } ) YIELD value RETURN value.has_access AS has_access """ # noqa:E501 SUBACCOUNT_ACCESS = """ MATCH(profile:Profile {profileId: toInteger($profile_id), profileType: toString($profile_type)}) OPTIONAL MATCH (profile)-[:HAS_ACCESS_TO|HAS_ADMIN_ACCESS_TO]->(vStar:Vendor {id: '*'}) CALL apoc.when( vStar IS NOT NULL, ' RETURN true AS has_access ', ' OPTIONAL MATCH(profile)-[:HAS_ACCESS_TO|HAS_ADMIN_ACCESS_TO]->(:Vendor)-[:OWNS]->(s1:SubAccount) WHERE s1.id IN resourceIds OPTIONAL MATCH(profile)-[:HAS_ACCESS_TO|HAS_ADMIN_ACCESS_TO]->(s2:SubAccount) WHERE s2.id IN resourceIds WITH resourceIds, COLLECT(s1.id) + COLLECT(s2.id) AS s_ids UNWIND s_ids AS s_id WITH resourceIds, COLLECT(DISTINCT s_id) AS d_s_ids RETURN SIZE(d_s_ids) = SIZE(resourceIds) AS has_access ', { profile: profile, vStart: vStar, resourceIds: $resource_ids } ) YIELD value RETURN value.has_access AS has_access """ # noqa:E501 TRACK_ACCESS = """ MATCH(profile:Profile {profileId: toInteger($profile_id), profileType: toString($profile_type)}) OPTIONAL MATCH (profile)-[:HAS_ACCESS_TO|HAS_ADMIN_ACCESS_TO]->(vStar:Vendor {id: '*'}) CALL apoc.when( vStar IS NOT NULL, ' RETURN true AS has_access ', ' OPTIONAL MATCH(profile)-[:HAS_ACCESS_TO|HAS_ADMIN_ACCESS_TO]->(r)<-[:BELONGS_TO]-(:Project)-[:INCLUDES]->(:Product:Orchard)-[:INCLUDES]->(t:Track:Orchard) WHERE t.id IN resourceIds WITH COUNT(DISTINCT(t.id)) as cnt, SIZE(resourceIds) as sz RETURN cnt = sz AS has_access ', { profile: profile, vStart: vStar, resourceIds: $resource_ids } ) YIELD value RETURN value.has_access AS has_access """ # noqa:E501