onSaveField(field.id!, val)}
- readOnly={readOnly || field.readOnly}
+ onSave={canEdit ? (val) => onSaveField(field.id!, val) : undefined}
+ readOnly={readOnly || field.readOnly || !canEdit}
/>
diff --git a/packages/webui/components/folder-tree.tsx b/packages/webui/components/folder-tree.tsx
index bd53c90f..3db77c50 100644
--- a/packages/webui/components/folder-tree.tsx
+++ b/packages/webui/components/folder-tree.tsx
@@ -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}
/>
-
- navigate({
- to: '/projects/$projectId/recently-deleted',
- params: { projectId },
- })
- }
- >
-
-
+
+ {canEdit && (
+
+ navigate({
+ to: '/projects/$projectId/recently-deleted',
+ params: { projectId },
+ })
+ }
+ >
+
+
+
+
Recently Deleted
-
Recently Deleted
-
+ )}
@@ -369,12 +375,14 @@ export function FolderTree({
)}
-
+ {canEdit && (
+
+ )}
- e.stopPropagation()}
- >
-
-
-
-
-
- {
- setRenameId(collection.id)
- setRenameType('collection')
- setRenameName(collection.name)
- setIsRenameOpen(true)
- }}
- >
- Rename
-
- {
- setDeleteId(collection.id)
- setDeleteType('collection')
- setIsDeleteOpen(true)
- }}
- >
- Delete
-
-
-
-
+ {canEdit && (
+ e.stopPropagation()}
+ >
+
+
+
+
+
+ {
+ setRenameId(collection.id)
+ setRenameType('collection')
+ setRenameName(collection.name)
+ setIsRenameOpen(true)
+ }}
+ >
+ Rename
+
+ {
+ setDeleteId(collection.id)
+ setDeleteType('collection')
+ setIsDeleteOpen(true)
+ }}
+ >
+ Delete
+
+
+
+
+ )}
)
})}
@@ -491,14 +501,16 @@ export function FolderTree({
)}
-
-
-
+ {canEdit && (
+
+
+
+ )}
{
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({
{link.name}
- e.stopPropagation()}
- >
-
-
-
-
-
- {
- onRenameTrigger(link.id, link.name)
- }}
- >
- Rename
-
- {
- onDeleteTrigger(link.id)
- }}
- >
- Delete
-
-
-
-
+ {canEdit && (
+ e.stopPropagation()}
+ >
+
+
+
+
+
+ {
+ onRenameTrigger(link.id, link.name)
+ }}
+ >
+ Rename
+
+ {
+ onDeleteTrigger(link.id)
+ }}
+ >
+ Delete
+
+
+
+
+ )}
)
}
@@ -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 && (
diff --git a/packages/webui/hooks/use-permissions.ts b/packages/webui/hooks/use-permissions.ts
new file mode 100644
index 00000000..149a2118
--- /dev/null
+++ b/packages/webui/hooks/use-permissions.ts
@@ -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],
+ )
+}
diff --git a/packages/webui/routes/__root.tsx b/packages/webui/routes/__root.tsx
index 62a916b7..ca31d281 100644
--- a/packages/webui/routes/__root.tsx
+++ b/packages/webui/routes/__root.tsx
@@ -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() {
} label="Notifications" badge={badge}>
- 0}
- className={uploading > 0 ? 'text-blue-500' : ''}
- />
- }
- label="Uploads"
- >
-
-
+ {canEdit && (
+ 0}
+ className={uploading > 0 ? 'text-blue-500' : ''}
+ />
+ }
+ label="Uploads"
+ >
+
+
+ )}
diff --git a/packages/webui/routes/teams/$teamId/index.tsx b/packages/webui/routes/teams/$teamId/index.tsx
index 09b940ba..08f3d39c 100644
--- a/packages/webui/routes/teams/$teamId/index.tsx
+++ b/packages/webui/routes/teams/$teamId/index.tsx
@@ -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}
/>
-
+ {canEdit && (
+
+ )}
@@ -302,14 +306,16 @@ function TeamPage() {
- {
- e.stopPropagation()
- handleEditProjectClick(project)
- }}
- >
- Project Settings
-
+ {canEdit && (
+ {
+ e.stopPropagation()
+ handleEditProjectClick(project)
+ }}
+ >
+ Project Settings
+
+ )}
{
@@ -323,12 +329,14 @@ function TeamPage() {
className="pointer-events-none"
/>
- handleDeleteProjectClick(project)}
- >
- Delete
-
+ {canAdmin && (
+ handleDeleteProjectClick(project)}
+ >
+ Delete
+
+ )}
@@ -336,24 +344,26 @@ function TeamPage() {
))}
-
-
-
-
-
- Create Project
-
+ {canEdit && (
+
-
+ )}