diff --git a/backend/src/api/public/v1/akrites/openapi.yaml b/backend/src/api/public/v1/akrites/openapi.yaml index d609a532d8..9026112a63 100644 --- a/backend/src/api/public/v1/akrites/openapi.yaml +++ b/backend/src/api/public/v1/akrites/openapi.yaml @@ -151,7 +151,10 @@ components: type: string userId: type: string - name: + username: + type: string + nullable: true + displayName: type: string nullable: true role: diff --git a/backend/src/api/public/v1/packages/types.ts b/backend/src/api/public/v1/packages/types.ts index 2762708697..6b4f542af3 100644 --- a/backend/src/api/public/v1/packages/types.ts +++ b/backend/src/api/public/v1/packages/types.ts @@ -24,7 +24,8 @@ export interface OpenVulns { export interface Steward { userId: string - name: string + username: string | null + displayName: string | null role: 'lead' | 'co_steward' assignedAt: string } diff --git a/backend/src/api/public/v1/stewardships/assignSteward.ts b/backend/src/api/public/v1/stewardships/assignSteward.ts index e48ada8a39..81b66957ad 100644 --- a/backend/src/api/public/v1/stewardships/assignSteward.ts +++ b/backend/src/api/public/v1/stewardships/assignSteward.ts @@ -14,6 +14,8 @@ 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), @@ -21,11 +23,16 @@ const bodySchema = z.object({ export async function assignStewardHandler(req: Request, res: Response): Promise { 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, diff --git a/backend/src/api/public/v1/stewardships/openapi.yaml b/backend/src/api/public/v1/stewardships/openapi.yaml index 08928976d6..a4cd456ea5 100644 --- a/backend/src/api/public/v1/stewardships/openapi.yaml +++ b/backend/src/api/public/v1/stewardships/openapi.yaml @@ -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 + displayName: + type: + - string + - 'null' + description: Display name of the steward. Null if not provided at assignment time. example: Jonathan R. role: type: string diff --git a/backend/src/osspckgs/migrations/V1781877251__stewardship-steward-name-username.sql b/backend/src/osspckgs/migrations/V1781877251__stewardship-steward-name-username.sql new file mode 100644 index 0000000000..16106baa0c --- /dev/null +++ b/backend/src/osspckgs/migrations/V1781877251__stewardship-steward-name-username.sql @@ -0,0 +1,3 @@ +ALTER TABLE stewardship_stewards + ADD COLUMN IF NOT EXISTS username TEXT, + ADD COLUMN IF NOT EXISTS display_name TEXT; diff --git a/services/libs/data-access-layer/src/osspckgs/api.ts b/services/libs/data-access-layer/src/osspckgs/api.ts index 0d0b588b52..8e3617cd03 100644 --- a/services/libs/data-access-layer/src/osspckgs/api.ts +++ b/services/libs/data-access-layer/src/osspckgs/api.ts @@ -112,6 +112,8 @@ export async function getOsspreyMetrics(qx: QueryExecutor): Promise): 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, @@ -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 @@ -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( @@ -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 } : {}), }), @@ -267,7 +280,7 @@ export async function assignSteward( } const stewards: Array> = 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 @@ -293,7 +306,7 @@ export async function getStewardshipSummary( ): Promise { 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