Treat legacy boolean commenting preference as disabled

Teams not yet migrated to the CommentingAccess enum may still have a
boolean `false` stored for the commenting preference. Guard the
enabled checks so `false` reads as disabled rather than enabled.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Tom Moor
2026-06-06 10:23:38 -04:00
parent 14225ff9f3
commit 9c9f5cc3af
3 changed files with 10 additions and 8 deletions
+3 -3
View File
@@ -106,9 +106,9 @@ class Team extends Model {
*/
@computed
get commentingEnabled(): boolean {
return (
this.getPreference(TeamPreference.Commenting) !== CommentingAccess.None
);
const access = this.getPreference(TeamPreference.Commenting);
// A legacy boolean `false` (team not yet migrated) means disabled.
return access !== CommentingAccess.None && access !== false;
}
/**
+5 -4
View File
@@ -28,10 +28,11 @@ export function commentingEnabled() {
ctx: APIContext,
next: Next
) {
if (
ctx.state.auth.user.team.getPreference(TeamPreference.Commenting) ===
CommentingAccess.None
) {
const commenting = ctx.state.auth.user.team.getPreference(
TeamPreference.Commenting
);
// A legacy boolean `false` (team not yet migrated) means disabled.
if (commenting === CommentingAccess.None || commenting === false) {
throw ValidationError("Commenting is currently disabled");
}
return next();
+2 -1
View File
@@ -56,7 +56,8 @@ allow(User, "comment", Document, (actor, document) => {
!!document?.isActive,
isTeamMutable(actor),
can(actor, "read", document),
commenting !== CommentingAccess.None,
// A legacy boolean `false` (team not yet migrated) means disabled.
commenting !== CommentingAccess.None && commenting !== false,
or(!actor.isGuest, commenting === CommentingAccess.Everyone),
or(!document?.collection, document?.collection?.commenting !== false)
);