feat(discord): add archive/unarchive commands for read-only channel archiving - #104
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 313f80b4d5
ℹ️ 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".
| } | ||
|
|
||
| if _, err := GetArchivedChannel(channel.ID); err != nil { | ||
| overwrites, err := json.Marshal(channel.PermissionOverwrites) |
There was a problem hiding this comment.
Persist the pre-update overwrites in the snapshot
When a move into ARCHIVE also synchronizes or otherwise changes permission overwrites in the same channel update, channel contains the post-update values while BeforeUpdate contains the state being archived. Serializing channel.PermissionOverwrites therefore records the archive permissions, so unarchive cannot restore the channel's original access configuration. Pass and persist the overwrites from BeforeUpdate when it is available.
Useful? React with 👍 / 👎.
| logger.SugarLogger.Infof("channel archive: snapshot already exists for %s (%s), keeping original", channel.ID, channel.Name) | ||
| } | ||
|
|
||
| if len(category.PermissionOverwrites) > 0 { |
There was a problem hiding this comment.
Clear overwrites when the archive category has none
When the ARCHIVE category has zero explicit overwrites, this guard skips permission synchronization entirely, leaving every channel-specific allow and deny from before the move in place. Such a channel does not match the category and can remain visible to members explicitly allowed by its old overwrites; the empty target set needs to be applied by deleting the channel's existing overwrites, as the unarchive path already does.
Useful? React with 👍 / 👎.
| if err := Discord.ChannelPermissionDelete(channelID, overwrite.ID); err != nil { | ||
| logger.SugarLogger.Errorf("channel archive: failed to delete overwrite %s on %s: %v", overwrite.ID, channelID, err) | ||
| } |
There was a problem hiding this comment.
Keep the snapshot when overwrite cleanup fails
When restoring a channel whose original overwrite list was empty, any rejected ChannelPermissionDelete is only logged, after which the snapshot is deleted and the operation returns success. The channel then retains part of the archive permission set while the state needed to retry restoration is lost; return an error and preserve the snapshot unless every deletion succeeds.
Useful? React with 👍 / 👎.
…ty ID, expose archived channels API
!archivecommand: snapshots the channel's permission overwrites + parent category to a newarchived_channeltable, moves it to an ARCHIVE category, and rewrites permissions to Sentinel's standardized archived formGET /api/core/entity/:id/groups) must include one of Admins/Leads/Officers (case-insensitive, configurable inconfig.ArchiveCommandAllowedGroups); fails closed on missing entity link or lookup errors!unarchiveto restore!unarchivecommand: restores the snapshotted overwrites and original category, deletes the snapshotdiscord_message)GET /discord/archived-channelsendpoint (scopesentinel:all) for surfacing archive info in the frontend (web UI to follow in a separate PR)