From f147ab0bd1f5888540a04ec65a0980f7b2eb2e2a Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Mon, 6 Sep 2021 23:56:51 +0100 Subject: [PATCH] feat(api): changed change password response --- api/chalicelib/core/users.py | 23 +++++++++++++++++++++-- ee/api/chalicelib/core/users.py | 24 ++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/api/chalicelib/core/users.py b/api/chalicelib/core/users.py index a87a6023f..917328910 100644 --- a/api/chalicelib/core/users.py +++ b/api/chalicelib/core/users.py @@ -426,8 +426,27 @@ def change_password(tenant_id, user_id, email, old_password, new_password): if auth is None: return {"errors": ["wrong password"]} changes = {"password": new_password, "generatedPassword": False} - return {"data": update(tenant_id=tenant_id, user_id=user_id, changes=changes), - "jwt": authenticate(email, new_password)["jwt"]} + user = update(tenant_id=tenant_id, user_id=user_id, changes=changes) + r = authenticate(user['email'], new_password) + tenant_id = r.pop("tenantId") + + r["limits"] = { + "teamMember": -1, + "projects": -1, + "metadata": metadata.get_remaining_metadata_with_count(tenant_id)} + + c = tenants.get_by_tenant_id(tenant_id) + c.pop("createdAt") + c["projects"] = projects.get_projects(tenant_id=tenant_id, recording_state=True, recorded=True, + stack_integrations=True) + c["smtp"] = helper.has_smtp() + return { + 'jwt': r.pop('jwt'), + 'data': { + "user": r, + "client": c + } + } def set_password_invitation(user_id, new_password): diff --git a/ee/api/chalicelib/core/users.py b/ee/api/chalicelib/core/users.py index 034a9549d..6c3434255 100644 --- a/ee/api/chalicelib/core/users.py +++ b/ee/api/chalicelib/core/users.py @@ -436,8 +436,27 @@ def change_password(tenant_id, user_id, email, old_password, new_password): if auth is None: return {"errors": ["wrong password"]} changes = {"password": new_password, "generatedPassword": False} - return {"data": update(tenant_id=tenant_id, user_id=user_id, changes=changes), - "jwt": authenticate(email, new_password)["jwt"]} + user = update(tenant_id=tenant_id, user_id=user_id, changes=changes) + r = authenticate(user['email'], new_password) + + tenant_id = r.pop("tenantId") + r["limits"] = { + "teamMember": -1, + "projects": -1, + "metadata": metadata.get_remaining_metadata_with_count(tenant_id)} + + c = tenants.get_by_tenant_id(tenant_id) + c.pop("createdAt") + c["projects"] = projects.get_projects(tenant_id=tenant_id, recording_state=True, recorded=True, + stack_integrations=True) + c["smtp"] = helper.has_smtp() + return { + 'jwt': r.pop('jwt'), + 'data': { + "user": r, + "client": c, + } + } def set_password_invitation(tenant_id, user_id, new_password): @@ -457,6 +476,7 @@ def set_password_invitation(tenant_id, user_id, new_password): c.pop("createdAt") c["projects"] = projects.get_projects(tenant_id=tenant_id, recording_state=True, recorded=True, stack_integrations=True) + c["smtp"] = helper.has_smtp() return { 'jwt': r.pop('jwt'), 'data': {