diff --git a/ee/api/chalicelib/core/roles.py b/ee/api/chalicelib/core/roles.py index f22262cd5..ca1bf9812 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)