Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion backend/src/api/public/v1/akrites/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ components:
type: string
userId:
type: string
name:
username:
type: string
nullable: true
displayName:
type: string
nullable: true
role:
Comment on lines 152 to 160
Expand Down
3 changes: 2 additions & 1 deletion backend/src/api/public/v1/packages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export interface OpenVulns {

export interface Steward {
userId: string
name: string
username: string | null
displayName: string | null
role: 'lead' | 'co_steward'
Comment on lines 25 to 29
assignedAt: string
}
Expand Down
9 changes: 8 additions & 1 deletion backend/src/api/public/v1/stewardships/assignSteward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ const paramsSchema = z.object({

const bodySchema = z.object({
userId: z.string().trim().min(1),
username: z.string().trim().min(1).optional(),
displayName: z.string().trim().min(1).optional(),
role: z.enum(['lead', 'co_steward']),
note: z.string().trim().min(1).optional(),
moveToAssessing: z.boolean().optional().default(false),
})

export async function assignStewardHandler(req: Request, res: Response): Promise<void> {
const { id } = validateOrThrow(paramsSchema, req.params)
const { userId, role, note, moveToAssessing } = validateOrThrow(bodySchema, req.body)
const { userId, username, displayName, role, note, moveToAssessing } = validateOrThrow(
bodySchema,
req.body,
)

const qx = await getPackagesQx()
const result = await assignSteward(qx, id, {
userId,
username,
displayName,
role,
note,
assignedBy: req.actor.id,
Expand Down
10 changes: 8 additions & 2 deletions backend/src/api/public/v1/stewardships/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,17 @@ components:
type: string
description: Auth0 sub of the assigned steward.
example: abc123
name:
username:
type:
- string
- 'null'
description: Display name of the steward. Null if not available.
description: Username of the steward in LFX. Null if not provided at assignment time.
example: jonathanr
Comment on lines +129 to +134
displayName:
type:
- string
- 'null'
description: Display name of the steward. Null if not provided at assignment time.
example: Jonathan R.
role:
type: string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE stewardship_stewards
ADD COLUMN IF NOT EXISTS username TEXT,
ADD COLUMN IF NOT EXISTS display_name TEXT;
4 changes: 3 additions & 1 deletion services/libs/data-access-layer/src/osspckgs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export async function getOsspreyMetrics(qx: QueryExecutor): Promise<OsspreyMetri

export interface StewardEntry {
userId: string
username: string | null
displayName: string | null
role: string
assignedAt: string
}
Expand Down Expand Up @@ -460,7 +462,7 @@ export async function listPackagesForApi(
LEFT JOIN LATERAL (
SELECT COALESCE(
json_agg(
json_build_object('userId', ss.user_id, 'role', ss.role, 'assignedAt', ss.assigned_at)
json_build_object('userId', ss.user_id, 'username', ss.username, 'displayName', ss.display_name, 'role', ss.role, 'assignedAt', ss.assigned_at)
ORDER BY ss.assigned_at ASC
Comment on lines 463 to 466
) FILTER (WHERE ss.id IS NOT NULL),
'[]'::json
Expand Down
29 changes: 21 additions & 8 deletions services/libs/data-access-layer/src/osspckgs/stewardships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export interface StewardshipStewardRecord {
id: string
stewardshipId: string
userId: string
name: string | null
username: string | null
displayName: string | null
role: string
assignedAt: string
assignedBy: string | null
Expand Down Expand Up @@ -92,7 +93,8 @@ function mapStewardStewardRow(row: Record<string, unknown>): StewardshipStewardR
id: String(row.id),
stewardshipId: String(row.stewardship_id),
userId: String(row.user_id),
name: null,
username: row.username ? String(row.username) : null,
displayName: row.display_name ? String(row.display_name) : null,
role: String(row.role),
assignedAt: toIso(row.assigned_at),
assignedBy: row.assigned_by ? String(row.assigned_by) : null,
Expand Down Expand Up @@ -190,6 +192,8 @@ export async function assignSteward(
stewardshipId: number,
data: {
userId: string
username?: string
displayName?: string
role: 'lead' | 'co_steward'
assignedBy: string
note?: string
Expand All @@ -211,9 +215,16 @@ export async function assignSteward(
)

await tx.result(
`INSERT INTO stewardship_stewards (stewardship_id, user_id, role, assigned_by)
VALUES ($(stewardshipId), $(userId), $(role), $(assignedBy))`,
{ stewardshipId, userId: data.userId, role: data.role, assignedBy: data.assignedBy },
`INSERT INTO stewardship_stewards (stewardship_id, user_id, username, display_name, role, assigned_by)
VALUES ($(stewardshipId), $(userId), $(username), $(displayName), $(role), $(assignedBy))`,
{
stewardshipId,
userId: data.userId,
username: data.username ?? null,
displayName: data.displayName ?? null,
role: data.role,
assignedBy: data.assignedBy,
},
)

await tx.result(
Expand All @@ -222,9 +233,11 @@ export async function assignSteward(
{
stewardshipId,
actorUserId: data.assignedBy,
content: `Assigned steward ${data.userId} as ${data.role}`,
content: `Assigned steward ${data.displayName ?? data.username ?? data.userId} as ${data.role}`,
metadata: JSON.stringify({
userId: data.userId,
...(data.username ? { username: data.username } : {}),
...(data.displayName ? { displayName: data.displayName } : {}),
role: data.role,
...(data.note ? { note: data.note } : {}),
}),
Expand Down Expand Up @@ -267,7 +280,7 @@ export async function assignSteward(
}

const stewards: Array<Record<string, unknown>> = await tx.select(
`SELECT id, stewardship_id, user_id, role, assigned_at, assigned_by
`SELECT id, stewardship_id, user_id, username, display_name, role, assigned_at, assigned_by
FROM stewardship_stewards
WHERE stewardship_id = $(stewardshipId)
AND deleted_at IS NULL
Expand All @@ -293,7 +306,7 @@ export async function getStewardshipSummary(
): Promise<StewardshipSummary> {
const [stewards, activityRow] = await Promise.all([
qx.select(
`SELECT id, stewardship_id, user_id, role, assigned_at, assigned_by
`SELECT id, stewardship_id, user_id, username, display_name, role, assigned_at, assigned_by
FROM stewardship_stewards
WHERE stewardship_id = $(stewardshipId)
AND deleted_at IS NULL
Expand Down
Loading