mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 18:30:32 -06:00
adds enterprise license check
This commit is contained in:
@@ -16,7 +16,7 @@ export default async function PeopleLayout({ params, children }) {
|
||||
throw new Error("Team not found");
|
||||
}
|
||||
|
||||
const isUserTargetingAllowed = getAdvancedTargetingPermission(team);
|
||||
const isUserTargetingAllowed = await getAdvancedTargetingPermission(team);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -31,7 +31,7 @@ export default async function SegmentsPage({ params }) {
|
||||
throw new Error("Team not found");
|
||||
}
|
||||
|
||||
const isAdvancedTargetingAllowed = getAdvancedTargetingPermission(team);
|
||||
const isAdvancedTargetingAllowed = await getAdvancedTargetingPermission(team);
|
||||
|
||||
if (!segments) {
|
||||
throw new Error("Failed to fetch segments");
|
||||
|
||||
@@ -25,7 +25,7 @@ export default async function EnvironmentsNavbar({ environmentId, session }: Env
|
||||
return <ErrorComponent />;
|
||||
}
|
||||
|
||||
const isMultiLanguageAllowed = getMultiLanguagePermission(team);
|
||||
const isMultiLanguageAllowed = await getMultiLanguagePermission(team);
|
||||
|
||||
const [products, environments] = await Promise.all([
|
||||
getProducts(team.id),
|
||||
|
||||
@@ -37,7 +37,7 @@ export default async function EnterpriseLicensePage({ params }) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const isEnterpriseEdition = getIsEnterpriseEdition();
|
||||
const isEnterpriseEdition = await getIsEnterpriseEdition();
|
||||
|
||||
const paidFeatures = [
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ export default async function LanguageSettingsPage({ params }: { params: { envir
|
||||
throw new Error("Team not found");
|
||||
}
|
||||
|
||||
const isMultiLanguageAllowed = getMultiLanguagePermission(team);
|
||||
const isMultiLanguageAllowed = await getMultiLanguagePermission(team);
|
||||
|
||||
if (!isMultiLanguageAllowed) {
|
||||
notFound();
|
||||
|
||||
@@ -33,7 +33,7 @@ export default async function SettingsLayout({ children, params }) {
|
||||
throw new Error("Unauthenticated");
|
||||
}
|
||||
|
||||
const isMultiLanguageAllowed = getMultiLanguagePermission(team);
|
||||
const isMultiLanguageAllowed = await getMultiLanguagePermission(team);
|
||||
|
||||
const currentUserMembership = await getMembershipByUserIdTeamId(session?.user.id, team.id);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export async function EditMemberships({
|
||||
|
||||
const currentUserRole = membership?.role;
|
||||
const isUserAdminOrOwner = membership?.role === "admin" || membership?.role === "owner";
|
||||
const canDoRoleManagement = getRoleManagementPermission(team);
|
||||
const canDoRoleManagement = await getRoleManagementPermission(team);
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -51,7 +51,7 @@ export default async function MembersSettingsPage({ params }: { params: { enviro
|
||||
if (!team) {
|
||||
throw new Error("Team not found");
|
||||
}
|
||||
const canDoRoleManagement = getRoleManagementPermission(team);
|
||||
const canDoRoleManagement = await getRoleManagementPermission(team);
|
||||
|
||||
const currentUserMembership = await getMembershipByUserIdTeamId(session?.user.id, team.id);
|
||||
const { isOwner, isAdmin } = getAccessFlags(currentUserMembership?.role);
|
||||
|
||||
@@ -59,8 +59,8 @@ export default async function SurveysEditPage({ params }) {
|
||||
const { isViewer } = getAccessFlags(currentUserMembership?.role);
|
||||
const isSurveyCreationDeletionDisabled = isViewer;
|
||||
|
||||
const isUserTargetingAllowed = getAdvancedTargetingPermission(team);
|
||||
const isMultiLanguageAllowed = getMultiLanguagePermission(team);
|
||||
const isUserTargetingAllowed = await getAdvancedTargetingPermission(team);
|
||||
const isMultiLanguageAllowed = await getMultiLanguagePermission(team);
|
||||
|
||||
if (
|
||||
!survey ||
|
||||
|
||||
@@ -62,7 +62,7 @@ export default async function LinkSurveyPage({ params, searchParams }: LinkSurve
|
||||
if (!team) {
|
||||
throw new Error("Team not found");
|
||||
}
|
||||
const isMultiLanguageAllowed = getMultiLanguagePermission(team);
|
||||
const isMultiLanguageAllowed = await getMultiLanguagePermission(team);
|
||||
|
||||
if (survey && survey.status !== "inProgress") {
|
||||
return (
|
||||
|
||||
@@ -3,9 +3,48 @@ import "server-only";
|
||||
import { ENTERPRISE_LICENSE_KEY, IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants";
|
||||
import { TTeam } from "@formbricks/types/teams";
|
||||
|
||||
export const getIsEnterpriseEdition = (): boolean => {
|
||||
if (ENTERPRISE_LICENSE_KEY) {
|
||||
return ENTERPRISE_LICENSE_KEY.length > 0;
|
||||
const licenseDetails: {
|
||||
isValid: boolean | null;
|
||||
lastChecked: Date;
|
||||
} = {
|
||||
isValid: null,
|
||||
lastChecked: new Date(0), // Initialize with an old date
|
||||
};
|
||||
|
||||
export const getIsEnterpriseEdition = async (): Promise<boolean> => {
|
||||
if (ENTERPRISE_LICENSE_KEY && ENTERPRISE_LICENSE_KEY.length > 0) {
|
||||
const currentTime = new Date();
|
||||
const timeSinceLastChecked = currentTime.getTime() - licenseDetails.lastChecked.getTime(); // Difference in milliseconds
|
||||
|
||||
// Check if the lastChecked time is within the last 24 hours
|
||||
if (
|
||||
licenseDetails.isValid !== null &&
|
||||
timeSinceLastChecked < 1000 * 60 * 60 * 24 // 1000ms * 60s * 60min * 24hrs
|
||||
) {
|
||||
return licenseDetails.isValid;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch("https://ee.formbricks.com/api/licenses/check", {
|
||||
body: JSON.stringify({ licenseKey: ENTERPRISE_LICENSE_KEY }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
let isValid = false;
|
||||
|
||||
if (res.ok) {
|
||||
const responseJson = await res.json();
|
||||
isValid = responseJson.data.status === "active";
|
||||
}
|
||||
|
||||
licenseDetails.isValid = isValid;
|
||||
licenseDetails.lastChecked = new Date(); // Update the last checked time
|
||||
|
||||
return isValid;
|
||||
} catch (error) {
|
||||
console.error("Error while checking license", error);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
@@ -22,20 +61,20 @@ export const getRemoveLinkBrandingPermission = (team: TTeam): boolean => {
|
||||
else return false;
|
||||
};
|
||||
|
||||
export const getRoleManagementPermission = (team: TTeam): boolean => {
|
||||
export const getRoleManagementPermission = async (team: TTeam): Promise<boolean> => {
|
||||
if (IS_FORMBRICKS_CLOUD) return team.billing.features.inAppSurvey.status !== "inactive";
|
||||
else if (!IS_FORMBRICKS_CLOUD) return getIsEnterpriseEdition();
|
||||
else return false;
|
||||
};
|
||||
|
||||
export const getAdvancedTargetingPermission = (team: TTeam): boolean => {
|
||||
export const getAdvancedTargetingPermission = async (team: TTeam): Promise<boolean> => {
|
||||
if (IS_FORMBRICKS_CLOUD) return team.billing.features.userTargeting.status !== "inactive";
|
||||
else if (!IS_FORMBRICKS_CLOUD) return getIsEnterpriseEdition();
|
||||
else if (!IS_FORMBRICKS_CLOUD) return await getIsEnterpriseEdition();
|
||||
else return false;
|
||||
};
|
||||
|
||||
export const getMultiLanguagePermission = (team: TTeam): boolean => {
|
||||
export const getMultiLanguagePermission = async (team: TTeam): Promise<boolean> => {
|
||||
if (IS_FORMBRICKS_CLOUD) return team.billing.features.inAppSurvey.status !== "inactive";
|
||||
else if (!IS_FORMBRICKS_CLOUD) return getIsEnterpriseEdition();
|
||||
else if (!IS_FORMBRICKS_CLOUD) return await getIsEnterpriseEdition();
|
||||
else return false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user