Skip to content

Commit

Permalink
fix(chalice): create role return list of projects
Browse files Browse the repository at this point in the history
  • Loading branch information
tahayk committed Nov 15, 2024
1 parent 3048195 commit 89e9d4a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ee/api/chalicelib/core/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 89e9d4a

Please sign in to comment.