Skip to content

Announcements: history, edit, archive and restore for Admin - #32

Merged
anishmehta24 merged 5 commits into
mainfrom
feat/announcement-history
Nov 18, 2026
Merged

anishmehta24 merged 5 commits into
mainfrom
feat/announcement-history

Conversation

@anishmehta24

@anishmehta24 anishmehta24 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • History (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.
  • Edit (PUT /announcements/:id).
    • A published announcement keeps its publish time and isn't announced again, so fixing a typo doesn't notify everyone twice.
    • A scheduled one can be moved to another time, or published now; publishing now announces it at once.
    • The write only applies if the announcement hasn't been sent since it was read, so an edit can't race the scheduled delivery.
  • Archive and restore (POST /announcements/:id/archive and /restore).
    • Archived announcements are hidden from every list and are never delivered while archived.
    • A restored announcement whose time has passed goes out at the next check, unless it has expired.
    • Migration announcement_archive adds archivedAt.
  • Edits, archives and restores are audited.
  • From review:
    • Expired announcements can be corrected. An edit only needs the expiry after the publish time, so fixing a typo keeps the past expiry. New announcements still can't be created already expired.
    • Archiving can't race a delivery. Every delivery (publishing now, an edit moving it to now, and the scheduled check) now claims the announcement and stores its notifications in one transaction, and pushes 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 complete.
      • 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.
  • Page.
    • Admins get a Manage tab next to the notice board: the history table with state filters and counts, search, category, and Edit, Archive or Restore on each row.
    • The form is now shared between new and edit announcements. When editing a sent announcement, its publish time is shown and can't be changed, and a note says that people added by the edit won't be notified.

Rules used

  1. Any Admin can edit or archive any announcement in the college, not only its author, like the other Admin records.
  2. A sent announcement's publish time is fixed. Moving it would hide a notice people have already been told about, and there's no notifying again.
  3. Archiving hides rather than deletes, so the history and audit trail stay. There is no delete.
  4. Attachments (the spec's "attach documents") are not in this PR.

Validation

  • pnpm test (292 passed, 12 new), pnpm lint, pnpm typecheck, pnpm build, git diff --check, prisma validate, prisma migrate status.
  • Locally, with one announcement published now, one scheduled for tomorrow and one for 45 seconds ahead:
    • History: the "scheduled" filter listed both scheduled ones with correct counts. The student's feed showed only the published one. HOD got 403 on the history.
    • Edits:
      • Editing the published title kept it published and sent no new notification.
      • Moving its publish time returned 409.
      • Moving tomorrow's announcement to now published it and notified the student.
    • Archive and restore:
      • The 45-second announcement was archived, and was still unsent after the delivery check ran.
      • Archiving the published one hid it from the student, and restoring it brought it back.
      • Doing either twice returned 409, and an unknown id returned 404.
    • The audit log has the update, archive and restore entries.
    • In the browser, the Manage tab, its filters and the edit form all worked. Saving a category change showed "Saved. It was already published, so nobody is notified again."
    • After the review fixes:
      • Publishing now went out through the transaction.
      • Of two announcements scheduled 30 seconds ahead, the archived one was not sent and the other was.
      • An expired announcement saved a typo fix and stayed expired, while creating one already expired returned 400.
    • Deleted the test announcements, notifications and audit rows.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T04:23:34.112241Z c7cc193 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 } });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant