예제 #1
0
from parsec.backend.postgresql.message import send_message
from parsec.backend.postgresql.utils import (
    Q,
    query,
    q_organization_internal_id,
    q_user,
    q_device,
    q_device_internal_id,
    q_realm,
    q_realm_internal_id,
)

_q_get_realm_status = Q(
    q_realm(
        organization_id="$organization_id",
        realm_id="$realm_id",
        select=
        f"encryption_revision, { q_device(_id='maintenance_started_by', select='device_id') } maintenance_started_by, maintenance_started_on, maintenance_type",
    ))


async def get_realm_status(conn, organization_id: OrganizationID,
                           realm_id: RealmID) -> RealmStatus:
    rep = await conn.fetchrow(*_q_get_realm_status(
        organization_id=organization_id.str, realm_id=realm_id.uuid))
    if not rep:
        raise RealmNotFoundError(f"Realm `{realm_id}` doesn't exist")

    return RealmStatus(
        maintenance_type=MaintenanceType(rep["maintenance_type"])
        if rep["maintenance_type"] else None,
        maintenance_started_on=rep["maintenance_started_on"],
예제 #2
0
    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
        FROM realm_user_role
        WHERE
            user_ = { q_user_internal_id(organization_id="$organization_id", user_id="needle_user_id") }
            AND realm = { q_realm_internal_id(organization_id="$organization_id", realm_id="$realm_id") }
        ORDER BY certified_on DESC LIMIT 1
    )
FROM UNNEST($users_ids::VARCHAR[]) AS needle_user_id