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.

chore: Update required permissions for OAuth apps authorized and disconnected routes

Kiran K63ea2e62ab55
diff --git a/apps/web/app/api/oauth-apps/[clientId]/disconnect/route.ts b/apps/web/app/api/oauth-apps/[clientId]/disconnect/route.ts
index 0eea016e44..6806decdf4 100644
--- a/apps/web/app/api/oauth-apps/[clientId]/disconnect/route.ts
+++ b/apps/web/app/api/oauth-apps/[clientId]/disconnect/route.ts
@@ -26,6 +26,6 @@ export const DELETE = withWorkspace(
return NextResponse.json({ id: params.clientId });
},
{
- requiredPermissions: ["workspaces.write"],
+ requiredPermissions: ["integrations.disconnect"],
},
);
diff --git a/apps/web/app/api/oauth-apps/authorized/route.ts b/apps/web/app/api/oauth-apps/authorized/route.ts
index f264f44d07..263c7f2818 100644
--- a/apps/web/app/api/oauth-apps/authorized/route.ts
+++ b/apps/web/app/api/oauth-apps/authorized/route.ts
@@ -47,6 +47,6 @@ export const GET = withWorkspace(
return NextResponse.json(appsAuthorized);
},
{
- requiredPermissions: ["workspaces.read"],
+ requiredPermissions: ["integrations.read"],
},
);
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsx
index 14dd1048e3..c42bda89ea 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsx
@@ -1,5 +1,6 @@
"use client";
+import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import { OAuthAppProps } from "@/lib/types";
import { useAddEditAppModal } from "@/ui/modals/add-edit-oauth-app-modal";
@@ -14,7 +15,7 @@ import {
Popover,
TokenAvatar,
} from "@dub/ui";
-import { Key } from "@dub/ui/src/icons";
+import { Window } from "@dub/ui/src/icons";
import { fetcher } from "@dub/utils";
import { Copy, Edit3, MoreVertical } from "lucide-react";
import { useState } from "react";
@@ -22,7 +23,7 @@ import { toast } from "sonner";
import useSWR from "swr";
export default function OAuthAppPageClient() {
- const { id: workspaceId } = useWorkspace();
+ const { id: workspaceId, role } = useWorkspace();
const { data: apps, isLoading } = useSWR<OAuthAppProps[]>(
`/api/oauth-apps?workspaceId=${workspaceId}`,
fetcher,
@@ -40,7 +41,7 @@ export default function OAuthAppPageClient() {
setShowAppCreatedModal(true);
};
- const { AddEditAppModal, AddAppButton } = useAddEditAppModal({
+ const { AddEditAppModal, setShowAddEditAppModal } = useAddEditAppModal({
onAppCreated,
});
@@ -49,8 +50,8 @@ export default function OAuthAppPageClient() {
<AppCreatedModal />
<AddEditAppModal />
<div className="rounded-lg border border-gray-200 bg-white">
- <div className="flex flex-col items-center justify-between gap-4 space-y-3 border-b border-gray-200 p-5 sm:flex-row sm:space-y-0 sm:p-10">
- <div className="flex max-w-screen-sm flex-col space-y-3">
+ <div className="flex flex-col items-center justify-between gap-4 space-y-3 p-5 sm:flex-row sm:space-y-0 sm:p-10">
+ <div className="flex flex-col space-y-3">
<h2 className="text-xl font-medium">OAuth Applications</h2>
<p className="text-sm text-gray-500">
Applications owned by your workspace. You can use OAuth app to
@@ -64,7 +65,20 @@ export default function OAuthAppPageClient() {
</a>
</p>
</div>
- <AddAppButton />
+ <div className="flex">
+ <Button
+ text="Create App"
+ className="h-9 w-28"
+ onClick={() => setShowAddEditAppModal(true)}
+ disabledTooltip={
+ clientAccessCheck({
+ action: "oauth_apps.write",
+ role,
+ customPermissionDescription: "create OAuth apps",
+ }).error || undefined
+ }
+ />
+ </div>
</div>
{isLoading || !apps ? (
<div className="flex flex-col items-center justify-center space-y-4 py-20">
@@ -85,10 +99,21 @@ export default function OAuthAppPageClient() {
) : (
<div className="flex flex-col items-center justify-center gap-y-4 py-20">
<EmptyState
- icon={Key}
+ icon={Window}
title="No OAuth Applications found for this workspace"
/>
- <AddAppButton />
+ <Button
+ text="Create App"
+ className="h-9 w-28"
+ onClick={() => setShowAddEditAppModal(true)}
+ disabledTooltip={
+ clientAccessCheck({
+ action: "oauth_apps.write",
+ role,
+ customPermissionDescription: "create OAuth apps",
+ }).error || undefined
+ }
+ />
</div>
)}
</div>
diff --git a/apps/web/lib/api/rbac/permissions.ts b/apps/web/lib/api/rbac/permissions.ts
index 9612441a87..3a271a380d 100644
--- a/apps/web/lib/api/rbac/permissions.ts
+++ b/apps/web/lib/api/rbac/permissions.ts
@@ -15,6 +15,8 @@ export const PERMISSION_ACTIONS = [
"conversions.write",
"oauth_apps.read",
"oauth_apps.write",
+ "integrations.read",
+ "integrations.disconnect",
] as const;
export type PermissionAction = (typeof PERMISSION_ACTIONS)[number];
@@ -94,6 +96,16 @@ export const ROLE_PERMISSIONS: {
description: "Create, update, or delete OAuth apps",
roles: ["owner"],
},
+ {
+ action: "integrations.read",
+ description: "Read authorized OAuth apps",
+ roles: ["owner", "member"],
+ },
+ {
+ action: "integrations.disconnect",
+ description: "Disconnect authorized OAuth apps",
+ roles: ["owner", "member"],
+ },
];
// Get permissions for a role
diff --git a/apps/web/lib/auth/workspace-edge.ts b/apps/web/lib/auth/workspace-edge.ts
index 378f2c2ee7..f5f240a3a8 100644
--- a/apps/web/lib/auth/workspace-edge.ts
+++ b/apps/web/lib/auth/workspace-edge.ts
@@ -15,7 +15,7 @@ import {
getPermissionsByRole,
} from "../api/rbac/permissions";
import { throwIfNoAccess } from "../api/tokens/permissions";
-import { ScopeName, mapScopesToPermissions } from "../api/tokens/scopes";
+import { Scope, mapScopesToPermissions } from "../api/tokens/scopes";
import { isBetaTester } from "../edge-config";
import { prismaEdge } from "../prisma/edge";
import { hashToken } from "./hash-token";
@@ -275,7 +275,7 @@ export const withWorkspaceEdge = (
// Find the subset of permissions that the user has access to based on the token scopes
if (isRestrictedToken) {
- const tokenScopes: ScopeName[] = token.scopes.split(" ") || [];
+ const tokenScopes: Scope[] = token.scopes.split(" ") || [];
permissions = mapScopesToPermissions(tokenScopes).filter((p) =>
permissions.includes(p),
);
diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.ts
index fa936200a9..abd295daac 100644
--- a/apps/web/lib/auth/workspace.ts
+++ b/apps/web/lib/auth/workspace.ts
@@ -9,7 +9,7 @@ import {
getPermissionsByRole,
} from "../api/rbac/permissions";
import { throwIfNoAccess } from "../api/tokens/permissions";
-import { ScopeName, mapScopesToPermissions } from "../api/tokens/scopes";
+import { Scope, mapScopesToPermissions } from "../api/tokens/scopes";
import { isBetaTester } from "../edge-config";
import { hashToken } from "./hash-token";
import { Session, getSession } from "./utils";
@@ -299,7 +299,7 @@ export const withWorkspace = (
// Find the subset of permissions that the user has access to based on the token scopes
if (isRestrictedToken) {
- const tokenScopes: ScopeName[] = token.scopes.split(" ") || [];
+ const tokenScopes: Scope[] = token.scopes.split(" ") || [];
permissions = mapScopesToPermissions(tokenScopes).filter((p) =>
permissions.includes(p),
);
diff --git a/apps/web/ui/modals/add-edit-oauth-app-modal.tsx b/apps/web/ui/modals/add-edit-oauth-app-modal.tsx
index 4c35d13477..f7bcdcdc6e 100644
--- a/apps/web/ui/modals/add-edit-oauth-app-modal.tsx
+++ b/apps/web/ui/modals/add-edit-oauth-app-modal.tsx
@@ -280,16 +280,11 @@ export function useAddEditAppModal(
);
}, [showAddEditAppModal, setShowAddEditAppModal]);
- const AddAppButtonCallback = useCallback(() => {
- return <AddAppButton setShowAddEditAppModal={setShowAddEditAppModal} />;
- }, [setShowAddEditAppModal]);
-
return useMemo(
() => ({
setShowAddEditAppModal,
AddEditAppModal: AddEditAppModalCallback,
- AddAppButton: AddAppButtonCallback,
}),
- [setShowAddEditAppModal, AddEditAppModalCallback, AddAppButtonCallback],
+ [setShowAddEditAppModal, AddEditAppModalCallback],
);
}
diff --git a/apps/web/ui/modals/add-edit-token-modal.tsx b/apps/web/ui/modals/add-edit-token-modal.tsx
index 866f901359..79d4ec8616 100644
--- a/apps/web/ui/modals/add-edit-token-modal.tsx
+++ b/apps/web/ui/modals/add-edit-token-modal.tsx
@@ -1,7 +1,7 @@
import { ResourceKey, RESOURCES } from "@/lib/api/rbac/resources";
import {
getScopesByResourceForRole,
- ScopeName,
+ Scope,
scopePresets,
} from "@/lib/api/tokens/scopes";
import useWorkspace from "@/lib/swr/use-workspace";
@@ -35,7 +35,7 @@ import { mutate } from "swr";
type APIKeyProps = {
id?: string;
name: string;
- scopes: { [key: string]: ScopeName };
+ scopes: { [key: string]: Scope };
isMachine: boolean;
};
@@ -294,7 +294,7 @@ function AddEditTokenModal({
<RadioGroup
defaultValue={scopes[resource.key] || ""}
className="flex gap-4"
- onValueChange={(v: ScopeName) => {
+ onValueChange={(v: Scope) => {
setData({
...data,
scopes: {