From cbf389f6f94077bac189e4b55653763448968e33 Mon Sep 17 00:00:00 2001 From: Kraiem Taha Yassine Date: Mon, 2 Sep 2024 18:05:22 +0200 Subject: [PATCH] Dev (#2526) * fix(chalice): fixed Math-operators validation refactor(chalice): search for sessions that have events for heatmaps * refactor(chalice): search for sessions that have at least 1 location event for heatmaps * fix(chalice): fixed Math-operators validation refactor(chalice): search for sessions that have events for heatmaps * refactor(chalice): search for sessions that have at least 1 location event for heatmaps * feat(chalice): autocomplete return top 10 with stats * fix(chalice): fixed autocomplete top 10 meta-filters * refactor(chalice): changed scope to scopeState with 0|1|2 values --- api/chalicelib/core/scope.py | 13 ++++++------- api/routers/core_dynamic.py | 2 +- api/schemas/schemas.py | 7 +------ ee/api/chalicelib/core/scope.py | 13 ++++++------- ee/api/routers/core_dynamic.py | 2 +- .../schema/db/init_dbs/postgresql/1.20.0/1.20.0.sql | 2 +- .../schema/db/init_dbs/postgresql/init_schema.sql | 2 +- .../schema/db/init_dbs/postgresql/1.20.0/1.20.0.sql | 2 +- .../schema/db/init_dbs/postgresql/init_schema.sql | 2 +- 9 files changed, 19 insertions(+), 26 deletions(-) diff --git a/api/chalicelib/core/scope.py b/api/chalicelib/core/scope.py index 44d3a8963..f2d013cb3 100644 --- a/api/chalicelib/core/scope.py +++ b/api/chalicelib/core/scope.py @@ -1,6 +1,5 @@ from cachetools import cached, TTLCache -import schemas from chalicelib.utils import helper from chalicelib.utils import pg_client @@ -8,19 +7,19 @@ cache = TTLCache(maxsize=1, ttl=60) @cached(cache) -def get_scope(tenant_id) -> schemas.ScopeType: +def get_scope(tenant_id) -> int: with pg_client.PostgresClient() as cur: - query = cur.mogrify(f"""SELECT scope + query = cur.mogrify(f"""SELECT scope_state FROM public.tenants;""") cur.execute(query) - return helper.dict_to_camel_case(cur.fetchone())["scope"] + return helper.dict_to_camel_case(cur.fetchone())["scope_state"] -def update_scope(tenant_id, scope: schemas.ScopeType): +def update_scope(tenant_id, scope: int): with pg_client.PostgresClient() as cur: query = cur.mogrify(f"""UPDATE public.tenants - SET scope = %(scope)s;""", - {"scope": scope}) + SET scope_state = %(scope_state)s;""", + {"scope_state": scope}) cur.execute(query) if tenant_id in cache: cache.pop(tenant_id) diff --git a/api/routers/core_dynamic.py b/api/routers/core_dynamic.py index 43bee3696..78218643e 100644 --- a/api/routers/core_dynamic.py +++ b/api/routers/core_dynamic.py @@ -77,7 +77,7 @@ def login_user(response: JSONResponse, spot: Optional[bool] = False, data: schem 'jwt': r.pop('jwt'), 'data': { "user": r, - "scope": scope.get_scope(-1) + "scopeState": scope.get_scope(-1) } } response.set_cookie(key="refreshToken", value=refresh_token, path=COOKIE_PATH, diff --git a/api/schemas/schemas.py b/api/schemas/schemas.py index ef9bd8df6..02598a808 100644 --- a/api/schemas/schemas.py +++ b/api/schemas/schemas.py @@ -1687,10 +1687,5 @@ class TagCreate(TagUpdate): ignoreDeadClick: bool = Field(default=False) -class ScopeType(str, Enum): - FULL_OR = "full" - SPOT_ONLY = "spot" - - class ScopeSchema(BaseModel): - scope: ScopeType = Field(default=ScopeType.FULL_OR) + scope: int = Field(default=1, ge=1, le=2) diff --git a/ee/api/chalicelib/core/scope.py b/ee/api/chalicelib/core/scope.py index 9c8e48fd5..ce4c789e9 100644 --- a/ee/api/chalicelib/core/scope.py +++ b/ee/api/chalicelib/core/scope.py @@ -1,6 +1,5 @@ from cachetools import cached, TTLCache -import schemas from chalicelib.utils import helper from chalicelib.utils import pg_client @@ -8,22 +7,22 @@ cache = TTLCache(maxsize=1000, ttl=60) @cached(cache) -def get_scope(tenant_id) -> schemas.ScopeType: +def get_scope(tenant_id) -> int: with pg_client.PostgresClient() as cur: - query = cur.mogrify(f"""SELECT scope + query = cur.mogrify(f"""SELECT scope_state FROM public.tenants WHERE tenant_id=%(tenant_id)s;""", {"tenant_id": tenant_id}) cur.execute(query) - return helper.dict_to_camel_case(cur.fetchone())["scope"] + return helper.dict_to_camel_case(cur.fetchone())["scope_state"] -def update_scope(tenant_id, scope: schemas.ScopeType): +def update_scope(tenant_id, scope: int): with pg_client.PostgresClient() as cur: query = cur.mogrify(f"""UPDATE public.tenants - SET scope = %(scope)s + SET scope_state = %(scope_state)s WHERE tenant_id=%(tenant_id)s;""", - {"scope": scope, "tenant_id": tenant_id}) + {"scope_state": scope, "tenant_id": tenant_id}) cur.execute(query) if tenant_id in cache: cache.pop(tenant_id) diff --git a/ee/api/routers/core_dynamic.py b/ee/api/routers/core_dynamic.py index 28fa11e12..b429e06aa 100644 --- a/ee/api/routers/core_dynamic.py +++ b/ee/api/routers/core_dynamic.py @@ -81,7 +81,7 @@ def login_user(response: JSONResponse, spot: Optional[bool] = False, data: schem content = { 'jwt': r.pop('jwt'), 'data': { - "scope": scope.get_scope(r["tenantId"]), + "scopeState": scope.get_scope(r["tenantId"]), "user": r } } diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.20.0/1.20.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.20.0/1.20.0.sql index de6dfb0aa..3e5309c4c 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.20.0/1.20.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.20.0/1.20.0.sql @@ -51,7 +51,7 @@ CREATE TABLE IF NOT EXISTS or_cache.autocomplete_top_values ); ALTER TABLE IF EXISTS public.tenants - ADD COLUMN IF NOT EXISTS scope text NOT NULL DEFAULT 'full'; + ADD COLUMN IF NOT EXISTS scope_state smallint NOT NULL DEFAULT 2; COMMIT; diff --git a/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql b/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql index 66bf91793..987bc18e7 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql @@ -105,7 +105,7 @@ CREATE TABLE public.tenants t_users integer NOT NULL DEFAULT 1, t_integrations integer NOT NULL DEFAULT 0, last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT), - scope text NOT NULL DEFAULT 'full' + scope_state smallint NOT NULL DEFAULT 0 ); diff --git a/scripts/schema/db/init_dbs/postgresql/1.20.0/1.20.0.sql b/scripts/schema/db/init_dbs/postgresql/1.20.0/1.20.0.sql index 5b62e277b..3e5646302 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.20.0/1.20.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.20.0/1.20.0.sql @@ -40,7 +40,7 @@ CREATE TABLE IF NOT EXISTS or_cache.autocomplete_top_values ); ALTER TABLE IF EXISTS public.tenants - ADD COLUMN IF NOT EXISTS scope text NOT NULL DEFAULT 'full'; + ADD COLUMN IF NOT EXISTS scope_state smallint NOT NULL DEFAULT 2; COMMIT; diff --git a/scripts/schema/db/init_dbs/postgresql/init_schema.sql b/scripts/schema/db/init_dbs/postgresql/init_schema.sql index 15cc114de..24229317f 100644 --- a/scripts/schema/db/init_dbs/postgresql/init_schema.sql +++ b/scripts/schema/db/init_dbs/postgresql/init_schema.sql @@ -104,7 +104,7 @@ CREATE TABLE public.tenants t_users integer NOT NULL DEFAULT 1, t_integrations integer NOT NULL DEFAULT 0, last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT), - scope text NOT NULL DEFAULT 'full', + scope_state smallint NOT NULL DEFAULT 0, CONSTRAINT onerow_uni CHECK (tenant_id = 1) );