Skip to content

Commit 57794c1

Browse files
authored
fix: update group timestamp when membership change (#2352)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent 2013c3c commit 57794c1

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

app/controlplane/pkg/data/group.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,13 @@ func (g GroupRepo) AddMemberToGroup(ctx context.Context, orgID uuid.UUID, groupI
458458
return fmt.Errorf("failed to add user to group: %w", err)
459459
}
460460

461+
// Update the group's updated_at timestamp
462+
if _, err := tx.Group.UpdateOneID(groupID).
463+
SetUpdatedAt(time.Now()).
464+
Save(ctx); err != nil {
465+
return fmt.Errorf("failed to update group timestamp: %w", err)
466+
}
467+
461468
// Update the user membership with the role of maintainer
462469
if maintainer {
463470
_, err = tx.Membership.Create().
@@ -513,6 +520,13 @@ func (g GroupRepo) RemoveMemberFromGroup(ctx context.Context, orgID uuid.UUID, g
513520
return fmt.Errorf("failed to remove user from group: %w", err)
514521
}
515522

523+
// Update the group's updated_at timestamp
524+
if _, err := tx.Group.UpdateOneID(groupID).
525+
SetUpdatedAt(now).
526+
Save(ctx); err != nil {
527+
return fmt.Errorf("failed to update group timestamp: %w", err)
528+
}
529+
516530
if existingMembership.Maintainer {
517531
// Also remove the user membership if it exists
518532
if _, err := tx.Membership.Delete().Where(
@@ -569,14 +583,22 @@ func (g GroupRepo) UpdateMemberMaintainerStatus(ctx context.Context, orgID uuid.
569583
}
570584

571585
// Update the group membership with the new maintainer status
586+
now := time.Now()
572587
_, err = tx.GroupMembership.UpdateOne(existingMembership).
573588
SetMaintainer(isMaintainer).
574-
SetUpdatedAt(time.Now()).
589+
SetUpdatedAt(now).
575590
Save(ctx)
576591
if err != nil {
577592
return fmt.Errorf("failed to update group membership maintainer status: %w", err)
578593
}
579594

595+
// Update the group's updated_at timestamp
596+
if _, err := tx.Group.UpdateOneID(groupID).
597+
SetUpdatedAt(now).
598+
Save(ctx); err != nil {
599+
return fmt.Errorf("failed to update group timestamp: %w", err)
600+
}
601+
580602
// Update the membership table as well
581603
if isMaintainer {
582604
// If becoming a maintainer, create the membership record if it doesn't exist

0 commit comments

Comments
 (0)