Repository navigation
Announcements: history, edit, archive and restore for Admin - #32
Conversation
Adds Announcement.archivedAt. An archived announcement is hidden from every list and never delivered while archived.
GET /announcements/manage lists every announcement in the college with its state (published, scheduled, expired, archived) and counts per state. PUT /announcements/:id edits one: a published announcement keeps its publish time and isn't announced again, a scheduled one can be moved or published now, and the write is conditional on it not having been sent since it was read. Archive and restore are guarded the same way. All three are audited. The notice board and the scheduled delivery skip archived announcements.
Admins get a Manage tab next to the notice board: every announcement with state filters and counts, search and category, and Edit, Archive or Restore on each. The form is shared between new and edit; when editing a sent announcement its publish time is shown and fixed.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7cc1934f7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const expiresAt = optionalDate(b.expiresAt); | ||
| // An announcement must still be live when it goes out: it expires after it is published, and after now. | ||
| const now = new Date(); | ||
| if (expiresAt && expiresAt <= (publishedAt && publishedAt > now ? publishedAt : now)) invalid(); |
There was a problem hiding this comment.
Allow edits to already-expired announcements
When an Admin edits an expired announcement, the form resubmits its existing expiry date, but this shared validator rejects any expiry at or before now. Even a title or body correction therefore fails with INVALID_INPUT unless the Admin clears or changes the expiry, which also changes the announcement’s behavior. Keep the create-time constraint, but allow updates to preserve an announcement’s past expiry.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3ff5a9c. An edit only needs the expiry after the publish time now, so an expired announcement can be corrected and keep its expiry. Creating one still requires a future expiry.
| for (const announcement of due) { | ||
| const claimed = await this.database.announcement.updateMany({ where: { id: announcement.id, notifiedAt: null }, data: { notifiedAt: now } }); | ||
| // Archived after it was found: the claim fails and it is not delivered. | ||
| const claimed = await this.database.announcement.updateMany({ where: { id: announcement.id, notifiedAt: null, archivedAt: null }, data: { notifiedAt: now } }); |
There was a problem hiding this comment.
Prevent archiving from racing an in-flight delivery
If the scheduled-delivery check claims an announcement here and an Admin archives it before announce() runs, the loop still sends notifications from the previously fetched announcement. The archive request can therefore succeed before recipients are notified, despite the guarantee that archived announcements are never delivered while archived. Coordinate archiving with the claim-and-notify flow so a successful archive cancels an in-flight delivery.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3ff5a9c. The claim and the notifications are now written in one transaction, and pushed live after commit. The claim holds the row lock, so an archive either commits first and nothing is sent, or waits until delivery is done. Publishing now and moving a scheduled one to now use the same path.
…low editing expired ones An archive could succeed between the delivery check claiming an announcement and its notifications going out, so an archived announcement was still delivered. Every delivery (publishing now, an edit moving it to now, and the scheduled check) now claims it and stores its notifications in one transaction, pushing them live after commit. The claim holds the row lock, so an archive either commits first and nothing is sent, or waits until delivery is done. Recipients are read from the claimed row. A failure leaves it unclaimed for the next check and never fails the request. NotificationsService.store writes with a given client for this. An edit only needs the expiry after the publish time, so an expired announcement can be corrected without changing its expiry; new announcements still can't be created expired.
Admin role, Announcements, continued from #31. The spec lists these Admin actions: edit announcements, archive announcements and view announcement history. Until now Admin couldn't see a scheduled announcement at all: the notice board only shows published ones.
Summary
GET /announcements/manage, Admin only). Every announcement in the college with its state: published, scheduled, expired or archived. Each state has a count, and the list can be filtered by state, category and search.PUT /announcements/:id).POST /announcements/:id/archiveand/restore).announcement_archiveaddsarchivedAt.NotificationsService.storewrites with a given client for this.Rules used
Validation
pnpm test(292 passed, 12 new),pnpm lint,pnpm typecheck,pnpm build,git diff --check,prisma validate,prisma migrate status.