from parsec.api.protocol import OrganizationID, UserID, DeviceID from parsec.backend.backend_events import BackendEvent from parsec.backend.user import UserError, UserNotFoundError, UserAlreadyExistsError, UserInvitation from parsec.backend.postgresql.handler import send_signal from parsec.backend.postgresql.utils import ( Q, query, q_organization_internal_id, q_device, q_device_internal_id, q_user, ) _q_user_exists = Q( q_user(organization_id="$organization_id", user_id="$user_id", select="TRUE")) async def _user_exists(conn, organization_id: OrganizationID, user_id: UserID): user_result = await conn.fetchrow( *_q_user_exists(organization_id=organization_id, user_id=user_id)) return bool(user_result) _q_insert_invitation = Q(f""" INSERT INTO user_invitation ( organization, creator, user_id, created_on
from parsec.backend.postgresql.handler import send_signal from parsec.backend.postgresql.message import send_message from parsec.backend.postgresql.utils import ( Q, query, q_user, q_user_internal_id, q_device_internal_id, q_realm, q_realm_internal_id, STR_TO_REALM_ROLE, ) _q_get_user_profile = Q( q_user(organization_id="$organization_id", user_id="$user_id", select="profile")) _q_get_realm_status = Q( q_realm( organization_id="$organization_id", realm_id="$realm_id", select= "encryption_revision, maintenance_started_by, maintenance_started_on, maintenance_type", )) _q_get_roles = Q(f""" SELECT { q_user_internal_id(organization_id="$organization_id", user_id="needle_user_id") }, ( SELECT role
) _q_revoke_user = Q(f""" UPDATE user_ SET revoked_user_certificate = $revoked_user_certificate, revoked_user_certifier = { q_device_internal_id(organization_id="$organization_id", device_id="$revoked_user_certifier") }, revoked_on = $revoked_on WHERE organization = { q_organization_internal_id("$organization_id") } AND user_id = $user_id AND revoked_on IS NULL """) _q_revoke_user_error = Q( q_user(organization_id="$organization_id", user_id="$user_id", select="revoked_on")) @query(in_transaction=True) async def query_revoke_user( conn, organization_id: OrganizationID, user_id: UserID, revoked_user_certificate: bytes, revoked_user_certifier: DeviceID, revoked_on: Optional[pendulum.DateTime] = None, ) -> None: result = await conn.execute(*_q_revoke_user( organization_id=organization_id, user_id=user_id,