From 016dd9dfed469dfac59f5b02eb235be35eb788ad Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Mon, 6 Feb 2023 17:47:37 +0100 Subject: [PATCH 1/3] feat(chalice): fixes --- api/chalicelib/core/integrations_global.py | 4 +- api/chalicelib/core/tenants.py | 67 +++++------ ee/api/chalicelib/core/custom_metrics.py | 4 +- ee/api/chalicelib/core/integrations_global.py | 4 +- ee/api/chalicelib/core/tenants.py | 112 ++++++++---------- ee/api/schemas_ee.py | 8 +- 6 files changed, 89 insertions(+), 110 deletions(-) diff --git a/api/chalicelib/core/integrations_global.py b/api/chalicelib/core/integrations_global.py index f69fa99c0..66cd38a74 100644 --- a/api/chalicelib/core/integrations_global.py +++ b/api/chalicelib/core/integrations_global.py @@ -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() diff --git a/api/chalicelib/core/tenants.py b/api/chalicelib/core/tenants.py index cabcdae7b..5479178d8 100644 --- a/api/chalicelib/core/tenants.py +++ b/api/chalicelib/core/tenants.py @@ -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()) diff --git a/ee/api/chalicelib/core/custom_metrics.py b/ee/api/chalicelib/core/custom_metrics.py index e4dd9beb3..b7502edd9 100644 --- a/ee/api/chalicelib/core/custom_metrics.py +++ b/ee/api/chalicelib/core/custom_metrics.py @@ -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. \ diff --git a/ee/api/chalicelib/core/integrations_global.py b/ee/api/chalicelib/core/integrations_global.py index 8de504f09..e601a94cc 100644 --- a/ee/api/chalicelib/core/integrations_global.py +++ b/ee/api/chalicelib/core/integrations_global.py @@ -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() diff --git a/ee/api/chalicelib/core/tenants.py b/ee/api/chalicelib/core/tenants.py index 70d0bb5b7..30a87bd29 100644 --- a/ee/api/chalicelib/core/tenants.py +++ b/ee/api/chalicelib/core/tenants.py @@ -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()) diff --git a/ee/api/schemas_ee.py b/ee/api/schemas_ee.py index e09677775..f5a3b8de0 100644 --- a/ee/api/schemas_ee.py +++ b/ee/api/schemas_ee.py @@ -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: From f34b77af7430015d42e451e2449ff11c5581fc7d Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Mon, 6 Feb 2023 16:15:59 +0100 Subject: [PATCH 2/3] fix(ui) - password reset errors --- .../app/components/ForgotPassword/ForgotPassword.js | 12 ++++++++---- frontend/app/duck/user.js | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/frontend/app/components/ForgotPassword/ForgotPassword.js b/frontend/app/components/ForgotPassword/ForgotPassword.js index e931677bf..1cd40c679 100644 --- a/frontend/app/components/ForgotPassword/ForgotPassword.js +++ b/frontend/app/components/ForgotPassword/ForgotPassword.js @@ -3,7 +3,7 @@ import { connect } from 'react-redux'; import ReCAPTCHA from 'react-google-recaptcha'; import withPageTitle from 'HOCs/withPageTitle'; import { Form, Input, Loader, Button, Link, Icon, Message } from 'UI'; -import { requestResetPassword, resetPassword } from 'Duck/user'; +import { requestResetPassword, resetPassword, resetErrors } from 'Duck/user'; import { login as loginRoute } from 'App/routes'; import { withRouter } from 'react-router-dom'; import { validateEmail } from 'App/validate'; @@ -26,7 +26,7 @@ const checkDontMatch = (newPassword, newPasswordRepeat) => loading: state.getIn([ 'user', 'requestResetPassowrd', 'loading' ]) || state.getIn([ 'user', 'resetPassword', 'loading' ]), params: new URLSearchParams(props.location.search) }), - { requestResetPassword, resetPassword }, + { requestResetPassword, resetPassword, resetErrors }, ) @withPageTitle("Password Reset - OpenReplay") @withRouter @@ -42,7 +42,7 @@ export default class ForgotPassword extends React.PureComponent { }; handleSubmit = (token) => { - const { email, requested, code, password } = this.state; + const { email, password } = this.state; const { params } = this.props; const pass = params.get('pass') @@ -89,6 +89,10 @@ export default class ForgotPassword extends React.PureComponent { } } + componentWillUnmount() { + this.props.resetErrors() + } + render() { const { CAPTCHA_ENABLED } = this.state; const { errors, loading, params } = this.props; @@ -148,7 +152,7 @@ export default class ForgotPassword extends React.PureComponent { } { - requested && ( + requested && !errors && (
Reset password link has been sent to your email.
) } diff --git a/frontend/app/duck/user.js b/frontend/app/duck/user.js index b345cb053..f9cee9a34 100644 --- a/frontend/app/duck/user.js +++ b/frontend/app/duck/user.js @@ -15,6 +15,7 @@ const RESEND_EMAIL_VERIFICATION = new RequestTypes('user/RESEND_EMAIL_VERIFICATI const FETCH_CLIENT = new RequestTypes('user/FETCH_CLIENT'); export const UPDATE_PASSWORD = new RequestTypes('user/UPDATE_PASSWORD'); const PUT_CLIENT = new RequestTypes('user/PUT_CLIENT'); +const RESET_ERRORS = 'user/RESET_ERRORS'; const PUSH_NEW_SITE = 'user/PUSH_NEW_SITE'; const SET_ONBOARDING = 'user/SET_ONBOARDING'; @@ -52,6 +53,8 @@ export function setJwt(data) { const reducer = (state = initialState, action = {}) => { switch (action.type) { + case RESET_ERRORS: + return state.set('requestResetPassowrd', List()); case UPDATE_JWT: return state.set('jwt', action.data); case LOGIN.REQUEST: @@ -184,3 +187,9 @@ export function setOnboarding(state = false) { state }; } + +export function resetErrors() { + return { + type: RESET_ERRORS, + }; +} \ No newline at end of file From c77042dbcdd4aed3faa0fd37db0baf493dfadc1c Mon Sep 17 00:00:00 2001 From: Alex K Date: Mon, 6 Feb 2023 16:42:05 +0100 Subject: [PATCH 3/3] fix(backend): decrease deadclick time a bit --- backend/pkg/handlers/web/deadClick.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/pkg/handlers/web/deadClick.go b/backend/pkg/handlers/web/deadClick.go index 6377b074e..434e6c1ce 100644 --- a/backend/pkg/handlers/web/deadClick.go +++ b/backend/pkg/handlers/web/deadClick.go @@ -21,7 +21,7 @@ import ( Output event: IssueEvent */ -const CLICK_RELATION_TIME = 1400 +const CLICK_RELATION_TIME = 1234 type DeadClickDetector struct { lastTimestamp uint64