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.

fix the update form

Kiran K5cbe8c305080
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx
index 2ed8ca3780..31310085f9 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx
@@ -1,6 +1,7 @@
"use client";
import { generateClientSecret } from "@/lib/actions/generate-client-secret";
+import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import { OAuthAppProps } from "@/lib/types";
import { useRemoveOAuthAppModal } from "@/ui/modals/remove-oauth-app-modal";
@@ -14,7 +15,7 @@ import {
Popover,
TokenAvatar,
} from "@dub/ui";
-import { cn, fetcher } from "@dub/utils";
+import { fetcher } from "@dub/utils";
import { ChevronLeft, RefreshCcw, Trash } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
import Link from "next/link";
@@ -25,7 +26,7 @@ import useSWR from "swr";
export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
const searchParams = useSearchParams();
- const { slug, id: workspaceId } = useWorkspace();
+ const { slug, id: workspaceId, role } = useWorkspace();
const [openPopover, setOpenPopover] = useState(false);
const { executeAsync, result, isExecuting } = useAction(
generateClientSecret,
@@ -49,6 +50,11 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
oAuthApp,
});
+ const { error: permissionsError } = clientAccessCheck({
+ action: "oauth_apps.write",
+ role,
+ });
+
if (!isLoading && !oAuthApp) {
return notFound();
}
@@ -66,7 +72,7 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
Back to OAuth Apps
</p>
</Link>
- <div className="flex justify-between gap-2">
+ <div className="flex items-center justify-between gap-2">
{isLoading ? (
<div className="flex items-center gap-x-3">
<div className="rounded-md border border-gray-200 bg-gradient-to-t from-gray-100 p-2">
@@ -100,7 +106,6 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
)}
<Popover
- align="end"
content={
<div className="grid w-screen gap-px p-2 sm:w-48">
<Button
@@ -129,19 +134,19 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
/>
</div>
}
+ align="end"
openPopover={openPopover}
setOpenPopover={setOpenPopover}
>
- <button
+ <Button
+ variant="outline"
+ 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)}
- className={cn(
- "flex h-10 items-center rounded-md border px-1.5 outline-none transition-all",
- "border-gray-200 bg-white text-gray-900 placeholder-gray-400",
- "focus-visible:border-gray-500 data-[state=open]:border-gray-500 data-[state=open]:ring-4 data-[state=open]:ring-gray-200",
- )}
- >
- <ThreeDots className="h-5 w-5 text-gray-500" />
- </button>
+ {...(permissionsError && {
+ disabledTooltip: permissionsError,
+ })}
+ />
</Popover>
</div>
</MaxWidthWrapper>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/new/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/new/page-client.tsx
index 90eb0faaea..ea5d943399 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/new/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/new/page-client.tsx
@@ -1,5 +1,6 @@
"use client";
+import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import AddOAuthAppForm from "@/ui/oauth-apps/add-edit-app-form";
import { MaxWidthWrapper } from "@dub/ui";
@@ -10,7 +11,13 @@ import { redirect } from "next/navigation";
export default function NewOAuthAppPageClient() {
const { slug, flags, role } = useWorkspace();
- if (!flags?.integrations) {
+ const { error: permissionsError } = clientAccessCheck({
+ action: "oauth_apps.write",
+ role,
+ customPermissionDescription: "manage OAuth applications",
+ });
+
+ if (!flags?.integrations || permissionsError) {
redirect(`/${slug}/settings`);
}
diff --git a/apps/web/lib/api/rbac/permissions.ts b/apps/web/lib/api/rbac/permissions.ts
index 2e4c34fdbc..9c7c937243 100644
--- a/apps/web/lib/api/rbac/permissions.ts
+++ b/apps/web/lib/api/rbac/permissions.ts
@@ -88,22 +88,22 @@ export const ROLE_PERMISSIONS: {
},
{
action: "oauth_apps.read",
- description: "Read OAuth apps",
+ description: "read OAuth apps",
roles: ["owner", "member"],
},
{
action: "oauth_apps.write",
- description: "Create, update, or delete OAuth apps",
+ description: "create, update, or delete OAuth apps",
roles: ["owner"],
},
{
action: "integrations.read",
- description: "Read authorized OAuth apps",
+ description: "read authorized OAuth apps",
roles: ["owner", "member"],
},
{
action: "integrations.write",
- description: "Disconnect authorized OAuth apps",
+ description: "disconnect authorized OAuth apps",
roles: ["owner", "member"],
},
];
diff --git a/apps/web/ui/oauth-apps/add-edit-app-form.tsx b/apps/web/ui/oauth-apps/add-edit-app-form.tsx
index 1df681d09b..d64799a77e 100644
--- a/apps/web/ui/oauth-apps/add-edit-app-form.tsx
+++ b/apps/web/ui/oauth-apps/add-edit-app-form.tsx
@@ -1,5 +1,6 @@
"use client";
+import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import { ExistingOAuthApp, NewOAuthApp, OAuthAppProps } from "@/lib/types";
import {
@@ -41,7 +42,7 @@ export default function AddOAuthAppForm({
}) {
const router = useRouter();
const [saving, setSaving] = useState(false);
- const { slug: workspaceSlug, id: workspaceId, flags } = useWorkspace();
+ const { slug: workspaceSlug, id: workspaceId, flags, role } = useWorkspace();
const [urls, setUrls] = useState<{ id: string; value: string }[]>([
{ id: nanoid(), value: "" },
]);
@@ -61,6 +62,12 @@ export default function AddOAuthAppForm({
oAuthApp || defaultValues,
);
+ const { error: permissionsError } = clientAccessCheck({
+ action: "oauth_apps.write",
+ role,
+ customPermissionDescription: "manage OAuth applications",
+ });
+
useEffect(() => {
setData((prev) => ({
...prev,
@@ -191,8 +198,8 @@ export default function AddOAuthAppForm({
const buttonDisabled =
!name || !slug || !developer || !website || !redirectUris;
-
const uploading = screenshots.some((s) => s.uploading);
+ const canManageApp = !permissionsError;
return (
<>
@@ -233,6 +240,7 @@ export default function AddOAuthAppForm({
autoFocus
autoComplete="off"
placeholder="My App"
+ disabled={!canManageApp}
/>
</div>
</div>
@@ -252,6 +260,7 @@ export default function AddOAuthAppForm({
onChange={(e) => setData({ ...data, slug: e.target.value })}
autoComplete="off"
placeholder="my-app"
+ disabled={!canManageApp}
/>
</div>
</div>
@@ -272,6 +281,7 @@ export default function AddOAuthAppForm({
onChange={(e) => {
setData({ ...data, description: e.target.value });
}}
+ disabled={!canManageApp}
/>
</div>
</div>
@@ -292,6 +302,7 @@ export default function AddOAuthAppForm({
onChange={(e) => {
setData({ ...data, readme: e.target.value });
}}
+ disabled={!canManageApp}
/>
</div>
</div>
@@ -324,6 +335,7 @@ export default function AddOAuthAppForm({
</p>
</div>
<button
+ disabled={!canManageApp}
className="h-full rounded-r-md border-l border-gray-200 p-2"
onClick={() => {
setScreenshots((prev) =>
@@ -337,7 +349,7 @@ export default function AddOAuthAppForm({
))}
</Reorder.Group>
- {screenshots.length < 4 && (
+ {canManageApp && screenshots.length < 4 && (
<FileUpload
accept="any"
className="mt-2 aspect-[5/1] w-full rounded-md border border-dashed border-gray-300"
@@ -363,6 +375,7 @@ export default function AddOAuthAppForm({
value={developer}
onChange={(e) => setData({ ...data, developer: e.target.value })}
placeholder="Acme Inc."
+ disabled={!canManageApp}
/>
</div>
</div>
@@ -380,6 +393,7 @@ export default function AddOAuthAppForm({
value={website}
onChange={(e) => setData({ ...data, website: e.target.value })}
placeholder="https://acme.com"
+ disabled={!canManageApp}
/>
</div>
</div>
@@ -400,6 +414,7 @@ export default function AddOAuthAppForm({
variant="secondary"
className="h-7 w-fit px-2.5 py-1 text-xs"
onClick={() => setUrls([...urls, { id: nanoid(), value: "" }])}
+ disabled={!canManageApp}
/>
</div>
@@ -445,6 +460,7 @@ export default function AddOAuthAppForm({
setUrls(newUrls);
}}
className="h-[26px] border-gray-300 px-2.5 py-1 text-xs text-red-500 hover:bg-gray-50"
+ disabled={!canManageApp}
/>
</div>
)}
@@ -468,6 +484,7 @@ export default function AddOAuthAppForm({
fn={(value: boolean) => {
setData({ ...data, pkce: value });
}}
+ disabled={!canManageApp}
/>
</div>
@@ -476,6 +493,9 @@ export default function AddOAuthAppForm({
disabled={buttonDisabled || uploading}
loading={saving}
type="submit"
+ {...(permissionsError && {
+ disabledTooltip: permissionsError,
+ })}
/>
</form>
</>