Beispiel #1
0
async def get_realm_status(conn, organization_id, realm_id):
    query = (q_realm(organization_id=Parameter("$1"),
                     realm_id=Parameter("$2")).select(
                         "encryption_revision",
                         "maintenance_started_by",
                         "maintenance_started_on",
                         "maintenance_type",
                     )).get_sql()

    rep = await conn.fetchrow(query, organization_id, realm_id)
    if not rep:
        raise RealmNotFoundError(f"Realm `{realm_id}` doesn't exist")
    return rep
Beispiel #2
0
    STR_TO_REALM_ROLE,
    STR_TO_REALM_MAINTENANCE_TYPE,
    q_user,
    q_user_internal_id,
    q_user_can_read_vlob,
    q_device,
    q_realm_internal_id,
    q_realm,
)

_q_get_realm_status = (q_realm(
    organization_id=Parameter("$1"), realm_id=Parameter("$2")).select(
        q_user_can_read_vlob(organization_id=Parameter("$1"),
                             realm_id=Parameter("$2"),
                             user_id=Parameter("$3")).as_("has_access"),
        "encryption_revision",
        q_device(_id=Parameter("maintenance_started_by")).select(
            "device_id").as_("maintenance_started_by"),
        "maintenance_started_on",
        "maintenance_type",
    )).get_sql()

_q_get_current_roles = """
SELECT DISTINCT ON(user_) ({}), role
FROM  realm_user_role
WHERE realm = ({})
ORDER BY user_, certified_on DESC
""".format(
    q_user(_id=Parameter("user_")).select("user_id"),
    q_realm_internal_id(organization_id=Parameter("$1"),
                        realm_id=Parameter("$2")),
Beispiel #3
0
from parsec.backend.postgresql.utils import query
from parsec.backend.postgresql.message import send_message
from parsec.backend.postgresql.tables import (
    STR_TO_REALM_ROLE,
    q_realm_internal_id,
    q_realm,
    q_realm_user_role,
    q_user_internal_id,
    q_device_internal_id,
)


_q_get_realm_status = (
    q_realm(organization_id=Parameter("$1"), realm_id=Parameter("$2")).select(
        "encryption_revision",
        "maintenance_started_by",
        "maintenance_started_on",
        "maintenance_type",
    )
).get_sql()


_q_get_roles = """
SELECT
({}),
({})
FROM UNNEST($3::VARCHAR[]) AS needle_user_id
""".format(
    q_user_internal_id(organization_id=Parameter("$1"), user_id=Parameter("needle_user_id")),
    q_realm_user_role(
        organization_id=Parameter("$1"),
        user_id=Parameter("needle_user_id"),
Beispiel #4
0
    t_block_data,
    q_block,
    q_realm,
    q_user_can_read_vlob,
    q_user_can_write_vlob,
    q_user_internal_id,
    q_realm_internal_id,
    q_organization_internal_id,
    q_device_internal_id,
)
from parsec.backend.postgresql.realm_queries.maintenance import get_realm_status, RealmNotFoundError


_q_get_realm_id_from_block_id = (
    q_block(organization_id=Parameter("$1"), block_id=Parameter("$2"))
    .select(q_realm(_id=t_block.realm).select("realm_id"))
    .get_sql()
)


_q_get_block_meta = (
    q_block(organization_id=Parameter("$1"), block_id=Parameter("$2"))
    .select(
        "deleted_on",
        q_user_can_read_vlob(
            user=q_user_internal_id(organization_id=Parameter("$1"), user_id=Parameter("$3")),
            realm=t_block.realm,
        ),
    )
    .get_sql()
)