Skip to content

Commit

Permalink
feat(ui): prevent SSO users from updating their name & password (#3735)
Browse files Browse the repository at this point in the history
* feat(ui): prevent SSO users from updating their name & password

* update

* update

* update

* update
  • Loading branch information
liangfung authored and zwpaper committed Jan 20, 2025
1 parent 059cf2d commit fd18ce3
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 13 deletions.
22 changes: 19 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 @@ -21,6 +21,11 @@ import {
import { IconSpinner } from '@/components/ui/icons'
import { Input } from '@/components/ui/input'
import { Separator } from '@/components/ui/separator'
import {
Tooltip,
TooltipContent,
TooltipTrigger
} from '@/components/ui/tooltip'
import { ListSkeleton } from '@/components/skeleton'

const updateNameMutation = graphql(/* GraphQL */ `
Expand All @@ -41,8 +46,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 @@ -81,7 +86,18 @@ const ChangeNameForm: React.FC<ChangeNameFormProps> = ({
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<Input className="w-full md:w-[350px]" {...field} />
<Tooltip>
<TooltipTrigger asChild>
<Input
className="w-full md:w-[350px]"
{...field}
disabled={fetching || isSsoUser}
/>
</TooltipTrigger>
<TooltipContent hidden={!isSsoUser} align="end" side="top">
Name cannot be changed for SSO users
</TooltipContent>
</Tooltip>
</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 @@ -32,7 +32,7 @@ import {
DropdownMenuItem,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
import { IconMore, IconSpinner } from '@/components/ui/icons'
import { IconInfoCircled, IconMore, IconSpinner } from '@/components/ui/icons'
import {
Pagination,
PaginationContent,
Expand All @@ -48,6 +48,11 @@ import {
TableHeader,
TableRow
} from '@/components/ui/table'
import {
Tooltip,
TooltipContent,
TooltipTrigger
} from '@/components/ui/tooltip'
import LoadingWrapper from '@/components/loading-wrapper'

import { UpdateUserRoleDialog } from './user-role-dialog'
Expand Down Expand Up @@ -311,12 +316,30 @@ 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>
<Tooltip>
<TooltipTrigger asChild>
<span>
<DropdownMenuItem
disabled={user.node.isSsoUser}
onSelect={() => setOpen(true)}
className="cursor-pointer gap-1"
>
<span className="flex items-center gap-1">
<span className="ml-2">Reset password</span>
{user.node.isSsoUser && <IconInfoCircled />}
</span>
</DropdownMenuItem>
</span>
</TooltipTrigger>
<TooltipContent
side="left"
sideOffset={8}
align="center"
hidden={!user.node.isSsoUser}
>
<p>Cannot request password reset for SSO users</p>
</TooltipContent>
</Tooltip>
</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 fd18ce3

Please sign in to comment.