Skip to content

Chat lifecycle: archive, 6-month cleanup, restore, deleted Users (#98) - #107

Merged
Oceandek merged 1 commit into
mainfrom
feat/chat-lifecycle
Oct 29, 2026
Merged

Oceandek merged 1 commit into
mainfrom
feat/chat-lifecycle

Conversation

@Oceandek

Copy link
Copy Markdown
Collaborator

Closes #98 and with it spec #91 (Project chat).

What's new

  • Archiving: projects.archived_at is set when a Project is archived and cleared on restore. An archived chat is read-only and only Teachers and the Superuser can open it. Former Members (Makers) and Guests get 403. Sending, editing, deleting, reacting, typing and Guest changes are refused (409).
  • Deletion notice: an archived chat shows "This Project is archived: its chat is read-only." and "This chat will be deleted on DD/MM/YYYY.", 182 days (6 months) after archiving, in Belgian time (deleted_on on GET .../chat).
  • Cleanup: a background task (chat.clean_up_forever, started in the app's lifespan) runs at startup and then once a day. It deletes the messages of chats whose Project was archived more than 182 days ago, using the database's now(). Their files, reactions and mentions go along via ON DELETE CASCADE, together with the read marks and the files folder on the chat-files volume. It runs on its own instead of inside the daily-email loop, because that loop only starts when SMTP is configured.
  • Restore within 6 months: the chat is writable again with its history. After the cleanup, it starts empty.
  • Deleting a Project removes its chat and files (since Chat photos and files, including backup #94). Deleting a User keeps their messages, shown as "Deleted user", and removes their reactions. Chat messages never blocked a delete, and a test now covers it.
  • Migration 0019: projects.archived_at. Projects that were already archived get the migration day, so their chats are deleted 6 months from now. CONTEXT.md (Chat) and changelog updated.

Tests

  • Backend 368 passed; new test_chat_lifecycle.py (archived chat read-only and staff-only, deletion date, write actions refused; restore keeps the history; cleanup at 181 vs 183 days with the database clock moved, the file removed from the volume, active chats untouched, restore after cleanup starts empty; deleting a User keeps "Deleted user" messages).
  • Frontend 118 passed; new test_chat_lifecycle.py (a Teacher reads an archived chat with its deletion date, no input, no menus or reactions).

Note: test_my_project.py::test_student_sees_their_projects_photo errored once more locally at teardown ("Your session has expired"; during #96 it was a NiceGUI reconnect_timeout error). It has nothing to do with the chat and passes on its own. It looks flaky and is worth a separate look. A first local run of the full suites also hung once and never finished; it ran cleanly on the rerun.

🤖 Generated with Claude Code

An Archived Project's chat is read-only and staff-only, with the day it
will be deleted; a daily background job deletes it 6 months after
archiving; restoring before then keeps the history; deleted Users' messages
stay as "Deleted user". Completes spec #91.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Oceandek
Oceandek merged commit 5343a36 into main Oct 29, 2026
2 checks passed
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.

Chat lifecycle: archive, 6-month cleanup, restore, delete, deleted Users

1 participant