mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-30 10:49:55 -06:00
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import "server-only";
|
|
|
|
import { ZId } from "@formbricks/types/v1/environment";
|
|
import { validateInputs } from "../utils/validate";
|
|
import { hasUserEnvironmentAccess } from "../environment/auth";
|
|
import { getActionClass } from "./service";
|
|
import { unstable_cache } from "next/cache";
|
|
import { SERVICES_REVALIDATION_INTERVAL } from "../constants";
|
|
|
|
export const canUserAccessActionClass = async (userId: string, actionClassId: string): Promise<boolean> =>
|
|
await unstable_cache(
|
|
async () => {
|
|
validateInputs([userId, ZId], [actionClassId, ZId]);
|
|
if (!userId) return false;
|
|
|
|
const actionClass = await getActionClass(actionClassId);
|
|
if (!actionClass) return false;
|
|
|
|
const hasAccessToEnvironment = await hasUserEnvironmentAccess(userId, actionClass.environmentId);
|
|
if (!hasAccessToEnvironment) return false;
|
|
|
|
return true;
|
|
},
|
|
|
|
[`users-${userId}-actionClasses-${actionClassId}`],
|
|
{ revalidate: SERVICES_REVALIDATION_INTERVAL, tags: [`actionClasses-${actionClassId}`] }
|
|
)();
|