fix: rename checkPermission to be more fitting
This commit is contained in:
parent
0dddc2224a
commit
dd0fd5b5cc
|
@ -7,7 +7,7 @@ import {
|
|||
parseTeamId,
|
||||
checkSelfImpersonation,
|
||||
checkUserIdentifier,
|
||||
checkPermission,
|
||||
checkGlobalPermission,
|
||||
} from "./ImpersonationProvider";
|
||||
|
||||
const session: Session = {
|
||||
|
@ -65,17 +65,17 @@ describe("checkUserIdentifier", () => {
|
|||
describe("checkPermission", () => {
|
||||
it("should throw an error if the user is not an admin and team impersonation is disabled", () => {
|
||||
process.env.NEXT_PUBLIC_TEAM_IMPERSONATION = "false";
|
||||
expect(() => checkPermission(session)).toThrow();
|
||||
expect(() => checkGlobalPermission(session)).toThrow();
|
||||
});
|
||||
|
||||
it("should not throw an error if the user is an admin and team impersonation is disabled", () => {
|
||||
const modifiedSession = { ...session, user: { ...session.user, role: UserPermissionRole.ADMIN } };
|
||||
process.env.NEXT_PUBLIC_TEAM_IMPERSONATION = "false";
|
||||
expect(() => checkPermission(modifiedSession)).not.toThrow();
|
||||
expect(() => checkGlobalPermission(modifiedSession)).not.toThrow();
|
||||
});
|
||||
|
||||
it("should not throw an error if the user is not an admin but team impersonation is enabled", () => {
|
||||
process.env.NEXT_PUBLIC_TEAM_IMPERSONATION = "true";
|
||||
expect(() => checkPermission(session)).not.toThrow();
|
||||
expect(() => checkGlobalPermission(session)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -63,7 +63,7 @@ export function checkUserIdentifier(creds: Partial<Credentials>) {
|
|||
if (!creds?.username) throw new Error("User identifier must be present");
|
||||
}
|
||||
|
||||
export function checkPermission(session: Session | null) {
|
||||
export function checkGlobalPermission(session: Session | null) {
|
||||
if (
|
||||
(session?.user.role !== "ADMIN" && process.env.NEXT_PUBLIC_TEAM_IMPERSONATION === "false") ||
|
||||
!session?.user
|
||||
|
@ -148,8 +148,7 @@ const ImpersonationProvider = CredentialsProvider({
|
|||
const teamId = parseTeamId(creds);
|
||||
checkSelfImpersonation(session, creds);
|
||||
checkUserIdentifier(creds);
|
||||
checkPermission(session);
|
||||
|
||||
checkGlobalPermission(session);
|
||||
const impersonatedUser = await getImpersonatedUser({ session, teamId, creds });
|
||||
|
||||
if (session?.user.role === "ADMIN") {
|
||||
|
|
Loading…
Reference in New Issue
Block a user