From 89e9d4a688d77c5b39a049355a5310d265be7e71 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Fri, 15 Nov 2024 16:58:06 +0100 Subject: [PATCH] fix(chalice): create role return list of projects --- ee/api/chalicelib/core/roles.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ee/api/chalicelib/core/roles.py b/ee/api/chalicelib/core/roles.py index f22262cd5d..ca1bf98123 100644 --- a/ee/api/chalicelib/core/roles.py +++ b/ee/api/chalicelib/core/roles.py @@ -101,12 +101,15 @@ def create(tenant_id, user_id, data: schemas.RolePayloadSchema): cur.execute(query=query) row = cur.fetchone() row["created_at"] = TimeUTC.datetime_to_timestamp(row["created_at"]) + row["projects"] = [] if not data.all_projects: role_id = row["role_id"] query = cur.mogrify(f"""INSERT INTO roles_projects(role_id, project_id) - VALUES {",".join(f"(%(role_id)s,%(project_id_{i})s)" for i in range(len(data.projects)))};""", + VALUES {",".join(f"(%(role_id)s,%(project_id_{i})s)" for i in range(len(data.projects)))} + RETURNING project_id;""", {"role_id": role_id, **{f"project_id_{i}": p for i, p in enumerate(data.projects)}}) cur.execute(query=query) + row["projects"] = [r["project_id"] for r in cur.fetchall()] return helper.dict_to_camel_case(row)