Api v1.15.0 (#1607)

* fix(chalice): fixed project's authorizer
* fix(chalice): fixed search session by request's duration
* fix(chalice): fixed search session by request's status code
* fix(chalice): fixed update modules
This commit is contained in:
Kraiem Taha Yassine 2023-11-03 20:14:52 +01:00 committed by GitHub
parent f1e5562fee
commit dbb613c752
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 111 additions and 59 deletions

View file

@ -889,7 +889,7 @@ def search_query_parts(data: schemas.SessionsSearchPayloadSchema, error_status,
apply = True
elif f.type == schemas.FetchFilterType._status_code:
event_where.append(
sh.multi_conditions(f"main.status_code {f.operator.value} %({e_k_f})s::integer", f.value,
sh.multi_conditions(f"main.status_code {f.operator} %({e_k_f})s::integer", f.value,
value_key=e_k_f))
apply = True
elif f.type == schemas.FetchFilterType._method:
@ -898,7 +898,7 @@ def search_query_parts(data: schemas.SessionsSearchPayloadSchema, error_status,
apply = True
elif f.type == schemas.FetchFilterType._duration:
event_where.append(
sh.multi_conditions(f"main.duration {f.operator.value} %({e_k_f})s::integer", f.value,
sh.multi_conditions(f"main.duration {f.operator} %({e_k_f})s::integer", f.value,
value_key=e_k_f))
apply = True
elif f.type == schemas.FetchFilterType._request_body:

View file

@ -17,59 +17,6 @@ def __generate_invitation_token():
return secrets.token_urlsafe(64)
def get_user_settings(user_id):
# read user settings from users.settings:jsonb column
with pg_client.PostgresClient() as cur:
cur.execute(
cur.mogrify(
f"""SELECT
settings
FROM public.users
WHERE users.deleted_at IS NULL
AND users.user_id=%(user_id)s
LIMIT 1""",
{"user_id": user_id})
)
return helper.dict_to_camel_case(cur.fetchone())
def update_user_module(user_id, data: schemas.ModuleStatus):
# example data = {"settings": {"modules": ['ASSIST', 'METADATA']}
# update user settings from users.settings:jsonb column only update settings.modules
# if module property is not exists, it will be created
# if module property exists, it will be updated, modify here and call update_user_settings
# module is a single element to be added or removed
settings = get_user_settings(user_id)["settings"]
if settings is None:
settings = {}
if settings.get("modules") is None:
settings["modules"] = []
if data.status and data.module not in settings["modules"]:
settings["modules"].append(data.module)
elif not data.status and data.module in settings["modules"]:
settings["modules"].remove(data.module)
return update_user_settings(user_id, settings)
def update_user_settings(user_id, settings):
# update user settings from users.settings:jsonb column
with pg_client.PostgresClient() as cur:
cur.execute(
cur.mogrify(
f"""UPDATE public.users
SET settings = %(settings)s
WHERE users.user_id = %(user_id)s
AND deleted_at IS NULL
RETURNING settings;""",
{"user_id": user_id, "settings": json.dumps(settings)})
)
return helper.dict_to_camel_case(cur.fetchone())
def create_new_member(email, invitation_token, admin, name, owner=False):
with pg_client.PostgresClient() as cur:
query = cur.mogrify(f"""\
@ -736,3 +683,56 @@ def get_user_role(tenant_id, user_id):
{"user_id": user_id})
)
return helper.dict_to_camel_case(cur.fetchone())
def get_user_settings(user_id):
# read user settings from users.settings:jsonb column
with pg_client.PostgresClient() as cur:
cur.execute(
cur.mogrify(
f"""SELECT
settings
FROM public.users
WHERE users.deleted_at IS NULL
AND users.user_id=%(user_id)s
LIMIT 1""",
{"user_id": user_id})
)
return helper.dict_to_camel_case(cur.fetchone())
def update_user_module(user_id, data: schemas.ModuleStatus):
# example data = {"settings": {"modules": ['ASSIST', 'METADATA']}
# update user settings from users.settings:jsonb column only update settings.modules
# if module property is not exists, it will be created
# if module property exists, it will be updated, modify here and call update_user_settings
# module is a single element to be added or removed
settings = get_user_settings(user_id)["settings"]
if settings is None:
settings = {}
if settings.get("modules") is None:
settings["modules"] = []
if data.status and data.module not in settings["modules"]:
settings["modules"].append(data.module)
elif not data.status and data.module in settings["modules"]:
settings["modules"].remove(data.module)
return update_user_settings(user_id, settings)
def update_user_settings(user_id, settings):
# update user settings from users.settings:jsonb column
with pg_client.PostgresClient() as cur:
cur.execute(
cur.mogrify(
f"""UPDATE public.users
SET settings = %(settings)s
WHERE users.user_id = %(user_id)s
AND deleted_at IS NULL
RETURNING settings;""",
{"user_id": user_id, "settings": json.dumps(settings)})
)
return helper.dict_to_camel_case(cur.fetchone())

View file

@ -642,7 +642,7 @@ def generate_new_tenant_token(context: schemas.CurrentContext = Depends(OR_conte
@app.post('/users/modules', tags=['users'])
def update_user_module(context: schemas.CurrentContext = Depends(OR_context),
data: schemas.ModuleStatus = Body(...)):
return users.update_user_module(context.user_id, data)
return {"data": users.update_user_module(context.user_id, data)}
@app.get('/notifications', tags=['notifications'])
@ -859,4 +859,3 @@ async def check_recording_status(project_id: int):
@public_app.get('/', tags=["health"])
def health_check():
return {}

View file

@ -1062,7 +1062,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
apply = True
elif f.type == schemas.FetchFilterType._status_code:
event_where.append(
_multiple_conditions(f"main.status {f.operator.value} %({e_k_f})s", f.value,
_multiple_conditions(f"main.status {f.operator} %({e_k_f})s", f.value,
value_key=e_k_f))
events_conditions[-1]["condition"].append(event_where[-1])
apply = True
@ -1073,7 +1073,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu
apply = True
elif f.type == schemas.FetchFilterType._duration:
event_where.append(
_multiple_conditions(f"main.duration {f.operator.value} %({e_k_f})s", f.value,
_multiple_conditions(f"main.duration {f.operator} %({e_k_f})s", f.value,
value_key=e_k_f))
events_conditions[-1]["condition"].append(event_where[-1])
apply = True

View file

@ -936,3 +936,56 @@ def restore_sso_user(user_id, tenant_id, email, admin, name, origin, role_id, in
query
)
return helper.dict_to_camel_case(cur.fetchone())
def get_user_settings(user_id):
# read user settings from users.settings:jsonb column
with pg_client.PostgresClient() as cur:
cur.execute(
cur.mogrify(
f"""SELECT
settings
FROM public.users
WHERE users.deleted_at IS NULL
AND users.user_id=%(user_id)s
LIMIT 1""",
{"user_id": user_id})
)
return helper.dict_to_camel_case(cur.fetchone())
def update_user_module(user_id, data: schemas.ModuleStatus):
# example data = {"settings": {"modules": ['ASSIST', 'METADATA']}
# update user settings from users.settings:jsonb column only update settings.modules
# if module property is not exists, it will be created
# if module property exists, it will be updated, modify here and call update_user_settings
# module is a single element to be added or removed
settings = get_user_settings(user_id)["settings"]
if settings is None:
settings = {}
if settings.get("modules") is None:
settings["modules"] = []
if data.status and data.module not in settings["modules"]:
settings["modules"].append(data.module)
elif not data.status and data.module in settings["modules"]:
settings["modules"].remove(data.module)
return update_user_settings(user_id, settings)
def update_user_settings(user_id, settings):
# update user settings from users.settings:jsonb column
with pg_client.PostgresClient() as cur:
cur.execute(
cur.mogrify(
f"""UPDATE public.users
SET settings = %(settings)s
WHERE users.user_id = %(user_id)s
AND deleted_at IS NULL
RETURNING settings;""",
{"user_id": user_id, "settings": json.dumps(settings)})
)
return helper.dict_to_camel_case(cur.fetchone())