mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
9c9f5cc3af
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>
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import type { Next } from "koa";
|
|
import { CommentingAccess, TeamPreference } from "@shared/types";
|
|
import { ValidationError } from "@server/errors";
|
|
import type { APIContext } from "@server/types";
|
|
|
|
/**
|
|
* Middleware to check if a feature is enabled for the team.
|
|
*
|
|
* @param preference The preference to check
|
|
* @returns The middleware function
|
|
*/
|
|
export function feature(preference: TeamPreference) {
|
|
return async function featureEnabledMiddleware(ctx: APIContext, next: Next) {
|
|
if (!ctx.state.auth.user.team.getPreference(preference)) {
|
|
throw ValidationError(`${preference} is currently disabled`);
|
|
}
|
|
return next();
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Middleware to check that commenting is enabled for the team.
|
|
*
|
|
* @returns The middleware function
|
|
*/
|
|
export function commentingEnabled() {
|
|
return async function commentingEnabledMiddleware(
|
|
ctx: APIContext,
|
|
next: Next
|
|
) {
|
|
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();
|
|
};
|
|
}
|