Skip to content

Scheduling infrastructure for absolutely everyone.

feat: PBAC - opt-in for organizations. (#24424)

sean-brydon35d140e0a7f6
diff --git a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/SettingsLayoutAppDirClient.tsx b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/SettingsLayoutAppDirClient.tsx
index 792ec1f01bd..39b11ab8c19 100644
--- a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/SettingsLayoutAppDirClient.tsx
+++ b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/SettingsLayoutAppDirClient.tsx
@@ -221,8 +221,7 @@ const useTabs = ({
});
}
- // Add pbac menu item only if feature flag is enabled AND user has permission to view roles
- // This prevents showing the menu item when user has no organization permissions
+ // Add pbac menu item - show opt-in page if not enabled, regular page if enabled
if (isPbacEnabled) {
if (permissions?.canViewRoles) {
newArray.push({
@@ -244,6 +243,14 @@ const useTabs = ({
href: "/settings/organizations/billing",
});
}
+ // Show roles page (modal will appear if PBAC not enabled)
+ if (permissions?.canUpdateOrganization) {
+ newArray.push({
+ name: "roles",
+ href: "/settings/organizations/roles",
+ isBadged: true, // Show "New" badge
+ });
+ }
}
return {
@@ -604,17 +611,23 @@ const SettingsSidebarContainer = ({
</div>
<div className="my-3 space-y-px">
{tab.children?.map((child, index) => (
- <VerticalTabItem
- key={child.href}
- name={t(child.name)}
- isExternalLink={child.isExternalLink}
- href={child.href || "/"}
- textClassNames="text-emphasis font-medium text-sm"
- className={`me-5 h-7 w-auto !px-2 ${
- tab.children && index === tab.children?.length - 1 && "!mb-3"
- }`}
- disableChevron
- />
+ <div key={child.href} className="flex items-start gap-2">
+ <VerticalTabItem
+ name={t(child.name)}
+ isExternalLink={child.isExternalLink}
+ href={child.href || "/"}
+ textClassNames="text-emphasis font-medium text-sm"
+ className={`h-7 w-fit !px-2 ${
+ tab.children && index === tab.children?.length - 1 && "!mb-3"
+ }`}
+ disableChevron
+ />
+ {child.isBadged && (
+ <Badge variant="blue" className="mt-0.5 text-xs">
+ New
+ </Badge>
+ )}
+ </div>
))}
</div>
</React.Fragment>
diff --git a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/FingerprintAnimation.tsx b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/FingerprintAnimation.tsx
new file mode 100644
index 00000000000..da28eb661f9
--- /dev/null
+++ b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/FingerprintAnimation.tsx
@@ -0,0 +1,63 @@
+"use client";
+
+import { motion } from "framer-motion";
+
+interface FingerprintAnimationProps {
+ isHovered: boolean;
+}
+
+export function FingerprintAnimation({ isHovered }: FingerprintAnimationProps) {
+ return (
+ <div className="size-32 relative mx-auto flex aspect-square rounded-full border before:absolute before:-inset-2 before:rounded-full before:border dark:border-white/10 dark:before:border-white/5">
+ <svg className="m-auto h-fit w-24" viewBox="0 0 212 143" fill="none" xmlns="http://www.w3.org/2000/svg">
+ {/*Fingerprint*/}
+ <path
+ className="text-subtle"
+ d="M44.0209 55.3542C43.1945 54.7639 42.6916 54.0272 42.5121 53.1442C42.3327 52.2611 42.5995 51.345 43.3125 50.3958C50.632 40.3611 59.812 32.5694 70.8525 27.0208C81.8931 21.4722 93.668 18.6979 106.177 18.6979C118.691 18.6979 130.497 21.3849 141.594 26.7587C152.691 32.1326 161.958 39.8936 169.396 50.0417C170.222 51.1042 170.489 52.0486 170.196 52.875C169.904 53.7014 169.401 54.4097 168.688 55C167.979 55.5903 167.153 55.8571 166.208 55.8004C165.264 55.7437 164.438 55.2408 163.729 54.2917C157.236 45.0833 148.885 38.0307 138.675 33.1337C128.466 28.2368 117.633 25.786 106.177 25.7812C94.7257 25.7812 83.9827 28.2321 73.948 33.1337C63.9132 38.0354 55.5903 45.0881 48.9792 54.2917C48.2709 55.3542 47.4445 55.9444 46.5 56.0625C45.5556 56.1806 44.7292 55.9444 44.0209 55.3542ZM126.188 142.656C113.91 139.587 103.875 133.476 96.0834 124.325C88.2917 115.173 84.3959 103.988 84.3959 90.7708C84.3959 84.8681 86.5209 79.9097 90.7709 75.8958C95.0209 71.8819 100.156 69.875 106.177 69.875C112.198 69.875 117.333 71.8819 121.583 75.8958C125.833 79.9097 127.958 84.8681 127.958 90.7708C127.958 94.6667 129.434 97.9439 132.385 100.602C135.337 103.261 138.819 104.588 142.833 104.583C146.847 104.583 150.271 103.256 153.104 100.602C155.938 97.9486 157.354 94.6714 157.354 90.7708C157.354 77.0764 152.337 65.566 142.302 56.2396C132.267 46.9132 120.285 42.25 106.354 42.25C92.4237 42.25 80.441 46.9132 70.4063 56.2396C60.3716 65.566 55.3542 77.0174 55.3542 90.5937C55.3542 93.4271 55.621 96.9687 56.1546 101.219C56.6882 105.469 57.9562 110.427 59.9584 116.094C60.3125 117.156 60.2842 118.101 59.8734 118.927C59.4625 119.753 58.7825 120.344 57.8334 120.698C56.8889 121.052 55.9752 121.024 55.0921 120.613C54.2091 120.202 53.5881 119.522 53.2292 118.573C51.4584 113.969 50.1905 109.395 49.4255 104.853C48.6605 100.31 48.2756 95.6158 48.2709 90.7708C48.2709 75.0694 53.9682 61.9062 65.363 51.2812C76.7577 40.6562 90.3624 35.3437 106.177 35.3437C122.115 35.3437 135.809 40.6562 147.26 51.2812C158.712 61.9062 164.438 75.0694 164.438 90.7708C164.438 96.6736 162.343 101.601 158.155 105.554C153.966 109.506 148.859 111.485 142.833 111.49C136.813 111.49 131.649 109.513 127.342 105.561C123.035 101.608 120.88 96.6783 120.875 90.7708C120.875 86.875 119.43 83.5978 116.54 80.9392C113.65 78.2805 110.196 76.9536 106.177 76.9583C102.163 76.9583 98.7089 78.2876 95.8142 80.9462C92.9195 83.6049 91.4745 86.8797 91.4792 90.7708C91.4792 102.222 94.8745 111.785 101.665 119.458C108.456 127.132 117.22 132.503 127.958 135.573C129.021 135.927 129.729 136.517 130.083 137.344C130.438 138.17 130.497 139.056 130.26 140C130.024 140.826 129.552 141.535 128.844 142.125C128.135 142.715 127.25 142.892 126.188 142.656ZM67.0417 18.3437C66.0973 18.934 65.1528 19.0828 64.2084 18.79C63.2639 18.4972 62.5556 17.8762 62.0834 16.9271C61.6112 15.9826 61.4931 15.1279 61.7292 14.3629C61.9653 13.5979 62.5556 12.9179 63.5 12.3229C70.1112 8.78125 77.0174 6.06597 84.2188 4.17708C91.4202 2.28819 98.7396 1.34375 106.177 1.34375C113.733 1.34375 121.111 2.25986 128.313 4.09208C135.514 5.92431 142.479 8.54986 149.208 11.9687C150.271 12.559 150.892 13.2674 151.071 14.0937C151.251 14.9201 151.161 15.7465 150.802 16.5729C150.448 17.3993 149.858 18.0486 149.031 18.5208C148.205 18.9931 147.201 18.934 146.021 18.3437C139.764 15.1563 133.299 12.7078 126.627 10.9983C119.954 9.28889 113.138 8.43181 106.177 8.42708C99.3299 8.42708 92.6007 9.22514 85.9896 10.8212C79.3785 12.4174 73.0625 14.9249 67.0417 18.3437ZM87.9375 140.177C80.9723 132.858 75.6314 125.392 71.915 117.78C68.1987 110.167 66.3381 101.164 66.3334 90.7708C66.3334 80.0278 70.2292 70.9658 78.0209 63.585C85.8125 56.2042 95.198 52.5161 106.177 52.5208C117.156 52.5208 126.601 56.2112 134.51 63.5921C142.42 70.9729 146.375 80.0325 146.375 90.7708C146.375 91.8333 146.052 92.6904 145.405 93.3421C144.758 93.9937 143.901 94.3172 142.833 94.3125C141.889 94.3125 141.063 93.989 140.354 93.3421C139.646 92.6951 139.292 91.8381 139.292 90.7708C139.292 81.9167 136.014 74.5099 129.46 68.5504C122.906 62.591 115.145 59.6089 106.177 59.6042C97.2049 59.6042 89.503 62.5862 83.0713 68.5504C76.6396 74.5146 73.4214 81.9214 73.4167 90.7708C73.4167 100.333 75.0695 108.451 78.375 115.123C81.6806 121.796 86.5209 128.494 92.8959 135.219C93.6042 135.927 93.9584 136.753 93.9584 137.698C93.9584 138.642 93.6042 139.469 92.8959 140.177C92.1875 140.885 91.3612 141.24 90.4167 141.24C89.4723 141.24 88.6459 140.885 87.9375 140.177ZM141.417 128.135C130.91 128.135 121.789 124.594 114.054 117.51C106.319 110.427 102.454 101.514 102.458 90.7708C102.458 89.8264 102.784 89 103.436 88.2917C104.088 87.5833 104.942 87.2292 106 87.2292C107.063 87.2292 107.92 87.5833 108.571 88.2917C109.223 89 109.546 89.8264 109.542 90.7708C109.542 99.625 112.729 106.885 119.104 112.552C125.479 118.219 132.917 121.052 141.417 121.052C142.125 121.052 143.129 120.993 144.427 120.875C145.726 120.757 147.083 120.58 148.5 120.344C149.563 120.108 150.479 120.256 151.248 120.79C152.018 121.324 152.519 122.119 152.75 123.177C152.986 124.122 152.809 124.948 152.219 125.656C151.629 126.365 150.861 126.837 149.917 127.073C147.792 127.663 145.934 127.989 144.342 128.05C142.751 128.112 141.776 128.14 141.417 128.135Z"
+ fill="currentColor"
+ />
+ {/*Clip path to contain animated scanning line*/}
+ <g clipPath="url(#clip0_0_1)">
+ <path
+ d="M44.0209 55.3542C43.1945 54.7639 42.6916 54.0272 42.5121 53.1442C42.3327 52.2611 42.5995 51.345 43.3125 50.3958C50.632 40.3611 59.812 32.5694 70.8525 27.0208C81.8931 21.4722 93.668 18.6979 106.177 18.6979C118.691 18.6979 130.497 21.3849 141.594 26.7587C152.691 32.1326 161.958 39.8936 169.396 50.0417C170.222 51.1042 170.489 52.0486 170.196 52.875C169.904 53.7014 169.401 54.4097 168.688 55C167.979 55.5903 167.153 55.8571 166.208 55.8004C165.264 55.7437 164.438 55.2408 163.729 54.2917C157.236 45.0833 148.885 38.0307 138.675 33.1337C128.466 28.2368 117.633 25.786 106.177 25.7812C94.7257 25.7812 83.9827 28.2321 73.948 33.1337C63.9132 38.0354 55.5903 45.0881 48.9792 54.2917C48.2709 55.3542 47.4445 55.9444 46.5 56.0625C45.5556 56.1806 44.7292 55.9444 44.0209 55.3542ZM126.188 142.656C113.91 139.587 103.875 133.476 96.0834 124.325C88.2917 115.173 84.3959 103.988 84.3959 90.7708C84.3959 84.8681 86.5209 79.9097 90.7709 75.8958C95.0209 71.8819 100.156 69.875 106.177 69.875C112.198 69.875 117.333 71.8819 121.583 75.8958C125.833 79.9097 127.958 84.8681 127.958 90.7708C127.958 94.6667 129.434 97.9439 132.385 100.602C135.337 103.261 138.819 104.588 142.833 104.583C146.847 104.583 150.271 103.256 153.104 100.602C155.938 97.9486 157.354 94.6714 157.354 90.7708C157.354 77.0764 152.337 65.566 142.302 56.2396C132.267 46.9132 120.285 42.25 106.354 42.25C92.4237 42.25 80.441 46.9132 70.4063 56.2396C60.3716 65.566 55.3542 77.0174 55.3542 90.5937C55.3542 93.4271 55.621 96.9687 56.1546 101.219C56.6882 105.469 57.9562 110.427 59.9584 116.094C60.3125 117.156 60.2842 118.101 59.8734 118.927C59.4625 119.753 58.7825 120.344 57.8334 120.698C56.8889 121.052 55.9752 121.024 55.0921 120.613C54.2091 120.202 53.5881 119.522 53.2292 118.573C51.4584 113.969 50.1905 109.395 49.4255 104.853C48.6605 100.31 48.2756 95.6158 48.2709 90.7708C48.2709 75.0694 53.9682 61.9062 65.363 51.2812C76.7577 40.6562 90.3624 35.3437 106.177 35.3437C122.115 35.3437 135.809 40.6562 147.26 51.2812C158.712 61.9062 164.438 75.0694 164.438 90.7708C164.438 96.6736 162.343 101.601 158.155 105.554C153.966 109.506 148.859 111.485 142.833 111.49C136.813 111.49 131.649 109.513 127.342 105.561C123.035 101.608 120.88 96.6783 120.875 90.7708C120.875 86.875 119.43 83.5978 116.54 80.9392C113.65 78.2805 110.196 76.9536 106.177 76.9583C102.163 76.9583 98.7089 78.2876 95.8142 80.9462C92.9195 83.6049 91.4745 86.8797 91.4792 90.7708C91.4792 102.222 94.8745 111.785 101.665 119.458C108.456 127.132 117.22 132.503 127.958 135.573C129.021 135.927 129.729 136.517 130.083 137.344C130.438 138.17 130.497 139.056 130.26 140C130.024 140.826 129.552 141.535 128.844 142.125C128.135 142.715 127.25 142.892 126.188 142.656ZM67.0417 18.3437C66.0973 18.934 65.1528 19.0828 64.2084 18.79C63.2639 18.4972 62.5556 17.8762 62.0834 16.9271C61.6112 15.9826 61.4931 15.1279 61.7292 14.3629C61.9653 13.5979 62.5556 12.9179 63.5 12.3229C70.1112 8.78125 77.0174 6.06597 84.2188 4.17708C91.4202 2.28819 98.7396 1.34375 106.177 1.34375C113.733 1.34375 121.111 2.25986 128.313 4.09208C135.514 5.92431 142.479 8.54986 149.208 11.9687C150.271 12.559 150.892 13.2674 151.071 14.0937C151.251 14.9201 151.161 15.7465 150.802 16.5729C150.448 17.3993 149.858 18.0486 149.031 18.5208C148.205 18.9931 147.201 18.934 146.021 18.3437C139.764 15.1563 133.299 12.7078 126.627 10.9983C119.954 9.28889 113.138 8.43181 106.177 8.42708C99.3299 8.42708 92.6007 9.22514 85.9896 10.8212C79.3785 12.4174 73.0625 14.9249 67.0417 18.3437ZM87.9375 140.177C80.9723 132.858 75.6314 125.392 71.915 117.78C68.1987 110.167 66.3381 101.164 66.3334 90.7708C66.3334 80.0278 70.2292 70.9658 78.0209 63.585C85.8125 56.2042 95.198 52.5161 106.177 52.5208C117.156 52.5208 126.601 56.2112 134.51 63.5921C142.42 70.9729 146.375 80.0325 146.375 90.7708C146.375 91.8333 146.052 92.6904 145.405 93.3421C144.758 93.9937 143.901 94.3172 142.833 94.3125C141.889 94.3125 141.063 93.989 140.354 93.3421C139.646 92.6951 139.292 91.8381 139.292 90.7708C139.292 81.9167 136.014 74.5099 129.46 68.5504C122.906 62.591 115.145 59.6089 106.177 59.6042C97.2049 59.6042 89.503 62.5862 83.0713 68.5504C76.6396 74.5146 73.4214 81.9214 73.4167 90.7708C73.4167 100.333 75.0695 108.451 78.375 115.123C81.6806 121.796 86.5209 128.494 92.8959 135.219C93.6042 135.927 93.9584 136.753 93.9584 137.698C93.9584 138.642 93.6042 139.469 92.8959 140.177C92.1875 140.885 91.3612 141.24 90.4167 141.24C89.4723 141.24 88.6459 140.885 87.9375 140.177ZM141.417 128.135C130.91 128.135 121.789 124.594 114.054 117.51C106.319 110.427 102.454 101.514 102.458 90.7708C102.458 89.8264 102.784 89 103.436 88.2917C104.088 87.5833 104.942 87.2292 106 87.2292C107.063 87.2292 107.92 87.5833 108.571 88.2917C109.223 89 109.546 89.8264 109.542 90.7708C109.542 99.625 112.729 106.885 119.104 112.552C125.479 118.219 132.917 121.052 141.417 121.052C142.125 121.052 143.129 120.993 144.427 120.875C145.726 120.757 147.083 120.58 148.5 120.344C149.563 120.108 150.479 120.256 151.248 120.79C152.018 121.324 152.519 122.119 152.75 123.177C152.986 124.122 152.809 124.948 152.219 125.656C151.629 126.365 150.861 126.837 149.917 127.073C147.792 127.663 145.934 127.989 144.342 128.05C142.751 128.112 141.776 128.14 141.417 128.135Z"
+ fill="url(#paint0_linear_0_1)"
+ />
+ </g>
+
+ {/* Animated scanning line */}
+ <motion.path
+ className="text-emphasis"
+ d="M48 0H164"
+ stroke="currentColor"
+ strokeWidth="6"
+ strokeLinecap="round"
+ animate={{
+ y: isHovered ? [0, 140, 0] : 0,
+ opacity: isHovered ? [0.3, 1, 0.3] : 0,
+ }}
+ transition={{
+ duration: 2.5,
+ repeat: isHovered ? Infinity : 0,
+ ease: "easeInOut",
+ }}
+ />
+
+ <defs>
+ <linearGradient
+ id="paint0_linear_0_1"
+ x1="106.385"
+ y1="1.34375"
+ x2="106"
+ y2="72"
+ gradientUnits="userSpaceOnUse">
+ <stop stopColor="white" stopOpacity="0" />
+ <stop className="text-emphasis" offset="1" stopColor="currentColor" />
+ </linearGradient>
+ <clipPath id="clip0_0_1">
+ <rect width="129" height="72" fill="white" transform="translate(41)" />
+ </clipPath>
+ </defs>
+ </svg>
+ </div>
+ );
+}
diff --git a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/PbacOptInModal.tsx b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/PbacOptInModal.tsx
new file mode 100644
index 00000000000..efaea779038
--- /dev/null
+++ b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/PbacOptInModal.tsx
@@ -0,0 +1,129 @@
+"use client";
+
+import { useRouter } from "next/navigation";
+import { useState } from "react";
+
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+import { trpc } from "@calcom/trpc/react";
+import { Button } from "@calcom/ui/components/button";
+import { Dialog, DialogContent } from "@calcom/ui/components/dialog";
+import { Icon } from "@calcom/ui/components/icon";
+import { showToast } from "@calcom/ui/components/toast";
+
+import { FingerprintAnimation } from "./FingerprintAnimation";
+
+interface PbacOptInModalProps {
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ revalidateRolesPath: () => Promise<void>;
+}
+
+export function PbacOptInModal({ open, onOpenChange, revalidateRolesPath }: PbacOptInModalProps) {
+ const router = useRouter();
+ const { t } = useLocale();
+ const [isButtonHovered, setIsButtonHovered] = useState(false);
+
+ const enablePbacMutation = trpc.viewer.pbac.enablePbac.useMutation({
+ onSuccess: async () => {
+ showToast(t("pbac_enabled_success"), "success");
+ await revalidateRolesPath();
+ onOpenChange(false);
+ router.refresh();
+ },
+ onError: (error) => {
+ showToast(error.message || t("pbac_enabled_error"), "error");
+ },
+ });
+
+ const handleOptIn = () => {
+ enablePbacMutation.mutate();
+ };
+
+ return (
+ <Dialog open={open} onOpenChange={onOpenChange}>
+ <DialogContent
+ enableOverflow
+ type={undefined}
+ className="max-w-[468px] p-6"
+ preventCloseOnOutsideClick={true}>
+ <div className="flex flex-col items-center gap-8">
+ <div className="flex w-full flex-col items-center gap-6">
+ <FingerprintAnimation isHovered={isButtonHovered} />
+
+ <div className="flex w-full flex-col items-center gap-1 text-center">
+ <h2 className="font-cal text-emphasis text-xl font-semibold">{t("pbac_opt_in_title")}</h2>
+ <p className="text-default text-sm">{t("pbac_opt_in_description")}</p>
+ </div>
+ </div>
+
+ <div className="bg-subtle w-full space-y-px overflow-hidden rounded-xl border border-gray-200">
+ <div className="bg-default flex gap-3 p-3">
+ <div className="bg-subtle flex h-8 w-8 shrink-0 items-center justify-center rounded-md">
+ <Icon name="shield-check" className="text-subtle h-5 w-5" />
+ </div>
+ <div className="flex flex-col gap-1">
+ <p className="text-emphasis text-sm font-semibold">{t("pbac_opt_in_custom_roles_title")}</p>
+ <p className="text-subtle text-sm">{t("pbac_opt_in_custom_roles_desc")}</p>
+ </div>
+ </div>
+
+ <div className="bg-default flex gap-3 p-3">
+ <div className="bg-subtle flex h-8 w-8 shrink-0 items-center justify-center rounded-md">
+ <Icon name="lock" className="text-subtle h-5 w-5" />
+ </div>
+ <div className="flex flex-col gap-1">
+ <p className="text-emphasis text-sm font-semibold">
+ {t("pbac_opt_in_granular_permissions_title")}
+ </p>
+ <p className="text-subtle text-sm">{t("pbac_opt_in_granular_permissions_desc")}</p>
+ </div>
+ </div>
+
+ <div className="bg-default flex gap-3 p-3">
+ <div className="bg-subtle flex h-8 w-8 shrink-0 items-center justify-center rounded-md">
+ <Icon name="users" className="text-subtle h-5 w-5" />
+ </div>
+ <div className="flex flex-col gap-1">
+ <p className="text-emphasis text-sm font-semibold">
+ {t("pbac_opt_in_team_assignment_title")}
+ </p>
+ <p className="text-subtle text-sm">{t("pbac_opt_in_team_assignment_desc")}</p>
+ </div>
+ </div>
+
+ <div className="bg-default flex gap-3 p-3">
+ <div className="bg-subtle flex h-8 w-8 shrink-0 items-center justify-center rounded-md">
+ <Icon name="shield" className="text-subtle h-5 w-5" />
+ </div>
+ <div className="flex flex-col gap-1">
+ <p className="text-emphasis text-sm font-semibold">
+ {t("pbac_opt_in_enhanced_security_title")}
+ </p>
+ <p className="text-subtle text-sm">{t("pbac_opt_in_enhanced_security_desc")}</p>
+ </div>
+ </div>
+ </div>
+
+ <div className="flex w-full flex-col-reverse gap-2 sm:flex-row">
+ <Button
+ color="secondary"
+ onClick={() => onOpenChange(false)}
+ disabled={enablePbacMutation.isPending}
+ className="w-full justify-center sm:w-1/4">
+ {t("cancel")}
+ </Button>
+ <Button
+ onClick={handleOptIn}
+ loading={enablePbacMutation.isPending}
+ className="w-full justify-center sm:w-3/4"
+ EndIcon="arrow-right"
+ onMouseEnter={() => setIsButtonHovered(true)}
+ onMouseLeave={() => setIsButtonHovered(false)}>
+ {t("pbac_opt_in_enable_button")}
+ </Button>
+ </div>
+ </div>
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/PbacOptInView.tsx b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/PbacOptInView.tsx
new file mode 100644
index 00000000000..b5031379aa4
--- /dev/null
+++ b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/PbacOptInView.tsx
@@ -0,0 +1,59 @@
+"use client";
+
+import { useState } from "react";
+
+import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+
+import { PbacOptInModal } from "./PbacOptInModal";
+import { RolesList } from "./RolesList";
+
+type Role = {
+ id: string;
+ name: string;
+ description?: string;
+ teamId?: number;
+ color?: string;
+ createdAt: Date;
+ updatedAt: Date;
+ type: "SYSTEM" | "CUSTOM";
+ permissions: {
+ id: string;
+ resource: string;
+ action: string;
+ }[];
+};
+
+interface PbacOptInViewProps {
+ revalidateRolesPath: () => Promise<void>;
+ systemRoles: Role[];
+ teamId: number;
+}
+
+export function PbacOptInView({ revalidateRolesPath, systemRoles, teamId }: PbacOptInViewProps) {
+ const [open, setOpen] = useState(true);
+ const { t } = useLocale();
+
+ return (
+ <>
+ <SettingsHeader
+ title={t("roles_and_permissions")}
+ description={t("roles_and_permissions_description")}
+ borderInShellHeader={false}
+ CTA={null}>
+ <RolesList
+ teamId={teamId}
+ roles={systemRoles}
+ permissions={{
+ canCreate: false,
+ canRead: true,
+ canUpdate: false,
+ canDelete: false,
+ }}
+ isPrivate={false}
+ />
+ </SettingsHeader>
+ <PbacOptInModal open={open} onOpenChange={setOpen} revalidateRolesPath={revalidateRolesPath} />
+ </>
+ );
+}
diff --git a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/page.tsx b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/page.tsx
index 97a0382843a..dcd08c327e1 100644
--- a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/page.tsx
+++ b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/page.tsx
@@ -1,6 +1,7 @@
import { _generateMetadata, getTranslate } from "app/_utils";
import { unstable_cache } from "next/cache";
import { notFound } from "next/navigation";
+import { revalidatePath } from "next/cache";
import type { AppFlags } from "@calcom/features/flags/config";
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
@@ -13,6 +14,7 @@ import { prisma } from "@calcom/prisma";
import { validateUserHasOrg } from "../actions/validateUserHasOrg";
import { CreateRoleCTA } from "./_components/CreateRoleCta";
+import { PbacOptInView } from "./_components/PbacOptInView";
import { RolesList } from "./_components/RolesList";
import { roleSearchParamsCache } from "./_components/searchParams";
@@ -65,6 +67,11 @@ export const generateMetadata = async () =>
"/settings/organizations/roles"
);
+async function revalidateRolesPath() {
+ "use server";
+ revalidatePath("/settings/organizations/roles");
+}
+
const Page = async ({ searchParams }: { searchParams: Record<string, string | string[] | undefined> }) => {
const t = await getTranslate();
const session = await validateUserHasOrg();
@@ -76,7 +83,18 @@ const Page = async ({ searchParams }: { searchParams: Record<string, string | st
const teamHasPBACFeature = await getCachedTeamFeature(session.user.org.id, "pbac");
if (!teamHasPBACFeature) {
- return notFound();
+ // Get system roles for preview
+ const roleService = new RoleService();
+ const systemRoles = (await roleService.getTeamRoles(session.user.org.id)).filter(
+ (role) => role.type === "SYSTEM"
+ );
+ return (
+ <PbacOptInView
+ revalidateRolesPath={revalidateRolesPath}
+ systemRoles={systemRoles}
+ teamId={session.user.org.id}
+ />
+ );
}
roleSearchParamsCache.parse(searchParams);
diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json
index 2d0cc310756..8638f300fd1 100644
--- a/apps/web/public/static/locales/en/common.json
+++ b/apps/web/public/static/locales/en/common.json
@@ -3463,6 +3463,7 @@
"requires_credits_tooltip": "You need enough credits in your account to use this feature",
"available_credits": "Available credits",
"create_role": "Create role",
+ "roles": "Roles",
"roles_and_permissions": "Roles & Permissions",
"roles_and_permissions_description": "Manage roles and permissions for your organization",
"learn_more_permissions": "Learn more about how Permissions work",
@@ -3576,6 +3577,19 @@
"pbac_desc_view_routing_forms": "View routing forms",
"pbac_desc_update_routing_forms": "Update routing forms",
"pbac_desc_delete_routing_forms": "Delete routing forms",
+ "pbac_opt_in_title": "Enable Roles & Permissions for your organization",
+ "pbac_opt_in_description": "Take control of your organization with customizable roles and granular permissions for your team members.",
+ "pbac_opt_in_custom_roles_title": "Custom roles",
+ "pbac_opt_in_custom_roles_desc": "Create custom roles tailored to your organization's unique workflow",
+ "pbac_opt_in_granular_permissions_title": "Granular permissions",
+ "pbac_opt_in_granular_permissions_desc": "Control exactly what team members can view, edit, and manage",
+ "pbac_opt_in_team_assignment_title": "Team member assignment",
+ "pbac_opt_in_team_assignment_desc": "Easily assign roles to team members as your team grows",
+ "pbac_opt_in_enhanced_security_title": "Enhanced security",
+ "pbac_opt_in_enhanced_security_desc": "Protect sensitive data with organization-wide security controls",
+ "pbac_opt_in_enable_button": "Enable PBAC",
+ "pbac_enabled_success": "Successfully enabled PBAC for your organization",
+ "pbac_enabled_error": "Failed to enable PBAC for your organization",
"read_permission_auto_enabled_tooltip": "Read permission is automatically enabled when creating, updating, or deleting a resource",
"choose_restriction_schedule": "Add restriction schedule",
"restriction_schedule_description": "Limit availability of hosts to only display slots that fall within a specified schedule.",
diff --git a/packages/features/flags/features.repository.ts b/packages/features/flags/features.repository.ts
index 3781766f655..c4baefb7760 100644
--- a/packages/features/flags/features.repository.ts
+++ b/packages/features/flags/features.repository.ts
@@ -190,6 +190,38 @@ export class FeaturesRepository implements IFeaturesRepository {
}
}
+ /**
+ * Enables a feature for a specific team.
+ * @param teamId - The ID of the team to enable the feature for
+ * @param featureId - The feature identifier to enable
+ * @param assignedBy - The user or what assigned the feature
+ * @returns Promise<void>
+ * @throws Error if the feature enabling fails
+ */
+ async enableFeatureForTeam(teamId: number, featureId: keyof AppFlags, assignedBy: string): Promise<void> {
+ try {
+ await this.prismaClient.teamFeatures.upsert({
+ where: {
+ teamId_featureId: {
+ teamId,
+ featureId,
+ },
+ },
+ create: {
+ teamId,
+ featureId,
+ assignedBy,
+ },
+ update: {},
+ });
+ // Clear cache when features are modified
+ this.clearCache();
+ } catch (err) {
+ captureException(err);
+ throw err;
+ }
+ }
+
/**
* Checks if a team or any of its ancestors has access to a specific feature.
* Uses a recursive CTE raw SQL query for performance.
diff --git a/packages/trpc/server/routers/viewer/pbac/_router.tsx b/packages/trpc/server/routers/viewer/pbac/_router.tsx
index 819f90443fd..692ac3a0328 100644
--- a/packages/trpc/server/routers/viewer/pbac/_router.tsx
+++ b/packages/trpc/server/routers/viewer/pbac/_router.tsx
@@ -5,7 +5,7 @@ import { isValidPermissionString } from "@calcom/features/pbac/domain/types/perm
import type { PermissionString } from "@calcom/features/pbac/domain/types/permission-registry";
import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
import { RoleService } from "@calcom/features/pbac/services/role.service";
-import prisma from "@calcom/prisma";
+import { prisma } from "@calcom/prisma";
import { RoleType, MembershipRole } from "@calcom/prisma/enums";
import authedProcedure from "../../../procedures/authedProcedure";
@@ -173,6 +173,7 @@ export const permissionsRouter = router({
.input(
z.object({
teamId: z.number(),
+ includeSystemRolesOnly: z.boolean().optional(),
})
)
.query(async ({ ctx, input }) => {
@@ -183,6 +184,14 @@ export const permissionsRouter = router({
const featureRepo = new FeaturesRepository(prisma);
const teamHasPBACFeature = await featureRepo.checkIfTeamHasFeature(input.teamId, "pbac");
+ // If PBAC is not enabled but caller wants system roles only (for preview), allow it
+ if (!teamHasPBACFeature && input.includeSystemRolesOnly) {
+ const roleService = new RoleService();
+ const allRoles = await roleService.getTeamRoles(input.teamId);
+ // Filter to only return system roles for preview
+ return allRoles.filter((role) => role.type === "SYSTEM");
+ }
+
if (!teamHasPBACFeature) {
throw new Error("PBAC is not enabled for this team");
}
@@ -203,4 +212,45 @@ export const permissionsRouter = router({
const roleService = new RoleService();
return roleService.getTeamRoles(input.teamId);
}),
+
+ enablePbac: authedProcedure.mutation(async ({ ctx }) => {
+ if (!ctx.user?.id) {
+ throw new Error("Unauthorized");
+ }
+
+ // Check for organization ID
+ const orgId = ctx.user.organizationId;
+ if (!orgId) {
+ throw new Error("No organization found for user");
+ }
+
+ // Check if user is ADMIN or OWNER of the organization
+ const membership = await prisma.membership.findFirst({
+ where: {
+ userId: ctx.user.id,
+ teamId: orgId,
+ accepted: true,
+ role: {
+ in: [MembershipRole.ADMIN, MembershipRole.OWNER],
+ },
+ },
+ });
+
+ if (!membership) {
+ throw new Error("You must be an ADMIN or OWNER to enable PBAC for this organization");
+ }
+
+ // Check if PBAC is already enabled for this org
+ const featureRepo = new FeaturesRepository(prisma);
+ const pbacAlreadyEnabled = await featureRepo.checkIfTeamHasFeature(orgId, "pbac");
+
+ if (pbacAlreadyEnabled) {
+ return { success: true, message: "PBAC is already enabled for this organization" };
+ }
+
+ // Enable PBAC feature for the organization
+ await featureRepo.enableFeatureForTeam(orgId, "pbac", "opt-in by user: " + ctx.user.id);
+
+ return { success: true, message: "PBAC enabled successfully" };
+ }),
});
diff --git a/packages/ui/components/navigation/tabs/VerticalTabItem.tsx b/packages/ui/components/navigation/tabs/VerticalTabItem.tsx
index 2d3da4b7c60..8f6095ef7c1 100644
--- a/packages/ui/components/navigation/tabs/VerticalTabItem.tsx
+++ b/packages/ui/components/navigation/tabs/VerticalTabItem.tsx
@@ -27,6 +27,7 @@ export type VerticalTabItemProps = {
iconClassName?: string;
onClick?: (name: string) => void;
isActive?: boolean;
+ isBadged?: boolean;
"data-testid"?: string;
};