Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

improve permission check

Kiran Kb2e3c19b7501
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
index d415e57a8b..2e1bc084b5 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
@@ -1,6 +1,5 @@
"use client";
-import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import { WebhookProps } from "@/lib/types";
import AddEditWebhookForm from "@/ui/webhooks/add-edit-webhook-form";
@@ -14,14 +13,9 @@ export default function UpdateWebhookPageClient({
}: {
webhookId: string;
}) {
- const { slug, flags, role, id: workspaceId } = useWorkspace();
+ const { slug, flags, id: workspaceId } = useWorkspace();
- const { error: permissionsError } = clientAccessCheck({
- action: "webhooks.write",
- role,
- });
-
- if (!flags?.webhooks || permissionsError) {
+ if (!flags?.webhooks) {
redirect(`/${slug}/settings`);
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/new/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/new/page-client.tsx
index 9c604e9915..06c8a345c3 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/new/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/new/page-client.tsx
@@ -1,6 +1,5 @@
"use client";
-import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import AddEditWebhookForm from "@/ui/webhooks/add-edit-webhook-form";
import { MaxWidthWrapper } from "@dub/ui";
@@ -13,17 +12,18 @@ export default function NewWebhookPageClient({
}: {
newSecret: string;
}) {
- const { slug, flags, role } = useWorkspace();
+ const { slug, flags, role, plan } = useWorkspace();
- const { error: permissionsError } = clientAccessCheck({
- action: "webhooks.write",
- role,
- });
+ const needsHigherPlan = plan === "free" || plan === "pro";
- if (!flags?.webhooks || permissionsError) {
+ if (!flags?.webhooks) {
redirect(`/${slug}/settings`);
}
+ if (needsHigherPlan) {
+ redirect(`/${slug}/settings/webhooks`);
+ }
+
return (
<>
<MaxWidthWrapper className="grid max-w-screen-lg gap-8">
diff --git a/apps/web/lib/api/tokens/scopes.ts b/apps/web/lib/api/tokens/scopes.ts
index 7b2c097474..ce8cb5c5c8 100644
--- a/apps/web/lib/api/tokens/scopes.ts
+++ b/apps/web/lib/api/tokens/scopes.ts
@@ -13,8 +13,6 @@ export const SCOPES = [
"domains.read",
"domains.write",
"conversions.write",
- "webhooks.read",
- "webhooks.write",
"apis.all", // All API scopes
"apis.read", // All read scopes
] as const;
@@ -120,6 +118,8 @@ export const RESOURCE_SCOPES: {
"tags.write",
"domains.read",
"domains.write",
+ "workspaces.read",
+ "workspaces.write",
"analytics.read",
"conversions.write",
],
diff --git a/apps/web/ui/webhooks/webhook-header.tsx b/apps/web/ui/webhooks/webhook-header.tsx
index a3440a20d9..17c03fd30c 100644
--- a/apps/web/ui/webhooks/webhook-header.tsx
+++ b/apps/web/ui/webhooks/webhook-header.tsx
@@ -109,6 +109,8 @@ export default function WebhookHeader({ webhookId }: { webhookId: string }) {
onClick={() => {
setDeleteWebhookModal(true);
}}
+ disabled={!!permissionsError}
+ disabledTooltip={permissionsError}
/>
</div>
}
@@ -121,9 +123,6 @@ export default function WebhookHeader({ webhookId }: { webhookId: string }) {
className="flex w-8 rounded-md border border-gray-200 px-2 transition-[border-color] duration-200"
icon={<ThreeDots className="h-5 w-5 shrink-0 text-gray-500" />}
onClick={() => setOpenPopover(!openPopover)}
- {...(permissionsError && {
- disabledTooltip: permissionsError,
- })}
/>
</Popover>
</div>