Skip to content

Commit 673509b

Browse files
authored
fix: stewardship action status at time (CM-1291) (#4284)
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent bbeabfe commit 673509b

4 files changed

Lines changed: 25 additions & 15 deletions

File tree

backend/src/api/public/v1/stewardships/getMyActivity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export async function getMyActivityHandler(req: Request, res: Response): Promise
6565
description: r.content,
6666
actor: r.actor,
6767
createdAt: r.createdAt,
68-
suggestedAction: SUGGESTED_ACTIONS[r.stewardshipStatus] ?? null,
68+
suggestedAction: SUGGESTED_ACTIONS[r.currentStewardshipStatus] ?? null,
6969
})),
7070
meta: {
7171
total,

backend/src/bin/scripts/merge-members.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ const options = [
3838
alias: 'u',
3939
typeLabel: '{underline userId}',
4040
type: String,
41-
description:
42-
'User ID of the user performing the merge.',
41+
description: 'User ID of the user performing the merge.',
4342
},
4443
{
4544
name: 'help',
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Store the stewardship status as it was at the moment each activity was logged.
2+
-- Existing rows get NULL (no history to reconstruct); queries fall back to s.status for them.
3+
ALTER TABLE stewardship_activity
4+
ADD COLUMN IF NOT EXISTS status_at_time TEXT;

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ export async function openStewardshipByPurl(
203203
),
204204
_log AS (
205205
INSERT INTO stewardship_activity
206-
(stewardship_id, actor_user_id, actor_type, activity_type, content, actor_username, actor_display_name, actor_avatar_url)
206+
(stewardship_id, actor_user_id, actor_type, activity_type, content, actor_username, actor_display_name, actor_avatar_url, status_at_time)
207207
SELECT upserted.id, $(actorUserId), 'user', 'state_changed', 'Opened for stewardship',
208-
$(actorUsername), $(actorDisplayName), $(actorAvatarUrl)
208+
$(actorUsername), $(actorDisplayName), $(actorAvatarUrl), 'open'
209209
FROM upserted
210210
WHERE NOT EXISTS (SELECT 1 FROM prev WHERE prev.old_status = 'open')
211211
)
@@ -278,16 +278,17 @@ export async function assignSteward(
278278

279279
await tx.result(
280280
`INSERT INTO stewardship_activity
281-
(stewardship_id, actor_user_id, actor_type, activity_type, content, metadata, actor_username, actor_display_name, actor_avatar_url)
281+
(stewardship_id, actor_user_id, actor_type, activity_type, content, metadata, actor_username, actor_display_name, actor_avatar_url, status_at_time)
282282
VALUES ($(stewardshipId), $(actorUserId), 'user', 'steward_added', $(content), $(metadata)::jsonb,
283-
$(actorUsername), $(actorDisplayName), $(actorAvatarUrl))`,
283+
$(actorUsername), $(actorDisplayName), $(actorAvatarUrl), $(statusAtTime))`,
284284
{
285285
stewardshipId,
286286
actorUserId: data.assignedBy,
287287
actorUsername: data.actorUsername ?? null,
288288
actorDisplayName: data.actorDisplayName ?? null,
289289
actorAvatarUrl: data.actorAvatarUrl ?? null,
290290
content: `Assigned steward ${data.userId} as ${data.role}`,
291+
statusAtTime: stewardship.status,
291292
metadata: JSON.stringify({
292293
userId: data.userId,
293294
role: data.role,
@@ -316,10 +317,10 @@ export async function assignSteward(
316317
),
317318
_log AS (
318319
INSERT INTO stewardship_activity
319-
(stewardship_id, actor_user_id, actor_type, activity_type, content, metadata, actor_username, actor_display_name, actor_avatar_url)
320+
(stewardship_id, actor_user_id, actor_type, activity_type, content, metadata, actor_username, actor_display_name, actor_avatar_url, status_at_time)
320321
SELECT id, $(actorUserId), 'user', 'state_changed',
321322
'Status updated to assessing', $(metadata)::jsonb,
322-
$(actorUsername), $(actorDisplayName), $(actorAvatarUrl)
323+
$(actorUsername), $(actorDisplayName), $(actorAvatarUrl), 'assessing'
323324
FROM upd
324325
)
325326
SELECT * FROM upd
@@ -380,6 +381,7 @@ export interface ActivityFeedRow {
380381
content: string | null
381382
metadata: Record<string, unknown> | null
382383
stewardshipStatus: string
384+
currentStewardshipStatus: string
383385
createdAt: string
384386
total: string
385387
}
@@ -406,7 +408,8 @@ export async function listStewardshipActivity(
406408
sa.activity_type AS "activityType",
407409
sa.content AS content,
408410
${STEWARD_DISPLAY_NAME_METADATA} AS metadata,
409-
s.status AS "stewardshipStatus",
411+
COALESCE(sa.status_at_time, s.status) AS "stewardshipStatus",
412+
s.status AS "currentStewardshipStatus",
410413
sa.created_at AS "createdAt",
411414
COUNT(*) OVER()::text AS total
412415
FROM stewardship_activity sa
@@ -454,6 +457,7 @@ export async function listStewardshipActivity(
454457
),
455458
metadata: row.metadata as Record<string, unknown> | null,
456459
stewardshipStatus: row.stewardshipStatus as string,
460+
currentStewardshipStatus: row.currentStewardshipStatus as string,
457461
createdAt: toIso(row.createdAt),
458462
})),
459463
total,
@@ -797,6 +801,7 @@ export async function listMyActivity(
797801
sub.content,
798802
sub.metadata,
799803
sub."stewardshipStatus",
804+
sub."currentStewardshipStatus",
800805
sub."createdAt",
801806
COUNT(*) OVER()::text AS total
802807
FROM (
@@ -814,7 +819,8 @@ export async function listMyActivity(
814819
sa.activity_type AS "activityType",
815820
sa.content AS content,
816821
${STEWARD_DISPLAY_NAME_METADATA} AS metadata,
817-
s.status AS "stewardshipStatus",
822+
COALESCE(sa.status_at_time, s.status) AS "stewardshipStatus",
823+
s.status AS "currentStewardshipStatus",
818824
sa.created_at AS "createdAt"
819825
FROM stewardship_activity sa
820826
JOIN stewardships s ON s.id = sa.stewardship_id
@@ -879,6 +885,7 @@ export async function listMyActivity(
879885
),
880886
metadata: row.metadata as Record<string, unknown> | null,
881887
stewardshipStatus: row.stewardshipStatus as string,
888+
currentStewardshipStatus: row.currentStewardshipStatus as string,
882889
createdAt: toIso(row.createdAt),
883890
})),
884891
total,
@@ -961,9 +968,9 @@ export async function escalateStewardship(
961968
),
962969
_log AS (
963970
INSERT INTO stewardship_activity
964-
(stewardship_id, actor_user_id, actor_type, activity_type, content, metadata, actor_username, actor_display_name, actor_avatar_url)
971+
(stewardship_id, actor_user_id, actor_type, activity_type, content, metadata, actor_username, actor_display_name, actor_avatar_url, status_at_time)
965972
SELECT id, $(actorUserId), 'user', 'escalation',
966-
$(content), $(metadata)::jsonb, $(actorUsername), $(actorDisplayName), $(actorAvatarUrl)
973+
$(content), $(metadata)::jsonb, $(actorUsername), $(actorDisplayName), $(actorAvatarUrl), 'escalated'
967974
FROM upd
968975
)
969976
SELECT * FROM upd
@@ -1037,9 +1044,9 @@ export async function updateStewardshipStatus(
10371044
),
10381045
_log AS (
10391046
INSERT INTO stewardship_activity
1040-
(stewardship_id, actor_user_id, actor_type, activity_type, content, metadata, actor_username, actor_display_name, actor_avatar_url)
1047+
(stewardship_id, actor_user_id, actor_type, activity_type, content, metadata, actor_username, actor_display_name, actor_avatar_url, status_at_time)
10411048
SELECT id, $(actorUserId), 'user', 'state_changed',
1042-
$(content), $(metadata)::jsonb, $(actorUsername), $(actorDisplayName), $(actorAvatarUrl)
1049+
$(content), $(metadata)::jsonb, $(actorUsername), $(actorDisplayName), $(actorAvatarUrl), $(status)
10431050
FROM upd
10441051
)
10451052
SELECT * FROM upd

0 commit comments

Comments
 (0)