Skip to content

Commit

Permalink
feat(ui): prevent SSO users from updating their name & password
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung committed Jan 20, 2025
1 parent 72478e5 commit 5f6c472
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
14 changes: 11 additions & 3 deletions ee/tabby-ui/app/(dashboard)/profile/components/change-name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Button } from '@/components/ui/button'
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
Expand Down Expand Up @@ -41,8 +42,8 @@ const ChangeNameForm: React.FC<ChangeNameFormProps> = ({
onSuccess,
defaultValues
}) => {
const [{ data }] = useMe()

const [{ data, fetching }] = useMe()
const isSsoUser = data?.me?.isSsoUser
const formSchema = z.object({
name: z.string()
})
Expand Down Expand Up @@ -80,8 +81,15 @@ const ChangeNameForm: React.FC<ChangeNameFormProps> = ({
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormDescription>
{isSsoUser ? 'Name cannot be changed for SSO users' : null}
</FormDescription>
<FormControl>
<Input className="w-full md:w-[350px]" {...field} />
<Input
className="w-full md:w-[350px]"
{...field}
// disabled={fetching || isSsoUser}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand Down
10 changes: 10 additions & 0 deletions ee/tabby-ui/app/(dashboard)/profile/components/profile-card.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -9,6 +10,7 @@ interface ProfileCardProps extends React.HTMLAttributes<HTMLDivElement> {
description?: string
footer?: React.ReactNode
footerClassname?: string
hideForSsoUser?: boolean
}

const ProfileCard: React.FC<ProfileCardProps> = ({
Expand All @@ -17,9 +19,17 @@ const ProfileCard: React.FC<ProfileCardProps> = ({
footer,
footerClassname,
className,
hideForSsoUser,
children,
...props
}) => {
const [{ data }] = useMe()
const isSsoUser = data?.me?.isSsoUser

if (isSsoUser && hideForSsoUser) {
return null
}

return (
<div
className={cn(
Expand Down
6 changes: 5 additions & 1 deletion ee/tabby-ui/app/(dashboard)/profile/components/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export default function Profile() {
>
<Avatar />
</ProfileCard>
<ProfileCard title="Change Password" footerClassname="pb-0">
<ProfileCard
title="Change Password"
footerClassname="pb-0"
hideForSsoUser
>
<ChangePassword />
</ProfileCard>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,14 @@ function OperationView({
<span className="ml-2">Activate</span>
</DropdownMenuItem>
)}
<DropdownMenuItem
onSelect={() => setOpen(true)}
className="cursor-pointer gap-1"
>
<span className="ml-2">Reset password</span>
</DropdownMenuItem>
{!user.node.isSsoUser && (
<DropdownMenuItem
onSelect={() => setOpen(true)}
className="cursor-pointer gap-1"
>
<span className="ml-2">Reset password</span>
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
<AlertDialog open={open} onOpenChange={onOpenChange}>
Expand Down
5 changes: 3 additions & 2 deletions ee/tabby-ui/lib/hooks/use-me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ const meQuery = graphql(/* GraphQL */ `
query MeQuery {
me {
id
authToken
email
name
isAdmin
isOwner
authToken
isPasswordSet
name
isSsoUser
}
}
`)
Expand Down
1 change: 1 addition & 0 deletions ee/tabby-ui/lib/tabby/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const listSecuredUsers = graphql(/* GraphQL */ `
createdAt
active
name
isSsoUser
}
cursor
}
Expand Down

0 comments on commit 5f6c472

Please sign in to comment.