Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: dataroom index

Marc Seitzd6c9aaf2806f
diff --git a/components/datarooms/actions/rebuild-index-button.tsx b/components/datarooms/actions/rebuild-index-button.tsx
index f0c74c25..69eeb9ec 100644
--- a/components/datarooms/actions/rebuild-index-button.tsx
+++ b/components/datarooms/actions/rebuild-index-button.tsx
@@ -4,6 +4,7 @@ import { PlanEnum } from "@/ee/stripe/constants";
import { ListOrderedIcon } from "lucide-react";
import { toast } from "sonner";
+import { useFeatureFlags } from "@/lib/hooks/use-feature-flags";
import { usePlan } from "@/lib/swr/use-billing";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
@@ -30,17 +31,28 @@ export default function RebuildIndexButton({
dataroomId,
disabled = false,
}: RebuildIndexButtonProps) {
+ const { isFeatureEnabled } = useFeatureFlags();
const { isDatarooms, isDataroomsPlus, isTrial } = usePlan();
const [isLoading, setIsLoading] = useState(false);
const [isOpen, setIsOpen] = useState(false);
- // INFO: Don't render if user doesn't have a datarooms plan
- if (!isDatarooms && !isDataroomsPlus && !isTrial) {
+ const isDataroomIndexEnabled = isFeatureEnabled("dataroomIndex");
+ const hasDataroomsPlan = isDatarooms || isDataroomsPlus || isTrial;
+ const hasDataroomsPlusPlan = isDataroomsPlus;
+
+ // Show button if: feature flag is enabled OR user has datarooms plan or higher
+ const shouldShowButton = isDataroomIndexEnabled || hasDataroomsPlan;
+
+ // Allow usage if: feature flag is enabled OR user has datarooms-plus plan
+ const canUseFeature = isDataroomIndexEnabled || hasDataroomsPlusPlan;
+
+ // Don't render if conditions aren't met
+ if (!shouldShowButton) {
return null;
}
const handleRebuildIndex = async () => {
- if (!isDataroomsPlus) {
+ if (!canUseFeature) {
toast.error("Upgrade to Data Rooms Plus plan to use this feature.");
return;
}
@@ -127,7 +139,7 @@ export default function RebuildIndexButton({
</div>
<DialogFooter>
- {isDataroomsPlus ? (
+ {canUseFeature ? (
<>
<Button variant="outline" onClick={() => setIsOpen(false)}>
Cancel
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/calculate-indexes.ts b/pages/api/teams/[teamId]/datarooms/[id]/calculate-indexes.ts
index 4703577b..f91750e4 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/calculate-indexes.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/calculate-indexes.ts
@@ -40,13 +40,7 @@ export default async function handler(
}
try {
- // Check if dataroomIndex feature flag is enabled
- const featureFlags = await getFeatureFlags({ teamId });
- if (!featureFlags.dataroomIndex) {
- return res.status(403).json({ message: "Feature not enabled" });
- }
-
- // Verify user has access to this dataroom
+ // Verify user has access to this dataroom and get team plan
const dataroom = await prisma.dataroom.findUnique({
where: {
id: dataroomId,
@@ -62,6 +56,11 @@ export default async function handler(
select: {
id: true,
name: true,
+ team: {
+ select: {
+ plan: true,
+ },
+ },
},
});
@@ -69,6 +68,18 @@ export default async function handler(
return res.status(404).json({ message: "Dataroom not found" });
}
+ // Check if user has access: feature flag enabled OR datarooms-plus plan
+ const featureFlags = await getFeatureFlags({ teamId });
+ const hasDataroomsPlusPlan =
+ dataroom.team.plan === "datarooms-plus" ||
+ dataroom.team.plan === "datarooms-plus+old";
+
+ if (!featureFlags.dataroomIndex && !hasDataroomsPlusPlan) {
+ return res.status(403).json({
+ message: "This feature requires a Data Rooms Plus plan",
+ });
+ }
+
// Calculate and update hierarchical indexes
const result = await calculateAndUpdateHierarchicalIndexes(dataroomId);