feat(webui): enforce reviewer role restrictions in the UI

This commit is contained in:
yiling
2026-06-07 09:51:33 +08:00
parent 9370c6b255
commit d06b523dc7
15 changed files with 449 additions and 303 deletions
+12 -2
View File
@@ -1,4 +1,5 @@
import type { AncestorFolder } from '@shumai/dtos'
import { usePermissions } from '@/ui/hooks/use-permissions'
import { Badge } from '@/ui/components/ui/badge'
import {
DropdownMenu,
@@ -70,6 +71,7 @@ export function BreadcrumbNav({
versions,
}: BreadcrumbNavProps) {
const navigate = useNavigate()
const { canEdit } = usePermissions()
const handleVersionClick = (versionId: string) => {
if (!projectId || !fileId) return
@@ -155,8 +157,16 @@ export function BreadcrumbNav({
<DropdownMenuItem onClick={() => console.log('Download')}>
Download
</DropdownMenuItem>
<DropdownMenuItem onClick={() => console.log('Rename')}>Rename</DropdownMenuItem>
<DropdownMenuItem onClick={() => console.log('Delete')}>Delete</DropdownMenuItem>
{canEdit && (
<DropdownMenuItem onClick={() => console.log('Rename')}>
Rename
</DropdownMenuItem>
)}
{canEdit && (
<DropdownMenuItem onClick={() => console.log('Delete')}>
Delete
</DropdownMenuItem>
)}
{versions && versions.length > 0 && (
<>
+1 -1
View File
@@ -12,7 +12,7 @@ import ToggleField from './fields/toggle-field'
interface FieldRendererProps {
config: FieldInfo['config']
value: unknown
onSave: (value: unknown) => void
onSave?: (value: unknown) => void
readOnly?: boolean
}
+13 -11
View File
@@ -52,7 +52,7 @@ function SortableFieldItem({ field, index, onVisibilityChange }: SortableFieldIt
type FieldsManagerProps = {
projectId: string
onManageFields: () => void
onManageFields?: () => void
onSave?: () => void
}
@@ -288,16 +288,18 @@ export function FieldsManager({ projectId, onManageFields, onSave }: FieldsManag
</DragDropProvider>
</div>
<div className="mt-4 space-y-2">
<Button variant="secondary" className="w-full" onClick={onManageFields}>
<Settings className="h-4 w-4 mr-2" />
Manage Fields
</Button>
<Button className="w-full" onClick={() => setView('create')}>
<Plus className="h-4 w-4 mr-2" />
New Field
</Button>
</div>
{onManageFields && (
<div className="mt-4 space-y-2">
<Button variant="secondary" className="w-full" onClick={onManageFields}>
<Settings className="h-4 w-4 mr-2" />
Manage Fields
</Button>
<Button className="w-full" onClick={() => setView('create')}>
<Plus className="h-4 w-4 mr-2" />
New Field
</Button>
</div>
)}
</div>
)
}
@@ -45,6 +45,7 @@ interface FileBrowserContextMenuProps {
shareLinks?: ShareLinkInfo[]
onCreateShareLink?: (items: AssetInfo[]) => void
onAddToShareLink?: (shareId: string, items: AssetInfo[]) => void
canEdit?: boolean
}
export function FileBrowserContextMenu({
@@ -69,6 +70,7 @@ export function FileBrowserContextMenu({
shareLinks = [],
onCreateShareLink,
onAddToShareLink,
canEdit = true,
}: FileBrowserContextMenuProps) {
const allItems = [...folders, ...files]
const selectedItems = allItems.filter((i) => selectedIds.has(i.id!))
@@ -129,6 +131,7 @@ export function FileBrowserContextMenu({
}
if (!item) {
if (!canEdit) return null
// Right-click on empty area
return (
<ContextMenuContent
@@ -167,44 +170,54 @@ export function FileBrowserContextMenu({
<Download className="mr-2 h-4 w-4" />
<span>Download</span>
</ContextMenuItem>
<ContextMenuItem onSelect={() => onMoveTo(itemsToModify)}>
<ArrowRight className="mr-2 h-4 w-4" />
<span>Move to</span>
</ContextMenuItem>
<ContextMenuItem onSelect={() => onCopyTo(itemsToModify)}>
<Copy className="mr-2 h-4 w-4" />
<span>Copy to</span>
</ContextMenuItem>
<ContextMenuItem onSelect={handleDelete} className="text-destructive">
<Trash2 className="mr-2 h-4 w-4" />
<span>Delete</span>
</ContextMenuItem>
{canEdit && (
<ContextMenuItem onSelect={() => onMoveTo(itemsToModify)}>
<ArrowRight className="mr-2 h-4 w-4" />
<span>Move to</span>
</ContextMenuItem>
)}
{canEdit && (
<ContextMenuItem onSelect={() => onCopyTo(itemsToModify)}>
<Copy className="mr-2 h-4 w-4" />
<span>Copy to</span>
</ContextMenuItem>
)}
{canEdit && (
<ContextMenuItem onSelect={handleDelete} className="text-destructive">
<Trash2 className="mr-2 h-4 w-4" />
<span>Delete</span>
</ContextMenuItem>
)}
<ContextMenuSeparator />
<ContextMenuItem onSelect={() => onCreateShareLink?.(itemsToModify)}>
<Plus className="mr-2 h-4 w-4" />
<span>Create Share Link</span>
</ContextMenuItem>
{canEdit && (
<>
<ContextMenuSeparator />
<ContextMenuItem onSelect={() => onCreateShareLink?.(itemsToModify)}>
<Plus className="mr-2 h-4 w-4" />
<span>Create Share Link</span>
</ContextMenuItem>
{shareLinks.length > 0 && (
<ContextMenuSub>
<ContextMenuSubTrigger>
<Link className="mr-2 h-4 w-4" />
<span>Add to Share Links</span>
</ContextMenuSubTrigger>
<ContextMenuPortal>
<ContextMenuSubContent className="w-48">
{shareLinks.map((share) => (
<ContextMenuItem
key={share.id}
onSelect={() => onAddToShareLink?.(share.id, itemsToModify)}
>
<span className="truncate">{share.name}</span>
</ContextMenuItem>
))}
</ContextMenuSubContent>
</ContextMenuPortal>
</ContextMenuSub>
{shareLinks.length > 0 && (
<ContextMenuSub>
<ContextMenuSubTrigger>
<Link className="mr-2 h-4 w-4" />
<span>Add to Share Links</span>
</ContextMenuSubTrigger>
<ContextMenuPortal>
<ContextMenuSubContent className="w-48">
{shareLinks.map((share) => (
<ContextMenuItem
key={share.id}
onSelect={() => onAddToShareLink?.(share.id, itemsToModify)}
>
<span className="truncate">{share.name}</span>
</ContextMenuItem>
))}
</ContextMenuSubContent>
</ContextMenuPortal>
</ContextMenuSub>
)}
</>
)}
</ContextMenuContent>
) : (
@@ -213,29 +226,35 @@ export function FileBrowserContextMenu({
e.preventDefault()
}}
>
<ContextMenuItem
onSelect={() => {
handleRename()
}}
>
<Edit className="mr-2 h-4 w-4" />
<span>Rename</span>
</ContextMenuItem>
{canEdit && (
<ContextMenuItem
onSelect={() => {
handleRename()
}}
>
<Edit className="mr-2 h-4 w-4" />
<span>Rename</span>
</ContextMenuItem>
)}
<ContextMenuItem onSelect={handleDownload}>
<Download className="mr-2 h-4 w-4" />
<span>Download</span>
</ContextMenuItem>
<ContextMenuItem onSelect={() => onMoveTo(itemsToModify)}>
<ArrowRight className="mr-2 h-4 w-4" />
<span>Move to</span>
</ContextMenuItem>
<ContextMenuItem onSelect={() => onCopyTo(itemsToModify)}>
<Copy className="mr-2 h-4 w-4" />
<span>Copy to</span>
</ContextMenuItem>
{canEdit && (
<ContextMenuItem onSelect={() => onMoveTo(itemsToModify)}>
<ArrowRight className="mr-2 h-4 w-4" />
<span>Move to</span>
</ContextMenuItem>
)}
{canEdit && (
<ContextMenuItem onSelect={() => onCopyTo(itemsToModify)}>
<Copy className="mr-2 h-4 w-4" />
<span>Copy to</span>
</ContextMenuItem>
)}
{(item.type === 'file' || item.type === 'version_stack') && (
{canEdit && (item.type === 'file' || item.type === 'version_stack') && (
<ContextMenuItem onSelect={() => onNewVersion(item)}>
<UploadCloud className="mr-2 h-4 w-4" />
<span>Create new version</span>
@@ -249,37 +268,41 @@ export function FileBrowserContextMenu({
</ContextMenuItem>
)}
<ContextMenuSeparator />
<ContextMenuItem onSelect={handleDelete} className="text-destructive">
<Trash2 className="mr-2 h-4 w-4" />
<span>Delete</span>
</ContextMenuItem>
{canEdit && (
<>
<ContextMenuSeparator />
<ContextMenuItem onSelect={handleDelete} className="text-destructive">
<Trash2 className="mr-2 h-4 w-4" />
<span>Delete</span>
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem onSelect={() => onCreateShareLink?.(itemsToModify)}>
<Plus className="mr-2 h-4 w-4" />
<span>Create Share Link</span>
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem onSelect={() => onCreateShareLink?.(itemsToModify)}>
<Plus className="mr-2 h-4 w-4" />
<span>Create Share Link</span>
</ContextMenuItem>
{shareLinks.length > 0 && (
<ContextMenuSub>
<ContextMenuSubTrigger>
<Link className="mr-2 h-4 w-4" />
<span>Add to Share Links</span>
</ContextMenuSubTrigger>
<ContextMenuPortal>
<ContextMenuSubContent className="w-48">
{shareLinks.map((share) => (
<ContextMenuItem
key={share.id}
onSelect={() => onAddToShareLink?.(share.id, itemsToModify)}
>
<span className="truncate">{share.name}</span>
</ContextMenuItem>
))}
</ContextMenuSubContent>
</ContextMenuPortal>
</ContextMenuSub>
{shareLinks.length > 0 && (
<ContextMenuSub>
<ContextMenuSubTrigger>
<Link className="mr-2 h-4 w-4" />
<span>Add to Share Links</span>
</ContextMenuSubTrigger>
<ContextMenuPortal>
<ContextMenuSubContent className="w-48">
{shareLinks.map((share) => (
<ContextMenuItem
key={share.id}
onSelect={() => onAddToShareLink?.(share.id, itemsToModify)}
>
<span className="truncate">{share.name}</span>
</ContextMenuItem>
))}
</ContextMenuSubContent>
</ContextMenuPortal>
</ContextMenuSub>
)}
</>
)}
</ContextMenuContent>
)
@@ -8,6 +8,7 @@ import type { SearchCondition, SearchSort } from '@shumai/dtos'
import type { ShareLinkInfo } from '@shumai/dtos'
import type { CreateUploadTaskRequest } from '@shumai/dtos'
import { formatSize } from '@/ui/lib/format'
import { usePermissions } from '@/ui/hooks/use-permissions'
import { useFieldStore } from '@/ui/stores/fields'
import { useUploadStore } from '@/ui/stores/upload'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
@@ -404,6 +405,7 @@ export function FileBrowser({
const newVersionInputRef = useRef<HTMLInputElement>(null)
const [targetVersionFileId, setTargetVersionFileId] = useState<string | null>(null)
const fileContextMenu = useRef(false)
const { canEdit } = usePermissions()
const scrollContainerRef = useRef<HTMLDivElement>(null)
@@ -513,6 +515,7 @@ export function FileBrowser({
selectedCount: selectedIds.size,
isShareView,
fields: displayedFields,
canEdit,
}
if (displayStyle === 'card') {
if (effectiveType === 'folder') return <FolderCard key={item.id} {...props} />
@@ -706,7 +709,7 @@ export function FileBrowser({
const handlePaste = useCallback(
(e: React.ClipboardEvent | ClipboardEvent) => {
if (isShareView || !!collection) return
if (!canEdit || isShareView || !!collection) return
if (!e.clipboardData) return
const items = e.clipboardData.items
const files: File[] = []
@@ -745,7 +748,7 @@ export function FileBrowser({
// Add global paste listener if browser is active
useEffect(() => {
const onGlobalPaste = (e: ClipboardEvent) => {
if (isShareView || !!collection) return
if (!canEdit || isShareView || !!collection) return
// Don't intercept if user is typing in an input
if (
document.activeElement &&
@@ -925,6 +928,7 @@ export function FileBrowser({
shareLinks={shareLinksData?.data ?? []}
onCreateShareLink={handleCreateShareLink}
onAddToShareLink={handleAddToShareLink}
canEdit={canEdit}
/>
</ContextMenu>
)
@@ -932,28 +936,32 @@ export function FileBrowser({
return (
<>
<input
type="file"
ref={fileInputRef}
multiple
style={{ display: 'none' }}
onChange={handleFileChange}
/>
<input
type="file"
ref={folderInputRef}
multiple
/* @ts-expect-error - webkitdirectory is not in the type definition */
webkitdirectory="true"
style={{ display: 'none' }}
onChange={handleFileChange}
/>
<input
type="file"
ref={newVersionInputRef}
style={{ display: 'none' }}
onChange={handleNewVersionFileChange}
/>
{canEdit && (
<>
<input
type="file"
ref={fileInputRef}
multiple
style={{ display: 'none' }}
onChange={handleFileChange}
/>
<input
type="file"
ref={folderInputRef}
multiple
/* @ts-expect-error - webkitdirectory is not in the type definition */
webkitdirectory="true"
style={{ display: 'none' }}
onChange={handleFileChange}
/>
<input
type="file"
ref={newVersionInputRef}
style={{ display: 'none' }}
onChange={handleNewVersionFileChange}
/>
</>
)}
{renderContent()}
{moveCopyMode && (
@@ -50,6 +50,7 @@ interface FileCardProps {
selectedCount?: number
fields: MetadataFieldInfo[]
isShareView?: boolean
canEdit?: boolean
}
export function FileCard({
@@ -75,6 +76,7 @@ export function FileCard({
selectedCount,
fields,
isShareView,
canEdit = true,
}: FileCardProps) {
const [name, setName] = useState(item.name)
const inputRef = useRef<HTMLInputElement>(null)
@@ -315,7 +317,7 @@ export function FileCard({
</DropdownMenuItem>
) : (
<>
{(!isChecked || (selectedCount || 0) <= 1) && (
{canEdit && (!isChecked || (selectedCount || 0) <= 1) && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
@@ -335,17 +337,21 @@ export function FileCard({
<Download className="mr-2 h-4 w-4" />
<span>Download</span>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('delete', item)
}}
className="text-destructive"
>
<Trash2 className="mr-2 h-4 w-4" />
<span>Delete</span>
</DropdownMenuItem>
{canEdit && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('delete', item)
}}
className="text-destructive"
>
<Trash2 className="mr-2 h-4 w-4" />
<span>Delete</span>
</DropdownMenuItem>
</>
)}
</>
)}
</DropdownMenuContent>
@@ -362,8 +368,8 @@ export function FileCard({
<FieldRenderer
config={field.config}
value={itemFieldValueMap[field.id!]?.value}
onSave={(val) => onSaveField(field.id!, val)}
readOnly={field.readOnly}
onSave={canEdit ? (val) => onSaveField(field.id!, val) : undefined}
readOnly={field.readOnly || !canEdit}
/>
</div>
</div>
@@ -32,6 +32,7 @@ interface FileListItemProps {
disabled?: boolean
fields: MetadataFieldInfo[]
columnSizing?: Record<string, number>
canEdit?: boolean
}
export function FileListItem({
@@ -54,6 +55,7 @@ export function FileListItem({
disabled,
fields,
columnSizing,
canEdit = true,
}: FileListItemProps) {
const [name, setName] = useState(item.name)
const inputRef = useRef<HTMLInputElement>(null)
@@ -282,8 +284,8 @@ export function FileListItem({
<FieldRenderer
config={field.config}
value={itemFieldValueMap[field.id!]?.value}
onSave={(val) => onSaveField(field.id!, val)}
readOnly={field.readOnly}
onSave={canEdit ? (val) => onSaveField(field.id!, val) : undefined}
readOnly={field.readOnly || !canEdit}
/>
</td>
))}
@@ -33,6 +33,7 @@ interface FolderCardProps {
onAction?: (action: 'rename' | 'delete' | 'download' | 'restore', item: AssetInfo) => void
isRecentlyDeleted?: boolean
selectedCount?: number
canEdit?: boolean
}
const FolderPreviewGrid = ({ items }: { items: ChildPreview[] }) => {
@@ -105,6 +106,7 @@ export function FolderCard({
onAction,
isRecentlyDeleted,
selectedCount,
canEdit = true,
}: FolderCardProps) {
const [name, setName] = useState(item.name || '')
const inputRef = useRef<HTMLInputElement>(null)
@@ -311,7 +313,7 @@ export function FolderCard({
</DropdownMenuItem>
) : (
<>
{(!isChecked || (selectedCount || 0) <= 1) && (
{canEdit && (!isChecked || (selectedCount || 0) <= 1) && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
@@ -331,17 +333,21 @@ export function FolderCard({
<Download className="mr-2 h-4 w-4" />
<span>Download</span>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('delete', item)
}}
className="text-destructive"
>
<Trash2 className="mr-2 h-4 w-4" />
<span>Delete</span>
</DropdownMenuItem>
{canEdit && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('delete', item)
}}
className="text-destructive"
>
<Trash2 className="mr-2 h-4 w-4" />
<span>Delete</span>
</DropdownMenuItem>
</>
)}
</>
)}
</DropdownMenuContent>
@@ -3,6 +3,7 @@ import type { CollectionInfo } from '@shumai/dtos'
import { type FieldInfo as MetadataFieldInfo } from '@shumai/dtos'
import type { SearchCondition, SearchSort } from '@shumai/dtos'
import { client } from '@/ui/api/client'
import { usePermissions } from '@/ui/hooks/use-permissions'
import { useMutation, useQuery } from '@tanstack/react-query'
import type { InferRequestType, InferResponseType } from 'hono/client'
import { useState } from 'react'
@@ -48,6 +49,7 @@ export function FileBrowserToolbar({
onUpdateCollection,
rootFolderId,
}: FileBrowserToolbarProps) {
const { canEdit } = usePermissions()
const [popoverOpen, setPopoverOpen] = useState(false)
const [searchDialogOpen, setSearchDialogOpen] = useState(false)
const [manageDialogOpen, setManageDialogOpen] = useState(false)
@@ -156,7 +158,7 @@ export function FileBrowserToolbar({
<PopoverContent className="w-auto p-0" align="start">
<FieldsManager
projectId={projectId}
onManageFields={handleManageFields}
onManageFields={canEdit ? handleManageFields : undefined}
onSave={() => setPopoverOpen(false)}
/>
</PopoverContent>
@@ -3,6 +3,7 @@ import type { CollectionInfo } from '@shumai/dtos'
import { type FieldInfo as MetadataFieldInfo } from '@shumai/dtos'
import type { SearchCondition, SearchSort } from '@shumai/dtos'
import { client } from '@/ui/api/client'
import { usePermissions } from '@/ui/hooks/use-permissions'
import { useMutation } from '@tanstack/react-query'
import { InferRequestType, InferResponseType } from 'hono/client'
@@ -46,6 +47,7 @@ export default function FileSystemManager({
}: FileSystemManagerProps) {
const navigate = useNavigate()
const queryClient = useQueryClient()
const { canEdit } = usePermissions()
const { loadedProjectId, setFields } = useFieldStore()
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
const { mutate: patchMetadata } = useMutation<
@@ -397,7 +399,7 @@ export default function FileSystemManager({
<DragDropProvider
modifiers={[SnapToPointer.configure({ anchor: { x: 0, y: 0 } })]}
sensors={
isRecentlyDeleted
isRecentlyDeleted || !canEdit
? []
: [
PointerSensor.configure({
@@ -2,6 +2,7 @@ import type { AssetInfo, AttachmentInfo, CommentInfo, FieldValueInfo } from '@sh
import { type FieldInfo as MetadataFieldInfo } from '@shumai/dtos'
import type { UserInfo } from '@shumai/dtos'
import { client } from '@/ui/api/client'
import { usePermissions } from '@/ui/hooks/use-permissions'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/ui/components/ui/tabs'
import { useFieldStore } from '@/ui/stores/fields'
import type { Annotation } from '@/ui/types'
@@ -48,6 +49,7 @@ export function FileViewerRightSidebar({
onTyping,
selectedCommentId,
}: FileViewerRightSidebarProps) {
const { canEdit } = usePermissions()
const { fields, setFields } = useFieldStore()
const queryClient = useQueryClient()
const { ref, inView } = useInView()
@@ -431,8 +433,8 @@ export function FileViewerRightSidebar({
<FieldRenderer
config={field.config}
value={itemFieldValueMap[field.id!]?.value}
onSave={(val) => onSaveField(field.id!, val)}
readOnly={readOnly || field.readOnly}
onSave={canEdit ? (val) => onSaveField(field.id!, val) : undefined}
readOnly={readOnly || field.readOnly || !canEdit}
/>
</div>
</div>
+123 -103
View File
@@ -1,5 +1,6 @@
import type { AssetInfoPaginatedList, AssetInfo } from '@shumai/dtos'
import { client } from '@/ui/api/client'
import { usePermissions } from '@/ui/hooks/use-permissions'
import { cn } from '@/ui/lib/utils'
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { useMatch, useNavigate, useParams } from '@tanstack/react-router'
@@ -76,6 +77,7 @@ export function FolderTree({
}: FolderTreeProps) {
const navigate = useNavigate()
const queryClient = useQueryClient()
const { canEdit } = usePermissions()
const isRecentlyDeleted = useMatch({
from: '/projects/$projectId/recently-deleted',
shouldThrow: false,
@@ -329,24 +331,28 @@ export function FolderTree({
dragState={dragState}
onSelect={onSelect}
selectedFolderId={selectedFolderId}
canEdit={canEdit}
/>
<div
className={cn(
'group flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
isRecentlyDeleted && 'bg-sidebar-accent text-sidebar-accent-foreground font-medium',
)}
onClick={() =>
navigate({
to: '/projects/$projectId/recently-deleted',
params: { projectId },
})
}
>
<div className="flex h-4 w-4 items-center justify-center">
<Trash2 className="h-4 w-4 text-sidebar-primary" />
{canEdit && (
<div
className={cn(
'group flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
isRecentlyDeleted && 'bg-sidebar-accent text-sidebar-accent-foreground font-medium',
)}
onClick={() =>
navigate({
to: '/projects/$projectId/recently-deleted',
params: { projectId },
})
}
>
<div className="flex h-4 w-4 items-center justify-center">
<Trash2 className="h-4 w-4 text-sidebar-primary" />
</div>
<span className="flex-1 truncate text-sidebar-foreground">Recently Deleted</span>
</div>
<span className="flex-1 truncate text-sidebar-foreground">Recently Deleted</span>
</div>
)}
</div>
</div>
@@ -369,12 +375,14 @@ export function FolderTree({
<ChevronsUpDown className="h-3.5 w-3.5 opacity-0 group-hover:opacity-100 transition-opacity duration-200" />
)}
</div>
<button
onClick={() => createCollection()}
className="text-muted-foreground hover:text-foreground flex-none"
>
<Plus className="h-3.5 w-3.5" />
</button>
{canEdit && (
<button
onClick={() => createCollection()}
className="text-muted-foreground hover:text-foreground flex-none"
>
<Plus className="h-3.5 w-3.5" />
</button>
)}
</header>
<div
@@ -427,44 +435,46 @@ export function FolderTree({
</span>
</div>
<div
className="opacity-0 group-hover:opacity-100 transition-opacity"
onClick={(e) => e.stopPropagation()}
>
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon-sm"
className="h-6 w-6 shrink-0 hover:bg-muted hover:text-muted-foreground p-0"
>
<MoreHorizontal className="h-3.5 w-3.5" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-32">
<DropdownMenuItem
onClick={() => {
setRenameId(collection.id)
setRenameType('collection')
setRenameName(collection.name)
setIsRenameOpen(true)
}}
>
Rename
</DropdownMenuItem>
<DropdownMenuItem
className="text-destructive focus:text-destructive focus:bg-destructive/10"
onClick={() => {
setDeleteId(collection.id)
setDeleteType('collection')
setIsDeleteOpen(true)
}}
>
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
{canEdit && (
<div
className="opacity-0 group-hover:opacity-100 transition-opacity"
onClick={(e) => e.stopPropagation()}
>
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon-sm"
className="h-6 w-6 shrink-0 hover:bg-muted hover:text-muted-foreground p-0"
>
<MoreHorizontal className="h-3.5 w-3.5" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-32">
<DropdownMenuItem
onClick={() => {
setRenameId(collection.id)
setRenameType('collection')
setRenameName(collection.name)
setIsRenameOpen(true)
}}
>
Rename
</DropdownMenuItem>
<DropdownMenuItem
className="text-destructive focus:text-destructive focus:bg-destructive/10"
onClick={() => {
setDeleteId(collection.id)
setDeleteType('collection')
setIsDeleteOpen(true)
}}
>
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
)}
</div>
)
})}
@@ -491,14 +501,16 @@ export function FolderTree({
<ChevronsUpDown className="h-3.5 w-3.5 opacity-0 group-hover:opacity-100 transition-opacity duration-200" />
)}
</div>
<div className="flex items-center gap-1 flex-none">
<button
onClick={() => createShareLink()}
className="text-muted-foreground hover:text-foreground"
>
<Plus className="h-3.5 w-3.5" />
</button>
</div>
{canEdit && (
<div className="flex items-center gap-1 flex-none">
<button
onClick={() => createShareLink()}
className="text-muted-foreground hover:text-foreground"
>
<Plus className="h-3.5 w-3.5" />
</button>
</div>
)}
</header>
<div
@@ -532,6 +544,7 @@ export function FolderTree({
link={link}
projectId={projectId}
dragState={dragState}
canEdit={canEdit}
onRenameTrigger={(id, currentName) => {
setRenameId(id)
setRenameType('share')
@@ -631,12 +644,14 @@ function ShareLinkItem({
link,
projectId,
dragState,
canEdit,
onRenameTrigger,
onDeleteTrigger,
}: {
link: ShareLinkInfo
projectId: string
dragState?: DragState
canEdit?: boolean
onRenameTrigger: (id: string, currentName: string) => void
onDeleteTrigger: (id: string) => void
}) {
@@ -679,39 +694,41 @@ function ShareLinkItem({
<span className="truncate text-sidebar-foreground flex-1">{link.name}</span>
</div>
<div
className="opacity-0 group-hover:opacity-100 transition-opacity"
onClick={(e) => e.stopPropagation()}
>
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon-sm"
className="h-6 w-6 shrink-0 hover:bg-muted hover:text-muted-foreground p-0"
>
<MoreHorizontal className="h-3.5 w-3.5" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-32">
<DropdownMenuItem
onClick={() => {
onRenameTrigger(link.id, link.name)
}}
>
Rename
</DropdownMenuItem>
<DropdownMenuItem
className="text-destructive focus:text-destructive focus:bg-destructive/10"
onClick={() => {
onDeleteTrigger(link.id)
}}
>
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
{canEdit && (
<div
className="opacity-0 group-hover:opacity-100 transition-opacity"
onClick={(e) => e.stopPropagation()}
>
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon-sm"
className="h-6 w-6 shrink-0 hover:bg-muted hover:text-muted-foreground p-0"
>
<MoreHorizontal className="h-3.5 w-3.5" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-32">
<DropdownMenuItem
onClick={() => {
onRenameTrigger(link.id, link.name)
}}
>
Rename
</DropdownMenuItem>
<DropdownMenuItem
className="text-destructive focus:text-destructive focus:bg-destructive/10"
onClick={() => {
onDeleteTrigger(link.id)
}}
>
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
)}
</div>
)
}
@@ -725,6 +742,7 @@ interface FolderTreeItemProps {
dragState?: DragState
onSelect?: (folder: AssetInfo) => void
selectedFolderId?: string
canEdit?: boolean
}
function FolderTreeItem({
@@ -736,6 +754,7 @@ function FolderTreeItem({
dragState,
onSelect,
selectedFolderId,
canEdit,
}: FolderTreeItemProps) {
const [isExpanded, setIsExpanded] = useState(isRoot || false)
const navigate = useNavigate()
@@ -824,7 +843,7 @@ function FolderTreeItem({
type: 'folder',
item: folder,
},
disabled: !!isRoot || !!onSelect,
disabled: !!isRoot || !!onSelect || !canEdit,
})
const { ref: setDroppableRef, isDropTarget: isOver } = useDroppable({
@@ -833,7 +852,7 @@ function FolderTreeItem({
type: 'folder',
item: folder,
},
disabled: dragState?.draggedIds.has(folder.id!) || !!onSelect,
disabled: dragState?.draggedIds.has(folder.id!) || !!onSelect || !canEdit,
})
const setNodeRef = (node: HTMLDivElement | null) => {
@@ -905,6 +924,7 @@ function FolderTreeItem({
dragState={dragState}
onSelect={onSelect}
selectedFolderId={selectedFolderId}
canEdit={canEdit}
/>
))}
{hasNextPage && (
+49
View File
@@ -0,0 +1,49 @@
import { client } from '@/ui/api/client'
import { useTeamContextStore } from '@/ui/stores/team-context'
import { useQuery } from '@tanstack/react-query'
import { useMemo } from 'react'
export interface Permissions {
role: string | undefined
/** Whether the user can perform write operations (owner or editor) */
canEdit: boolean
/** Whether the user can perform admin operations (owner only) */
canAdmin: boolean
}
/**
* Hook that derives permission booleans from the current user's team role.
*
* Permission model (mirrors backend AuthzService.checkRole):
* - Read: all roles (owner, editor, reviewer)
* - Edit: owner + editor
* - Admin: owner only
*
* Reuses the same React Query cache key (['teams', teamId, 'me']) populated
* by __root.tsx, so no extra API calls are made.
*/
export function usePermissions(): Permissions {
const teamId = useTeamContextStore((s) => s.teamId)
const { data: me } = useQuery({
queryKey: ['teams', teamId, 'me'],
queryFn: async () => {
if (!teamId) return null
const res = await client.api.teams[':teamId'].me.$get({
param: { teamId },
})
if (!res.ok) throw new Error('Failed to fetch me')
return await res.json()
},
enabled: !!teamId,
})
return useMemo(
() => ({
role: me?.role,
canEdit: me?.role === 'owner' || me?.role === 'editor',
canAdmin: me?.role === 'owner',
}),
[me?.role],
)
}
+15 -11
View File
@@ -5,6 +5,7 @@ import { TopNav } from '@/ui/components/top-nav'
import { HomeIcon, NotificationFillIcon, UploadCloudIcon } from '@/ui/components/ui/icons'
import { Toaster } from '@/ui/components/ui/sonner'
import { UploadTasks } from '@/ui/components/upload-tasks'
import { usePermissions } from '@/ui/hooks/use-permissions'
import { useAuthStore } from '@/ui/stores/auth'
import { useTeamContextStore } from '@/ui/stores/team-context'
import { useUploadStore } from '@/ui/stores/upload'
@@ -20,6 +21,7 @@ import { useEffect } from 'react'
function RootComponent() {
const user = useAuthStore((state) => state.user)
const { uploading } = useUploadStore()
const { canEdit } = usePermissions()
const pathname = useRouterState({ select: (s) => s.location.pathname })
const navigate = useNavigate()
@@ -88,17 +90,19 @@ function RootComponent() {
<DualSidebarItem icon={<NotificationFillIcon />} label="Notifications" badge={badge}>
<NotificationList />
</DualSidebarItem>
<DualSidebarItem
icon={
<UploadCloudIcon
uploading={uploading > 0}
className={uploading > 0 ? 'text-blue-500' : ''}
/>
}
label="Uploads"
>
<UploadTasks />
</DualSidebarItem>
{canEdit && (
<DualSidebarItem
icon={
<UploadCloudIcon
uploading={uploading > 0}
className={uploading > 0 ? 'text-blue-500' : ''}
/>
}
label="Uploads"
>
<UploadTasks />
</DualSidebarItem>
)}
</DualSidebar>
<div className="flex flex-col flex-1 md:pl-16 overflow-hidden relative">
<TopNav />
+47 -37
View File
@@ -1,4 +1,5 @@
import type { ProjectInfo } from '@shumai/dtos'
import { usePermissions } from '@/ui/hooks/use-permissions'
import { client } from '@/ui/api/client'
import { MembersDialog } from '@/ui/components/members-dialog'
import { ProjectDialog } from '@/ui/components/project-dialog'
@@ -35,6 +36,7 @@ import { toast } from 'sonner'
function TeamPage() {
const { teamId } = Route.useParams()
const { canEdit, canAdmin } = usePermissions()
const navigate = useNavigate()
const queryClient = useQueryClient()
@@ -255,13 +257,15 @@ function TeamPage() {
sortDirection={sortDirection}
onSortChange={handleSortChange}
/>
<Button
className="bg-orange-600 hover:bg-orange-700 text-white gap-2"
onClick={handleCreateProjectClick}
>
<PlusIcon className="w-4 h-4" />
Create Project
</Button>
{canEdit && (
<Button
className="bg-orange-600 hover:bg-orange-700 text-white gap-2"
onClick={handleCreateProjectClick}
>
<PlusIcon className="w-4 h-4" />
Create Project
</Button>
)}
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4">
@@ -302,14 +306,16 @@ function TeamPage() {
</button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
handleEditProjectClick(project)
}}
>
Project Settings
</DropdownMenuItem>
{canEdit && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
handleEditProjectClick(project)
}}
>
Project Settings
</DropdownMenuItem>
)}
<DropdownMenuItem
className="flex items-center justify-between gap-4 cursor-pointer"
onSelect={(e) => {
@@ -323,12 +329,14 @@ function TeamPage() {
className="pointer-events-none"
/>
</DropdownMenuItem>
<DropdownMenuItem
className="text-destructive focus:text-destructive"
onClick={() => handleDeleteProjectClick(project)}
>
Delete
</DropdownMenuItem>
{canAdmin && (
<DropdownMenuItem
className="text-destructive focus:text-destructive"
onClick={() => handleDeleteProjectClick(project)}
>
Delete
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
</div>
@@ -336,24 +344,26 @@ function TeamPage() {
</div>
</div>
))}
<div
className={cn(
'shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out border-dashed hover:border-orange-600/50 group',
clickedProjectId === 'create' ? 'scale-95' : 'scale-100',
)}
onClick={handleCreateCardClick}
>
<div className="flex flex-col">
<div className="relative w-full aspect-square flex items-center justify-center bg-zinc-400/5 group-hover:bg-orange-600/5 transition-colors">
<PlusIcon className="w-8 h-8 text-zinc-400 group-hover:text-orange-600 transition-colors" />
</div>
<div className="px-2 h-10 flex items-center justify-center bg-zinc-400/10 border-t group-hover:bg-orange-600/10 transition-colors">
<p className="text-sm text-muted-foreground group-hover:text-orange-600 transition-colors">
Create Project
</p>
{canEdit && (
<div
className={cn(
'shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out border-dashed hover:border-orange-600/50 group',
clickedProjectId === 'create' ? 'scale-95' : 'scale-100',
)}
onClick={handleCreateCardClick}
>
<div className="flex flex-col">
<div className="relative w-full aspect-square flex items-center justify-center bg-zinc-400/5 group-hover:bg-orange-600/5 transition-colors">
<PlusIcon className="w-8 h-8 text-zinc-400 group-hover:text-orange-600 transition-colors" />
</div>
<div className="px-2 h-10 flex items-center justify-center bg-zinc-400/10 border-t group-hover:bg-orange-600/10 transition-colors">
<p className="text-sm text-muted-foreground group-hover:text-orange-600 transition-colors">
Create Project
</p>
</div>
</div>
</div>
</div>
)}
</div>
<ProjectDialog