Skip to content

Commit

Permalink
refactor(chalice): return owner name for cards and dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
tahayk committed Jul 2, 2024
1 parent ce62cb9 commit 627e968
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/chalicelib/core/custom_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def search_all(project_id, user_id, data: schemas.SearchCardsSchema, include_ser
query = cur.mogrify(
f"""SELECT metric_id, project_id, user_id, name, is_public, created_at, edited_at,
metric_type, metric_of, metric_format, metric_value, view_type, is_pinned,
dashboards, owner_email, default_config AS config, thumbnail
dashboards, owner_email, owner_name, default_config AS config, thumbnail
FROM metrics
{sub_join}
LEFT JOIN LATERAL (SELECT COALESCE(jsonb_agg(connected_dashboards.* ORDER BY is_public,name),'[]'::jsonb) AS dashboards
Expand All @@ -500,7 +500,7 @@ def search_all(project_id, user_id, data: schemas.SearchCardsSchema, include_ser
AND project_id = %(project_id)s
AND ((dashboards.user_id = %(user_id)s OR is_public))) AS connected_dashboards
) AS connected_dashboards ON (TRUE)
LEFT JOIN LATERAL (SELECT email AS owner_email
LEFT JOIN LATERAL (SELECT email AS owner_email, name AS owner_name
FROM users
WHERE deleted_at ISNULL
AND users.user_id = metrics.user_id
Expand Down
4 changes: 2 additions & 2 deletions api/chalicelib/core/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def create_dashboard(project_id, user_id, data: schemas.CreateDashboardSchema):

def get_dashboards(project_id, user_id):
with pg_client.PostgresClient() as cur:
pg_query = f"""SELECT *, owner_email
pg_query = f"""SELECT *, owner_email, owner_name
FROM dashboards
LEFT JOIN LATERAL (SELECT email AS owner_email
LEFT JOIN LATERAL (SELECT email AS owner_email, name AS owner_name
FROM users
WHERE deleted_at ISNULL
AND users.user_id = dashboards.user_id
Expand Down
6 changes: 3 additions & 3 deletions ee/api/chalicelib/core/custom_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def get_sessions_by_card_id(project_id, user_id, metric_id, data: schemas.CardSe
# No need for this because UI is sending the full payload
# card: dict = get_card(metric_id=metric_id, project_id=project_id, user_id=user_id, flatten=False)
# if card is None:
# return None
# return None
# metric: schemas.CardSchema = schemas.CardSchema(**card)
# metric: schemas.CardSchema = __merge_metric_with_data(metric=metric, data=data)
if not card_exists(metric_id=metric_id, project_id=project_id, user_id=user_id):
Expand Down Expand Up @@ -521,7 +521,7 @@ def search_all(project_id, user_id, data: schemas.SearchCardsSchema, include_ser
query = cur.mogrify(
f"""SELECT metric_id, project_id, user_id, name, is_public, created_at, edited_at,
metric_type, metric_of, metric_format, metric_value, view_type, is_pinned,
dashboards, owner_email, default_config AS config, thumbnail
dashboards, owner_email, owner_name, default_config AS config, thumbnail
FROM metrics
{sub_join}
LEFT JOIN LATERAL (SELECT COALESCE(jsonb_agg(connected_dashboards.* ORDER BY is_public,name),'[]'::jsonb) AS dashboards
Expand All @@ -532,7 +532,7 @@ def search_all(project_id, user_id, data: schemas.SearchCardsSchema, include_ser
AND project_id = %(project_id)s
AND ((dashboards.user_id = %(user_id)s OR is_public))) AS connected_dashboards
) AS connected_dashboards ON (TRUE)
LEFT JOIN LATERAL (SELECT email AS owner_email
LEFT JOIN LATERAL (SELECT email AS owner_email, name AS owner_name
FROM users
WHERE deleted_at ISNULL
AND users.user_id = metrics.user_id
Expand Down

0 comments on commit 627e968

Please sign in to comment.