feat(chalice): fixes
This commit is contained in:
parent
13357a9c25
commit
016dd9dfed
6 changed files with 89 additions and 110 deletions
|
|
@ -51,10 +51,10 @@ def get_global_integrations_status(tenant_id, user_id, project_id):
|
|||
AND provider='elasticsearch')) AS {schemas.IntegrationType.elasticsearch.value},
|
||||
EXISTS((SELECT 1
|
||||
FROM public.webhooks
|
||||
WHERE type='slack')) AS {schemas.IntegrationType.slack.value},
|
||||
WHERE type='slack' AND deleted_at ISNULL)) AS {schemas.IntegrationType.slack.value},
|
||||
EXISTS((SELECT 1
|
||||
FROM public.webhooks
|
||||
WHERE type='msteams')) AS {schemas.IntegrationType.ms_teams.value};""",
|
||||
WHERE type='msteams' AND deleted_at ISNULL)) AS {schemas.IntegrationType.ms_teams.value};""",
|
||||
{"user_id": user_id, "tenant_id": tenant_id, "project_id": project_id})
|
||||
)
|
||||
current_integrations = cur.fetchone()
|
||||
|
|
|
|||
|
|
@ -6,59 +6,50 @@ from chalicelib.core import users, license
|
|||
|
||||
def get_by_tenant_id(tenant_id):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(
|
||||
f"""SELECT
|
||||
tenants.tenant_id,
|
||||
tenants.name,
|
||||
tenants.api_key,
|
||||
tenants.created_at,
|
||||
'{license.EDITION}' AS edition,
|
||||
openreplay_version() AS version_number,
|
||||
tenants.opt_out
|
||||
FROM public.tenants
|
||||
LIMIT 1;""",
|
||||
{"tenantId": tenant_id}))
|
||||
query = cur.mogrify(f"""SELECT tenants.tenant_id,
|
||||
tenants.name,
|
||||
tenants.api_key,
|
||||
tenants.created_at,
|
||||
'{license.EDITION}' AS edition,
|
||||
openreplay_version() AS version_number,
|
||||
tenants.opt_out
|
||||
FROM public.tenants
|
||||
LIMIT 1;""",
|
||||
{"tenantId": tenant_id})
|
||||
cur.execute(query=query)
|
||||
return helper.dict_to_camel_case(cur.fetchone())
|
||||
|
||||
|
||||
def get_by_api_key(api_key):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(
|
||||
f"""SELECT
|
||||
1 AS tenant_id,
|
||||
tenants.name,
|
||||
tenants.created_at
|
||||
FROM public.tenants
|
||||
WHERE tenants.api_key = %(api_key)s
|
||||
LIMIT 1;""",
|
||||
{"api_key": api_key})
|
||||
)
|
||||
query = cur.mogrify(f"""SELECT 1 AS tenant_id,
|
||||
tenants.name,
|
||||
tenants.created_at
|
||||
FROM public.tenants
|
||||
WHERE tenants.api_key = %(api_key)s
|
||||
LIMIT 1;""",
|
||||
{"api_key": api_key})
|
||||
cur.execute(query=query)
|
||||
return helper.dict_to_camel_case(cur.fetchone())
|
||||
|
||||
|
||||
def generate_new_api_key(tenant_id):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(
|
||||
f"""UPDATE public.tenants
|
||||
SET api_key=generate_api_key(20)
|
||||
RETURNING api_key;""",
|
||||
{"tenant_id": tenant_id})
|
||||
)
|
||||
query = cur.mogrify(f"""UPDATE public.tenants
|
||||
SET api_key=generate_api_key(20)
|
||||
RETURNING api_key;""",
|
||||
{"tenant_id": tenant_id})
|
||||
cur.execute(query=query)
|
||||
return helper.dict_to_camel_case(cur.fetchone())
|
||||
|
||||
|
||||
def edit_client(tenant_id, changes):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(f"""\
|
||||
UPDATE public.tenants
|
||||
SET {", ".join([f"{helper.key_to_snake_case(k)} = %({k})s" for k in changes.keys()])}
|
||||
RETURNING name, opt_out;""",
|
||||
{"tenantId": tenant_id, **changes})
|
||||
)
|
||||
query = cur.mogrify(f"""UPDATE public.tenants
|
||||
SET {", ".join([f"{helper.key_to_snake_case(k)} = %({k})s" for k in changes.keys()])}
|
||||
RETURNING name, opt_out;""",
|
||||
{"tenant_id": tenant_id, **changes})
|
||||
cur.execute(query=query)
|
||||
return helper.dict_to_camel_case(cur.fetchone())
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -489,8 +489,8 @@ def delete(project_id, metric_id, user_id):
|
|||
RETURNING data;""",
|
||||
{"metric_id": metric_id, "project_id": project_id, "user_id": user_id})
|
||||
)
|
||||
# for EE only
|
||||
row = cur.fetchone()
|
||||
# for EE only
|
||||
row = cur.fetchone()
|
||||
if row:
|
||||
if row["data"] and not sessions_favorite.favorite_session_exists(session_id=row["data"]["sessionId"]):
|
||||
keys = sessions_mobs. \
|
||||
|
|
|
|||
|
|
@ -51,10 +51,10 @@ def get_global_integrations_status(tenant_id, user_id, project_id):
|
|||
AND provider='elasticsearch')) AS {schemas.IntegrationType.elasticsearch.value},
|
||||
EXISTS((SELECT 1
|
||||
FROM public.webhooks
|
||||
WHERE type='slack' AND tenant_id=%(tenant_id)s)) AS {schemas.IntegrationType.slack.value},
|
||||
WHERE type='slack' AND tenant_id=%(tenant_id)s AND deleted_at ISNULL)) AS {schemas.IntegrationType.slack.value},
|
||||
EXISTS((SELECT 1
|
||||
FROM public.webhooks
|
||||
WHERE type='msteams' AND tenant_id=%(tenant_id)s)) AS {schemas.IntegrationType.ms_teams.value};""",
|
||||
WHERE type='msteams' AND tenant_id=%(tenant_id)s AND deleted_at ISNULL)) AS {schemas.IntegrationType.ms_teams.value};""",
|
||||
{"user_id": user_id, "tenant_id": tenant_id, "project_id": project_id})
|
||||
)
|
||||
current_integrations = cur.fetchone()
|
||||
|
|
|
|||
|
|
@ -6,88 +6,76 @@ from chalicelib.utils import pg_client
|
|||
|
||||
def get_by_tenant_key(tenant_key):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(
|
||||
f"""SELECT
|
||||
tenants.tenant_id,
|
||||
tenants.name,
|
||||
tenants.api_key,
|
||||
tenants.created_at,
|
||||
'{license.EDITION}' AS edition,
|
||||
openreplay_version() AS version_number,
|
||||
tenants.opt_out,
|
||||
tenants.tenant_key
|
||||
FROM public.tenants
|
||||
WHERE tenants.tenant_key = %(tenant_key)s
|
||||
AND tenants.deleted_at ISNULL
|
||||
LIMIT 1;""",
|
||||
{"tenant_key": tenant_key})
|
||||
)
|
||||
query = cur.mogrify(f"""SELECT tenants.tenant_id,
|
||||
tenants.name,
|
||||
tenants.api_key,
|
||||
tenants.created_at,
|
||||
'{license.EDITION}' AS edition,
|
||||
openreplay_version() AS version_number,
|
||||
tenants.opt_out,
|
||||
tenants.tenant_key
|
||||
FROM public.tenants
|
||||
WHERE tenants.tenant_key = %(tenant_key)s
|
||||
AND tenants.deleted_at ISNULL
|
||||
LIMIT 1;""",
|
||||
{"tenant_key": tenant_key})
|
||||
cur.execute(query=query)
|
||||
return helper.dict_to_camel_case(cur.fetchone())
|
||||
|
||||
|
||||
def get_by_tenant_id(tenant_id):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(
|
||||
f"""SELECT
|
||||
tenants.tenant_id,
|
||||
tenants.name,
|
||||
tenants.api_key,
|
||||
tenants.created_at,
|
||||
'{license.EDITION}' AS edition,
|
||||
openreplay_version() AS version_number,
|
||||
tenants.opt_out,
|
||||
tenants.tenant_key
|
||||
FROM public.tenants
|
||||
WHERE tenants.tenant_id = %(tenantId)s
|
||||
AND tenants.deleted_at ISNULL
|
||||
LIMIT 1;""",
|
||||
{"tenantId": tenant_id})
|
||||
)
|
||||
query = cur.mogrify(f"""SELECT tenants.tenant_id,
|
||||
tenants.name,
|
||||
tenants.api_key,
|
||||
tenants.created_at,
|
||||
'{license.EDITION}' AS edition,
|
||||
openreplay_version() AS version_number,
|
||||
tenants.opt_out,
|
||||
tenants.tenant_key
|
||||
FROM public.tenants
|
||||
WHERE tenants.tenant_id = %(tenantId)s
|
||||
AND tenants.deleted_at ISNULL
|
||||
LIMIT 1;""",
|
||||
{"tenantId": tenant_id})
|
||||
cur.execute(query=query)
|
||||
return helper.dict_to_camel_case(cur.fetchone())
|
||||
|
||||
|
||||
def get_by_api_key(api_key):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(
|
||||
f"""SELECT
|
||||
tenants.tenant_id,
|
||||
tenants.name,
|
||||
tenants.created_at
|
||||
FROM public.tenants
|
||||
WHERE tenants.api_key = %(api_key)s
|
||||
AND tenants.deleted_at ISNULL
|
||||
LIMIT 1;""",
|
||||
{"api_key": api_key})
|
||||
)
|
||||
query = cur.mogrify(f"""SELECT tenants.tenant_id,
|
||||
tenants.name,
|
||||
tenants.created_at
|
||||
FROM public.tenants
|
||||
WHERE tenants.api_key = %(api_key)s
|
||||
AND tenants.deleted_at ISNULL
|
||||
LIMIT 1;""",
|
||||
{"api_key": api_key})
|
||||
cur.execute(query=query)
|
||||
return helper.dict_to_camel_case(cur.fetchone())
|
||||
|
||||
|
||||
def generate_new_api_key(tenant_id):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(
|
||||
f"""UPDATE public.tenants
|
||||
SET api_key=generate_api_key(20)
|
||||
WHERE tenant_id= %(tenant_id)s AND deleted_at ISNULL
|
||||
RETURNING api_key;""",
|
||||
{"tenant_id": tenant_id})
|
||||
)
|
||||
query = cur.mogrify(f"""UPDATE public.tenants
|
||||
SET api_key=generate_api_key(20)
|
||||
WHERE tenant_id= %(tenant_id)s
|
||||
AND deleted_at ISNULL
|
||||
RETURNING api_key;""",
|
||||
{"tenant_id": tenant_id})
|
||||
cur.execute(query=query)
|
||||
return helper.dict_to_camel_case(cur.fetchone())
|
||||
|
||||
|
||||
def edit_client(tenant_id, changes):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify(f"""\
|
||||
UPDATE public.tenants
|
||||
SET {", ".join([f"{helper.key_to_snake_case(k)} = %({k})s" for k in changes.keys()])}
|
||||
WHERE tenant_id= %(tenant_id)s AND deleted_at ISNULL
|
||||
RETURNING name, opt_out;""",
|
||||
{"tenantId": tenant_id, **changes})
|
||||
)
|
||||
query = cur.mogrify(f"""UPDATE public.tenants
|
||||
SET {", ".join([f"{helper.key_to_snake_case(k)} = %({k})s" for k in changes.keys()])}
|
||||
WHERE tenant_id= %(tenant_id)s AND deleted_at ISNULL
|
||||
RETURNING name, opt_out;""",
|
||||
{"tenant_id": tenant_id, **changes})
|
||||
cur.execute(query=query)
|
||||
return helper.dict_to_camel_case(cur.fetchone())
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ class CurrentContext(schemas.CurrentContext):
|
|||
|
||||
|
||||
class RolePayloadSchema(BaseModel):
|
||||
name: str = Field(...)
|
||||
description: Optional[str] = Field(None)
|
||||
name: str = Field(..., min_length=1, max_length=40)
|
||||
description: Optional[str] = Field(default=None)
|
||||
permissions: List[Permissions] = Field(...)
|
||||
all_projects: bool = Field(True)
|
||||
projects: List[int] = Field([])
|
||||
all_projects: bool = Field(default=True)
|
||||
projects: List[int] = Field(default=[])
|
||||
_transform_name = validator('name', pre=True, allow_reuse=True)(schemas.remove_whitespace)
|
||||
|
||||
class Config:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue