diff options
| author | Sho Sakuma <me@m1sk9.dev> | 2026-08-02 19:36:39 +0900 |
|---|---|---|
| committer | Sho Sakuma <me@m1sk9.dev> | 2026-08-02 19:36:39 +0900 |
| commit | 288d1e4a4babc136e8b3837d19970cc37023eb8e (patch) | |
| tree | 79eba159ba5f04789384895d30c45039f6053fd6 /engine/src/test | |
| parent | bf62ebe35653492c123c729ae03cb32d8e20e2e6 (diff) | |
| download | LunaticChat-288d1e4a4babc136e8b3837d19970cc37023eb8e.tar.gz LunaticChat-288d1e4a4babc136e8b3837d19970cc37023eb8e.tar.bz2 LunaticChat-288d1e4a4babc136e8b3837d19970cc37023eb8e.zip | |
refactor: move channel moderation rules out of the commands
The rule "owners and moderators may kick and ban" was written out six
times, as `senderRole == null || senderRole == ChannelRole.MEMBER`, while
ChannelMembershipManager.hasRole - which encodes the OWNER > MODERATOR >
MEMBER hierarchy in one place and has tests - had no production caller at
all. Letting moderators ban meant editing six files and hoping none was
missed; a miss is a silent privilege change.
The bypass and self-invite rules had drifted further still: the engine
defines ChannelPlayerBypassBanException, ChannelPlayerBypassKickException
and ChannelCannotInviteSelfException, but nothing threw them. The checks
lived inline in the commands, and ChannelBanCommand carried a catch arm
for an exception that could never arrive. Those three rules now live on
ChannelMembershipManager and throw what the engine already declared, so
every caller is held to them rather than only the command path.
ChannelInviteCommand also pre-checked for a banned target, which
joinChannel checks again a moment later and reports through the same
message; the pre-check is gone.
What stays in the commands is what belongs there: parsing an argument and
choosing which message to show. ChannelSubCommand names the steps they
share and derives message keys from the subcommand's own literal.
The tests followed the rules: bypass and self-invite are now asserted
against ChannelMembershipManager, with a bypass predicate injected so the
manager stays testable without a running server.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'engine/src/test')
0 files changed, 0 insertions, 0 deletions
