mirror of
https://github.com/vee1e/workorder-desk.git
synced 2026-09-01 09:50:13 +00:00
fix(backend): treat missing aiEnabled as enabled for legacy users
Users seeded before the aiEnabled field existed read as undefined via lean(), and the copilot runtime treated undefined as disabled, 403-ing session creation. Only an explicit false now disables; toUserAdmin also defaults the field to true for display.
This commit is contained in:
parent
0de104568f
commit
303def2205
2 changed files with 4 additions and 2 deletions
|
|
@ -35,7 +35,9 @@ function isAbortError(err: unknown): boolean {
|
|||
|
||||
async function assertUserEnabled(userId: string): Promise<void> {
|
||||
const user = await userRepo.findById(userId);
|
||||
if (!user || !user.aiEnabled) throw forbidden('AI is disabled for this account');
|
||||
// aiEnabled defaults to true; only an explicit false disables (legacy
|
||||
// documents created before the field existed read as undefined).
|
||||
if (!user || user.aiEnabled === false) throw forbidden('AI is disabled for this account');
|
||||
}
|
||||
|
||||
const providerTools: ProviderTool[] = copilotTools.map((tool) => ({
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export function toUserAdmin(user: UserDoc): UserAdmin {
|
|||
return {
|
||||
...toUserPublic(user),
|
||||
isActive: user.isActive,
|
||||
aiEnabled: user.aiEnabled,
|
||||
lastLoginAt: user.lastLoginAt ? user.lastLoginAt.toISOString() : null,
|
||||
aiEnabled: user.aiEnabled ?? true,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue