From 5f6c47233b583d3399069f37e118b3170970444c Mon Sep 17 00:00:00 2001 From: liangfung Date: Mon, 20 Jan 2025 18:02:11 +0800 Subject: [PATCH] feat(ui): prevent SSO users from updating their name & password --- .../(dashboard)/profile/components/change-name.tsx | 14 +++++++++++--- .../profile/components/profile-card.tsx | 10 ++++++++++ .../app/(dashboard)/profile/components/profile.tsx | 6 +++++- .../settings/team/components/user-table.tsx | 14 ++++++++------ ee/tabby-ui/lib/hooks/use-me.ts | 5 +++-- ee/tabby-ui/lib/tabby/query.ts | 1 + 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/ee/tabby-ui/app/(dashboard)/profile/components/change-name.tsx b/ee/tabby-ui/app/(dashboard)/profile/components/change-name.tsx index 454f4d24b4aa..1741501dc78b 100644 --- a/ee/tabby-ui/app/(dashboard)/profile/components/change-name.tsx +++ b/ee/tabby-ui/app/(dashboard)/profile/components/change-name.tsx @@ -13,6 +13,7 @@ import { Button } from '@/components/ui/button' import { Form, FormControl, + FormDescription, FormField, FormItem, FormLabel, @@ -41,8 +42,8 @@ const ChangeNameForm: React.FC = ({ onSuccess, defaultValues }) => { - const [{ data }] = useMe() - + const [{ data, fetching }] = useMe() + const isSsoUser = data?.me?.isSsoUser const formSchema = z.object({ name: z.string() }) @@ -80,8 +81,15 @@ const ChangeNameForm: React.FC = ({ render={({ field }) => ( Name + + {isSsoUser ? 'Name cannot be changed for SSO users' : null} + - + diff --git a/ee/tabby-ui/app/(dashboard)/profile/components/profile-card.tsx b/ee/tabby-ui/app/(dashboard)/profile/components/profile-card.tsx index 6d6ec60dcc7c..32c66a69d025 100644 --- a/ee/tabby-ui/app/(dashboard)/profile/components/profile-card.tsx +++ b/ee/tabby-ui/app/(dashboard)/profile/components/profile-card.tsx @@ -1,5 +1,6 @@ import React from 'react' +import { useMe } from '@/lib/hooks/use-me' import { cn } from '@/lib/utils' import { CardContent, CardTitle } from '@/components/ui/card' import { Separator } from '@/components/ui/separator' @@ -9,6 +10,7 @@ interface ProfileCardProps extends React.HTMLAttributes { description?: string footer?: React.ReactNode footerClassname?: string + hideForSsoUser?: boolean } const ProfileCard: React.FC = ({ @@ -17,9 +19,17 @@ const ProfileCard: React.FC = ({ footer, footerClassname, className, + hideForSsoUser, children, ...props }) => { + const [{ data }] = useMe() + const isSsoUser = data?.me?.isSsoUser + + if (isSsoUser && hideForSsoUser) { + return null + } + return (
- +
diff --git a/ee/tabby-ui/app/(dashboard)/settings/team/components/user-table.tsx b/ee/tabby-ui/app/(dashboard)/settings/team/components/user-table.tsx index 10ed492396e5..b5fbfa45c34c 100644 --- a/ee/tabby-ui/app/(dashboard)/settings/team/components/user-table.tsx +++ b/ee/tabby-ui/app/(dashboard)/settings/team/components/user-table.tsx @@ -311,12 +311,14 @@ function OperationView({ Activate )} - setOpen(true)} - className="cursor-pointer gap-1" - > - Reset password - + {!user.node.isSsoUser && ( + setOpen(true)} + className="cursor-pointer gap-1" + > + Reset password + + )} diff --git a/ee/tabby-ui/lib/hooks/use-me.ts b/ee/tabby-ui/lib/hooks/use-me.ts index 07a55d7000ac..c7d4ff53e2d4 100644 --- a/ee/tabby-ui/lib/hooks/use-me.ts +++ b/ee/tabby-ui/lib/hooks/use-me.ts @@ -6,12 +6,13 @@ const meQuery = graphql(/* GraphQL */ ` query MeQuery { me { id - authToken email + name isAdmin isOwner + authToken isPasswordSet - name + isSsoUser } } `) diff --git a/ee/tabby-ui/lib/tabby/query.ts b/ee/tabby-ui/lib/tabby/query.ts index 87bdfd9dc9ba..85d0b9c5f0b8 100644 --- a/ee/tabby-ui/lib/tabby/query.ts +++ b/ee/tabby-ui/lib/tabby/query.ts @@ -136,6 +136,7 @@ export const listSecuredUsers = graphql(/* GraphQL */ ` createdAt active name + isSsoUser } cursor }