The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
include the feedbacks
Kiran K35588fe74d4d
diff --git a/apps/web/app/api/domains/[domain]/verify/route.ts b/apps/web/app/api/domains/[domain]/verify/route.tsindex a526b465ff..b923cf5716 100644--- a/apps/web/app/api/domains/[domain]/verify/route.ts+++ b/apps/web/app/api/domains/[domain]/verify/route.ts@@ -103,6 +103,6 @@ export const GET = withWorkspace(});},{- requiredPermissions: ["domains.write"],+ requiredPermissions: ["domains.read"],},);diff --git a/apps/web/app/api/tokens/route.ts b/apps/web/app/api/tokens/route.tsindex 5b5c1fb1e1..ac32b070df 100644--- a/apps/web/app/api/tokens/route.ts+++ b/apps/web/app/api/tokens/route.ts@@ -67,6 +67,14 @@ export const POST = withWorkspace(},});+ // Only workspace owners can create machine users+ if (isMachine && role !== "owner") {+ throw new DubApiError({+ code: "forbidden",+ message: "Only workspace owners can create machine users.",+ });+ }+if (!validateScopesForRole(scopes || [], role)) {throw new DubApiError({code: "unprocessable_entity",diff --git a/apps/web/lib/auth/workspace-edge.ts b/apps/web/lib/auth/workspace-edge.tsindex 89f88a2837..d3b9081fa1 100644--- a/apps/web/lib/auth/workspace-edge.ts+++ b/apps/web/lib/auth/workspace-edge.ts@@ -257,13 +257,17 @@ export const withWorkspaceEdge = (});}- // By default, the user has access to all permissions based on their role+ // Machine users have owner role by default+ // Only workspace owners can create machine users+ if (session.user.isMachine) {+ workspace.users[0].role = "owner";+ }+permissions = getPermissionsByRole(workspace.users[0].role);// Find the subset of permissions that the user has access to based on the token scopesif (isRestrictedToken) {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.tsindex 4796abb53f..f808b8c175 100644--- a/apps/web/lib/auth/workspace.ts+++ b/apps/web/lib/auth/workspace.ts@@ -282,13 +282,17 @@ export const withWorkspace = (}}- // By default, the user has access to all permissions based on their role+ // Machine users have owner role by default+ // Only workspace owners can create machine users+ if (session.user.isMachine) {+ workspace.users[0].role = "owner";+ }+permissions = getPermissionsByRole(workspace.users[0].role);// Find the subset of permissions that the user has access to based on the token scopesif (isRestrictedToken) {const tokenScopes: Scope[] = token.scopes.split(" ") || [];-permissions = mapScopesToPermissions(tokenScopes).filter((p) =>permissions.includes(p),);diff --git a/apps/web/ui/modals/add-edit-token-modal.tsx b/apps/web/ui/modals/add-edit-token-modal.tsxindex 28d7b0aa0c..bafbaac4f1 100644--- a/apps/web/ui/modals/add-edit-token-modal.tsx+++ b/apps/web/ui/modals/add-edit-token-modal.tsx@@ -21,6 +21,7 @@ import {} from "@dub/ui";import { ToggleGroup } from "@dub/ui/src/toggle-group";import { SimpleTooltipContent } from "@dub/ui/src/tooltip";+import { cn } from "@dub/utils";import {Dispatch,FormEvent,@@ -60,7 +61,14 @@ function AddEditTokenModal({onTokenCreated?: (token: string) => void;}) {const [saving, setSaving] = useState(false);- const { id: workspaceId, logo, slug, betaTester, isOwner } = useWorkspace();+ const {+ id: workspaceId,+ logo,+ slug,+ betaTester,+ role,+ isOwner,+ } = useWorkspace();const [data, setData] = useState<APIKeyProps>(token || newToken);const [preset, setPreset] = useState<ScopePreset>("all_access");@@ -128,7 +136,7 @@ function AddEditTokenModal({(!name || token?.name === name) && token?.scopes === scopes;const scopesByResources = transformScopesForUI(- getScopesByResourceForRole(isOwner ? "owner" : "member"),+ getScopesByResourceForRole(role),).filter((resource) => !resource.betaFeature || betaTester);return (@@ -188,21 +196,38 @@ function AddEditTokenModal({/></Label></div>- <div className="flex w-1/2 items-center space-x-2 rounded-md border border-gray-300 bg-white transition-all hover:bg-gray-50 active:bg-gray-100">+ <div+ className={cn(+ "flex w-1/2 items-center space-x-2 rounded-md border border-gray-300 bg-white transition-all hover:bg-gray-50 active:bg-gray-100",+ {+ "cursor-not-allowed opacity-75": !isOwner,+ },+ )}+ ><RadioGroupItemvalue="machine"id="machine"className="ml-3"+ disabled={!isOwner}/><LabelhtmlFor="machine"- className="flex flex-1 cursor-pointer items-center justify-between space-x-1 p-3 pl-0"+ className={cn(+ "flex flex-1 cursor-pointer items-center justify-between space-x-1 p-3 pl-0",+ {+ "cursor-not-allowed": !isOwner,+ },+ )}><p className="text-gray-600">Machine</p><InfoTooltipcontent={<SimpleTooltipContent- title="A new bot member will be added to your workspace, and the key will be associated with it. Since the key is not tied to your account, it will not be deleted even if you leave the workspace."+ title={+ isOwner+ ? "A new bot member will be added to your workspace, and the key will be associated with it. Since the key is not tied to your account, it will not be deleted even if you leave the workspace."+ : "Only the workspace owner can create machine users."+ }cta="Learn more"href="https://dub.co/docs/api-reference/tokens#machine-users"/>