Skip to content

Commit e9e1a4a

Browse files
committed
fix: adding steward details
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 14c7dc4 commit e9e1a4a

3 files changed

Lines changed: 55 additions & 21 deletions

File tree

backend/src/api/public/v1/packages/listPackages.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ export async function listPackages(req: Request, res: Response): Promise<void> {
6868

6969
const qx = await getPackagesQx()
7070
const [{ rows, total }, statusCounts] = await Promise.all([
71-
listPackagesForApi(qx, { page, pageSize, status, sortBy, sortDir, ...filterOpts }),
71+
listPackagesForApi(qx, {
72+
page,
73+
pageSize,
74+
status,
75+
sortBy,
76+
sortDir,
77+
...filterOpts,
78+
includeStewards: true,
79+
}),
7280
getPackageStatusCounts(qx, filterOpts),
7381
])
7482

@@ -83,7 +91,7 @@ export async function listPackages(req: Request, res: Response): Promise<void> {
8391
openVulns: r.openVulns,
8492
stewardshipId: r.stewardshipId ?? null,
8593
stewardship: (r.stewardshipStatus ?? 'unassigned') as StewardshipStatus,
86-
stewards: null,
94+
stewards: r.stewards ?? [],
8795
}))
8896

8997
ok(res, {

backend/src/api/public/v1/packages/openapi.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ components:
9191
type: string
9292
description: Auth0 sub of the assigned steward.
9393
example: abc123
94-
name:
94+
username:
95+
type:
96+
- string
97+
- 'null'
98+
description: Username of the steward. Null if not available.
99+
example: jrodriguez
100+
displayName:
95101
type:
96102
- string
97103
- 'null'
@@ -206,12 +212,10 @@ components:
206212
stewardship:
207213
$ref: '#/components/schemas/StewardshipStatus'
208214
stewards:
209-
description: Assigned stewards or null.
210-
oneOf:
211-
- type: array
212-
items:
213-
$ref: '#/components/schemas/Steward'
214-
- type: 'null'
215+
description: Assigned stewards. Empty array if none.
216+
type: array
217+
items:
218+
$ref: '#/components/schemas/Steward'
215219

216220
# ── Package detail ───────────────────────────────────────────────────────────
217221

services/libs/data-access-layer/src/osspckgs/stewardships.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ export async function assignSteward(
261261
metadata: JSON.stringify({
262262
userId: data.userId,
263263
role: data.role,
264+
...(data.displayName != null ? { stewardDisplayName: data.displayName } : {}),
264265
...(data.note ? { note: data.note } : {}),
265266
}),
266267
},
@@ -350,6 +351,17 @@ export interface ActivityFeedRow {
350351
total: string
351352
}
352353

354+
const STEWARD_MENTIONED_JOIN = `
355+
LEFT JOIN stewards st_mentioned
356+
ON sa.activity_type = 'steward_added'
357+
AND st_mentioned.user_id = (sa.metadata->>'userId')`
358+
359+
const STEWARD_DISPLAY_NAME_METADATA = `CASE
360+
WHEN sa.activity_type = 'steward_added' AND st_mentioned.display_name IS NOT NULL
361+
THEN COALESCE(sa.metadata, '{}'::jsonb) || jsonb_build_object('stewardDisplayName', st_mentioned.display_name)
362+
ELSE sa.metadata
363+
END`
364+
353365
export async function listStewardshipActivity(
354366
qx: QueryExecutor,
355367
opts: { page: number; pageSize: number },
@@ -366,13 +378,14 @@ export async function listStewardshipActivity(
366378
sa.actor_type AS "actorType",
367379
sa.activity_type AS "activityType",
368380
sa.content AS content,
369-
sa.metadata AS metadata,
381+
${STEWARD_DISPLAY_NAME_METADATA} AS metadata,
370382
s.status AS "stewardshipStatus",
371383
sa.created_at AS "createdAt",
372384
COUNT(*) OVER()::text AS total
373385
FROM stewardship_activity sa
374386
JOIN stewardships s ON s.id = sa.stewardship_id
375387
JOIN packages p ON p.id = s.package_id
388+
${STEWARD_MENTIONED_JOIN}
376389
ORDER BY sa.created_at DESC, sa.id DESC
377390
LIMIT $(limit) OFFSET $(offset)
378391
`,
@@ -430,16 +443,17 @@ export async function listPackageHistory(
430443
stewardshipId: string,
431444
): Promise<PackageHistoryEvent[]> {
432445
const rows: Array<Record<string, unknown>> = await qx.select(
433-
`SELECT id::text AS id,
434-
actor_user_id AS "actorUserId",
435-
actor_type AS "actorType",
436-
activity_type AS "activityType",
437-
content,
438-
metadata,
439-
created_at AS "createdAt"
440-
FROM stewardship_activity
441-
WHERE stewardship_id = $(stewardshipId)::bigint
442-
ORDER BY created_at DESC`,
446+
`SELECT sa.id::text AS id,
447+
sa.actor_user_id AS "actorUserId",
448+
sa.actor_type AS "actorType",
449+
sa.activity_type AS "activityType",
450+
sa.content,
451+
${STEWARD_DISPLAY_NAME_METADATA} AS metadata,
452+
sa.created_at AS "createdAt"
453+
FROM stewardship_activity sa
454+
${STEWARD_MENTIONED_JOIN}
455+
WHERE sa.stewardship_id = $(stewardshipId)::bigint
456+
ORDER BY sa.created_at DESC`,
443457
{ stewardshipId },
444458
)
445459
return rows.map((r) => ({
@@ -753,12 +767,13 @@ export async function listMyActivity(
753767
sa.actor_type AS "actorType",
754768
sa.activity_type AS "activityType",
755769
sa.content AS content,
756-
sa.metadata AS metadata,
770+
${STEWARD_DISPLAY_NAME_METADATA} AS metadata,
757771
s.status AS "stewardshipStatus",
758772
sa.created_at AS "createdAt"
759773
FROM stewardship_activity sa
760774
JOIN stewardships s ON s.id = sa.stewardship_id
761775
JOIN packages p ON p.id = s.package_id
776+
${STEWARD_MENTIONED_JOIN}
762777
WHERE s.id IN (
763778
SELECT stewardship_id FROM stewardship_stewards
764779
WHERE user_id = $(userId) AND deleted_at IS NULL
@@ -845,6 +860,13 @@ export function translateActivityContent(
845860
metadata?: Record<string, unknown> | null,
846861
): string | null {
847862
if (!content) return content
863+
if (activityType === 'steward_added') {
864+
const displayName = metadata?.stewardDisplayName as string | undefined
865+
const role = metadata?.role as string | undefined
866+
if (displayName && role) {
867+
return `Assigned steward ${displayName} as ${role}`
868+
}
869+
}
848870
if (activityType === 'escalation' && metadata?.resolutionPath) {
849871
const label =
850872
ESCALATION_RESOLUTION_PATH_LABELS[metadata.resolutionPath as EscalationResolutionPath]

0 commit comments

Comments
 (0)