Skip to content

Commit 7e3af36

Browse files
alaisterphamhieu
andauthored
fix: storage permissions (supabase#29937)
* fix: storage permissions * write -> read * whoops * right one this time * chore: update @supabase/shared-types * check permissions for creating folders * add additional permissions checks * use buttontooltip --------- Co-authored-by: phamhieu <phamhieu1998@gmail.com>
1 parent 92955d5 commit 7e3af36

File tree

10 files changed

+47
-21
lines changed

10 files changed

+47
-21
lines changed

apps/studio/components/to-be-cleaned/Storage/StorageExplorer/ColumnContextMenu.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { compact, uniqBy } from 'lodash'
22
import { Item, Menu, Separator, Submenu } from 'react-contexify'
33
import 'react-contexify/dist/ReactContexify.css'
44

5+
import { PermissionAction } from '@supabase/shared-types/out/constants'
6+
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
57
import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'
68
import { ChevronRight, ChevronsDown, ChevronsUp, Clipboard, Eye, FolderPlus } from 'lucide-react'
79
import {
@@ -16,6 +18,7 @@ interface ColumnContextMenuProps {
1618
}
1719

1820
const ColumnContextMenu = ({ id = '' }: ColumnContextMenuProps) => {
21+
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_WRITE, '*')
1922
const storageExplorerStore = useStorageStore()
2023
const {
2124
columns,
@@ -57,11 +60,15 @@ const ColumnContextMenu = ({ id = '' }: ColumnContextMenuProps) => {
5760

5861
return (
5962
<Menu id={id} animation="fade">
60-
<Item onClick={({ props }) => onSelectCreateFolder(props.index)}>
61-
<FolderPlus size="14" strokeWidth={1} />
62-
<span className="ml-2 text-xs">New folder</span>
63-
</Item>
64-
<Separator />
63+
{canUpdateFiles && (
64+
<>
65+
<Item onClick={({ props }) => onSelectCreateFolder(props.index)}>
66+
<FolderPlus size="14" strokeWidth={1} />
67+
<span className="ml-2 text-xs">New folder</span>
68+
</Item>
69+
<Separator />
70+
</>
71+
)}
6572
<Item onClick={({ props }) => onSelectAllItemsInColumn(props.index)}>
6673
<Clipboard size="14" strokeWidth={1} />
6774
<span className="ml-2 text-xs">Select all items</span>

apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const FileExplorerHeader = ({
183183

184184
const breadcrumbs = columns.map((column) => column.name)
185185
const backDisabled = columns.length <= 1
186-
const canUpdateStorage = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
186+
const canUpdateStorage = useCheckPermissions(PermissionAction.STORAGE_WRITE, '*')
187187

188188
useEffect(() => {
189189
if (itemSearchString) setSearchString(itemSearchString)

apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeaderSelection.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import { Download, Move, Trash2, X } from 'lucide-react'
2+
3+
import { PermissionAction } from '@supabase/shared-types/out/constants'
4+
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
5+
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
16
import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'
2-
import { X, Download, Trash2, Move } from 'lucide-react'
37
import { Button } from 'ui'
48

59
const FileExplorerHeaderSelection = () => {
10+
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_WRITE, '*')
611
const storageExplorerStore = useStorageStore()
712
const {
813
selectedItems,
@@ -39,20 +44,34 @@ const FileExplorerHeaderSelection = () => {
3944
Download
4045
</Button>
4146
<div className="border-r border-green-900 py-3 opacity-50" />
42-
<Button
47+
48+
<ButtonTooltip
4349
icon={<Trash2 size={16} strokeWidth={2} />}
4450
type="primary"
4551
onClick={() => setSelectedItemsToDelete(selectedItems)}
52+
tooltip={{
53+
content: {
54+
side: 'bottom',
55+
text: !canUpdateFiles ? 'You need additional permissions to delete files' : undefined,
56+
},
57+
}}
4658
>
4759
Delete
48-
</Button>
49-
<Button
60+
</ButtonTooltip>
61+
62+
<ButtonTooltip
5063
icon={<Move size={16} strokeWidth={2} />}
5164
type="primary"
5265
onClick={() => setSelectedItemsToMove(selectedItems)}
66+
tooltip={{
67+
content: {
68+
side: 'bottom',
69+
text: !canUpdateFiles ? 'You need additional permissions to move files' : undefined,
70+
},
71+
}}
5372
>
5473
Move
55-
</Button>
74+
</ButtonTooltip>
5675
</div>
5776
</div>
5877
)

apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const FileExplorerRow: ItemRenderer<StorageItem, FileExplorerRowProps> = ({
139139
const isOpened =
140140
openedFolders.length > columnIndex ? isEqual(openedFolders[columnIndex], item) : false
141141
const isPreviewed = !isEmpty(selectedFilePreview) && isEqual(selectedFilePreview?.id, item.id)
142-
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
142+
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_WRITE, '*')
143143

144144
const { show } = useContextMenu()
145145

apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FolderContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const FolderContextMenu = ({ id = '' }: FolderContextMenuProps) => {
1515
const storageExplorerStore = useStorageStore()
1616
const { openedFolders, downloadFolder, setSelectedItemToRename, setSelectedItemsToDelete } =
1717
storageExplorerStore
18-
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
18+
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_WRITE, '*')
1919

2020
return (
2121
<Menu id={id} animation="fade">

apps/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const ItemContextMenu = ({ id = '' }: ItemContextMenuProps) => {
2727
} = storageExplorerStore
2828
const { onCopyUrl } = useCopyUrl(storageExplorerStore.projectRef)
2929
const isPublic = selectedBucket.public
30-
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
30+
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_WRITE, '*')
3131

3232
const onHandleClick = async (event: any, item: StorageItemWithColumn, expiresIn?: number) => {
3333
if (item.isCorrupted) return

apps/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const PreviewPane = () => {
107107
} = storageExplorerStore
108108
const { onCopyUrl } = useCopyUrl(storageExplorerStore.projectRef)
109109

110-
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
110+
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_WRITE, '*')
111111

112112
if (!file) {
113113
return null

apps/studio/components/to-be-cleaned/Storage/StorageSettings/S3Connection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const S3Connection = () => {
3333
const [openDeleteDialog, setOpenDeleteDialog] = useState(false)
3434
const [deleteCred, setDeleteCred] = useState<{ id: string; description: string }>()
3535

36-
const canReadS3Credentials = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
36+
const canReadS3Credentials = useCheckPermissions(PermissionAction.STORAGE_ADMIN_READ, '*')
3737

3838
const { data: projectAPI } = useProjectApiQuery({ projectRef: projectRef })
3939
const { data: storageCreds, ...storageCredsQuery } = useStorageCredentialsQuery(

apps/studio/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@supabase/auth-js": "2.64.2",
4141
"@supabase/pg-meta": "*",
4242
"@supabase/realtime-js": "2.10.2",
43-
"@supabase/shared-types": "0.1.73",
43+
"@supabase/shared-types": "0.1.74",
4444
"@supabase/supabase-js": "^2.44.3",
4545
"@tanstack/react-query": "4.35.7",
4646
"@tanstack/react-query-devtools": "4.35.7",

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)