forked from calcom/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Exclude locked users by default (calcom#17889)
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Prisma } from "@prisma/client"; | ||
import type { DefaultArgs, InternalArgs } from "@prisma/client/runtime/library"; | ||
|
||
export function excludeLockedUsersExtension() { | ||
return Prisma.defineExtension({ | ||
query: { | ||
user: { | ||
async findUnique({ args, query }) { | ||
return excludeLockedUsers(args, query); | ||
}, | ||
async findFirst({ args, query }) { | ||
return excludeLockedUsers(args, query); | ||
}, | ||
async findMany({ args, query }) { | ||
return excludeLockedUsers(args, query); | ||
}, | ||
async findUniqueOrThrow({ args, query }) { | ||
return excludeLockedUsers(args, query); | ||
}, | ||
async findFirstOrThrow({ args, query }) { | ||
return excludeLockedUsers(args, query); | ||
}, | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
async function excludeLockedUsers( | ||
args: | ||
| Prisma.UserFindUniqueArgs<InternalArgs & DefaultArgs> | ||
| Prisma.UserFindFirstArgs<InternalArgs & DefaultArgs> | ||
| Prisma.UserFindManyArgs<InternalArgs & DefaultArgs> | ||
| Prisma.UserFindUniqueOrThrowArgs<InternalArgs & DefaultArgs> | ||
| Prisma.UserFindFirstOrThrowArgs<InternalArgs & DefaultArgs>, | ||
query: <T>(args: T) => Promise<unknown> | ||
) { | ||
args.where = args.where || {}; | ||
// Unless explicitly specified, we exclude locked users | ||
if (args.where.locked === undefined) { | ||
args.where.locked = false; | ||
} | ||
return query(args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters