mirror of
https://github.com/supabase/supabase.git
synced 2026-07-07 12:59:40 +08:00
* fix: update Permission params * fix: upgrade check permission hook to support project level role * fix: usePermissionsLoaded * fix: Permission params can be undefined * Scaffold new access management UI * Add validation * Update roles view * Add tooltip * Add button to apply role to all projects * Update UI to select projects first instead of roles * Merge master update UI * Midway trying to implementation project level perms API * First pass implementating updating project level permissions * Add client side validation for assigning/removing roles * Midway implementing new invites * Integrate most of the project level permissions functionality * fix: filter out org-level permissions before checking * Add relevant UI guards in org level pages for project role POV * Minor refactors * Small refactors * More fixes * Moar refactors * More fixes * More fixes * Refactor update role logic and smack some test cases on it * Fixes * Fix type issue * Fix type * more fixes, refactors, adding checks... * MORE fixes * Add perms checking for replicas * Add ButtonTooltip component and use them to prevent repetition of pointer events auto for buttons with tooltips * Convert all buttons with tooltips to use ButtonTooltip * refactor * PRettier * Small fix * Remove commented out code in organization-invitation-accept-mutation * fix: switch to use the platform oauth authorizations routes * Add perms checking for org audit logs and org oauth apps * PRettier * Fix incorrect URL for oauth app flow * Fix incorrect URL for oauth app flow * Fix * Add perms checking for warehouse related UI * Update roles helper icon * remove unused lib * Update package lock... again * Update package lock... again * Smalllll update * Update some checks * Add gate for project level permissions * Last fix * update codegen * Update warehouse endpoint routes * Fix --------- Co-authored-by: phamhieu <phamhieu1998@gmail.com> Co-authored-by: Alaister Young <a@alaisteryoung.com>
100 lines
3.2 KiB
TypeScript
100 lines
3.2 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { ChevronDown, Mail, UserPlus } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import semver from 'semver'
|
|
|
|
import { useCheckPermissions } from 'hooks'
|
|
import { IS_PLATFORM } from 'lib/constants'
|
|
import {
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
TooltipContent_Shadcn_,
|
|
TooltipTrigger_Shadcn_,
|
|
Tooltip_Shadcn_,
|
|
} from 'ui'
|
|
import CreateUserModal from './CreateUserModal'
|
|
import InviteUserModal from './InviteUserModal'
|
|
|
|
export type AddUserDropdownProps = {
|
|
projectKpsVersion?: string
|
|
}
|
|
|
|
const AddUserDropdown = ({ projectKpsVersion }: AddUserDropdownProps) => {
|
|
const inviteEnabled = IS_PLATFORM
|
|
? semver.gte(
|
|
// @ts-ignore
|
|
semver.coerce(projectKpsVersion ?? 'kps-v2.5.4'),
|
|
semver.coerce('kps-v2.5.3')
|
|
)
|
|
: true
|
|
|
|
const canInviteUsers = useCheckPermissions(PermissionAction.AUTH_EXECUTE, 'invite_user')
|
|
const canCreateUsers = useCheckPermissions(PermissionAction.AUTH_EXECUTE, 'create_user')
|
|
|
|
const [inviteVisible, setInviteVisible] = useState(false)
|
|
const [createVisible, setCreateVisible] = useState(false)
|
|
|
|
return (
|
|
<>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button type="primary" iconRight={<ChevronDown size={14} strokeWidth={1.5} />}>
|
|
Add user
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent side="bottom" align="end">
|
|
{inviteEnabled && (
|
|
<Tooltip_Shadcn_>
|
|
<TooltipTrigger_Shadcn_ asChild>
|
|
<DropdownMenuItem
|
|
className="space-x-2 !pointer-events-auto"
|
|
disabled={!canInviteUsers}
|
|
onClick={() => {
|
|
if (canInviteUsers) setInviteVisible(true)
|
|
}}
|
|
>
|
|
<Mail size={14} />
|
|
<p>Send invitation</p>
|
|
</DropdownMenuItem>
|
|
</TooltipTrigger_Shadcn_>
|
|
{!canInviteUsers && (
|
|
<TooltipContent_Shadcn_ side="left">
|
|
You need additional permissions to invite users
|
|
</TooltipContent_Shadcn_>
|
|
)}
|
|
</Tooltip_Shadcn_>
|
|
)}
|
|
|
|
<Tooltip_Shadcn_>
|
|
<TooltipTrigger_Shadcn_ asChild>
|
|
<DropdownMenuItem
|
|
className="space-x-2 !pointer-events-auto"
|
|
disabled={!canCreateUsers}
|
|
onClick={() => {
|
|
if (canCreateUsers) setCreateVisible(true)
|
|
}}
|
|
>
|
|
<UserPlus size={14} />
|
|
<p>Create new user</p>
|
|
</DropdownMenuItem>
|
|
</TooltipTrigger_Shadcn_>
|
|
{!canCreateUsers && (
|
|
<TooltipContent_Shadcn_ side="left">
|
|
You need additional permissions to create users
|
|
</TooltipContent_Shadcn_>
|
|
)}
|
|
</Tooltip_Shadcn_>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
|
|
{inviteEnabled && <InviteUserModal visible={inviteVisible} setVisible={setInviteVisible} />}
|
|
<CreateUserModal visible={createVisible} setVisible={setCreateVisible} />
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default AddUserDropdown
|