Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions app/(dashboard)/audit-target/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client"

import { useActionChecks, usePermissions } from "@/hooks/use-permissions"
import * as React from "react"
import { useState, useEffect, useCallback, useMemo } from "react"
import { useTranslation } from "react-i18next"
Expand Down Expand Up @@ -35,6 +36,9 @@ export default function AuditTargetPage() {
const { t } = useTranslation()
const message = useMessage()
const dialog = useDialog()
const { canAction, checkAction } = usePermissions()
useActionChecks([{ action: "admin:SetBucketTarget" }])
const canManageAction = canAction("admin:SetBucketTarget")
const { getAuditTargetList, deleteAuditTarget } = useAuditTarget()
const { getModuleSwitches } = useModuleSwitches()

Expand Down Expand Up @@ -96,6 +100,7 @@ export default function AuditTargetPage() {
}

try {
if (!(await checkAction("admin:SetBucketTarget"))) throw new Error(t("Access Denied"))
await deleteAuditTarget(`audit_${row.service}`, row.account_id)
message.success(t("Delete Success"))
loadData()
Expand All @@ -105,12 +110,12 @@ export default function AuditTargetPage() {
message.error(msg)
}
},
[canManageTargets, deleteAuditTarget, loadData, message, t],
[checkAction, canManageTargets, deleteAuditTarget, loadData, message, t],
)

const confirmDelete = useCallback(
(row: RowData) => {
if (!canManageTargets) return
if (!canManageAction || !canManageTargets) return
if (!isConfigSource(row.source)) return

dialog.error({
Expand All @@ -121,7 +126,7 @@ export default function AuditTargetPage() {
onPositiveClick: () => deleteItem(row),
})
},
[canManageTargets, deleteItem, dialog, t],
[canManageAction, canManageTargets, deleteItem, dialog, t],
)

const columns: ColumnDef<RowData>[] = useMemo(
Expand Down Expand Up @@ -169,7 +174,7 @@ export default function AuditTargetPage() {
variant="outline"
size="sm"
onClick={() => confirmDelete(row.original)}
disabled={!canManageTargets}
disabled={!canManageAction || !canManageTargets}
>
<RiDeleteBin5Line className="size-4" aria-hidden />
<span>{t("Delete")}</span>
Expand All @@ -180,7 +185,7 @@ export default function AuditTargetPage() {
),
},
],
[canManageTargets, confirmDelete, t],
[canManageAction, canManageTargets, confirmDelete, t],
)

const { table } = useDataTable<RowData>({
Expand All @@ -200,7 +205,7 @@ export default function AuditTargetPage() {
variant="outline"
className="h-11 w-full sm:h-8 sm:w-auto"
onClick={() => setNewFormOpen(true)}
disabled={!canManageTargets}
disabled={!canManageAction || !canManageTargets}
>
<RiAddLine className="size-4" aria-hidden />
<span>{t("Add Audit Target")}</span>
Expand Down
29 changes: 26 additions & 3 deletions app/(dashboard)/browser/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function BrowserContent({ bucketName, keyPath = "", preview = false, prev
const router = useRouter()
const searchParams = useSearchParams()
const message = useMessage()
const { canCapability } = usePermissions()
const { canCapability, mayCapability, checkCapability, retryPermissions } = usePermissions()
const { headBucket } = useBucket()

const isObjectList = keyPath.endsWith("/") || keyPath === ""
Expand All @@ -50,7 +50,7 @@ export function BrowserContent({ bucketName, keyPath = "", preview = false, prev
const [previewObject, setPreviewObject] = React.useState<Record<string, unknown> | null>(null)
const [previewBucketName, setPreviewBucketName] = React.useState("")
const objectApi = useObject(bucketName)
const canUploadObjects = canCapability("objects.upload", { bucket: bucketName, prefix })
const canUploadObjects = mayCapability("objects.upload", { bucket: bucketName, prefix })

React.useEffect(() => {
if (!bucketName) return
Expand Down Expand Up @@ -86,18 +86,30 @@ export function BrowserContent({ bucketName, keyPath = "", preview = false, prev
}

const handleRefresh = () => {
retryPermissions()
setRefreshTrigger((n) => n + 1)
}

const handleOpenPreview = React.useCallback(
async ({ key, data }: { key?: string; data?: Record<string, unknown> }) => {
if (!key) return
const versionId = typeof data?.SelectedVersionId === "string" ? data.SelectedVersionId : undefined
if (
!(await checkCapability(versionId ? "objects.version.preview" : "objects.preview", {
bucket: bucketName,
objectKey: key,
versionId,
}))
) {
message.error(t("Access Denied"))
return
}
const info = data ?? (await objectApi.getObjectInfo(key))
setPreviewObject(createObjectPreviewInfo(key, info))
setPreviewBucketName(bucketName)
setShowPreview(true)
},
[objectApi, bucketName],
[objectApi, bucketName, checkCapability, message, t],
)

const previewObjectKey = typeof previewObject?.Key === "string" ? previewObject.Key : ""
Expand All @@ -108,10 +120,21 @@ export function BrowserContent({ bucketName, keyPath = "", preview = false, prev
canCapability(previewVersionId ? "objects.version.download" : "objects.download", {
bucket: bucketName,
objectKey: previewObjectKey,
versionId: previewVersionId,
})
const downloadPreview = async () => {
if (!canDownloadPreview || !previewObjectKey) return
try {
if (
!(await checkCapability(previewVersionId ? "objects.version.download" : "objects.download", {
bucket: bucketName,
objectKey: previewObjectKey,
versionId: previewVersionId,
}))
) {
message.error(t("Access Denied"))
return
}
const filename = previewObjectKey.split("/").pop() ?? ""
const url = await objectApi.getSignedUrl(
previewObjectKey,
Expand Down
11 changes: 9 additions & 2 deletions app/(dashboard)/browser/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ function BrowserBucketsPage() {
const router = useRouter()
const message = useMessage()
const dialog = useDialog()
const { canCapability, userInfo, isLoading: accountInfoLoading, hasFetchedPolicy, fetchUserPolicy } = usePermissions()
const {
canCapability,
mayCapability,
userInfo,
isLoading: accountInfoLoading,
hasFetchedPolicy,
fetchUserPolicy,
} = usePermissions()
const { listBuckets, deleteBucket, getBucketPolicyStatus } = useBucket()

const [formVisible, setFormVisible] = useState(false)
Expand All @@ -51,7 +58,7 @@ function BrowserBucketsPage() {
const [policyLoading, setPolicyLoading] = useState(false)
const fetchIdRef = useRef(0)

const canCreateBucket = canCapability("bucket.create")
const canCreateBucket = mayCapability("bucket.create")

const loadPolicyStatus = useCallback(
async (fetchId: number, bucketNames: string[]) => {
Expand Down
17 changes: 11 additions & 6 deletions app/(dashboard)/events-target/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client"

import { useActionChecks, usePermissions } from "@/hooks/use-permissions"
import * as React from "react"
import { useState, useEffect, useCallback, useMemo } from "react"
import { useTranslation } from "react-i18next"
Expand Down Expand Up @@ -51,6 +52,9 @@ export default function EventsTargetPage() {
const { t } = useTranslation()
const message = useMessage()
const dialog = useDialog()
const { canAction, checkAction } = usePermissions()
useActionChecks([{ action: "admin:SetBucketTarget" }])
const canManageAction = canAction("admin:SetBucketTarget")
const { getEventsTargetList, deleteEventTarget, getEventTargetSubscriptions } = useEventTarget()
const { getModuleSwitches } = useModuleSwitches()

Expand Down Expand Up @@ -133,6 +137,7 @@ export default function EventsTargetPage() {
}

try {
if (!(await checkAction("admin:SetBucketTarget"))) throw new Error(t("Access Denied"))
await deleteEventTarget(`notify_${row.service}`, row.account_id)
message.success(t("Delete Success"))
loadData()
Expand All @@ -142,12 +147,12 @@ export default function EventsTargetPage() {
message.error(msg)
}
},
[canManageDestinations, deleteEventTarget, loadData, message, t],
[checkAction, canManageDestinations, deleteEventTarget, loadData, message, t],
)

const confirmDelete = useCallback(
(row: RowData) => {
if (!canManageDestinations) return
if (!canManageAction || !canManageDestinations) return
if (!isConfigSource(row.source)) return

dialog.error({
Expand All @@ -158,7 +163,7 @@ export default function EventsTargetPage() {
onPositiveClick: () => deleteItem(row),
})
},
[canManageDestinations, deleteItem, dialog, t],
[canManageAction, canManageDestinations, deleteItem, dialog, t],
)

const toggleSubscriptions = useCallback(
Expand Down Expand Up @@ -247,7 +252,7 @@ export default function EventsTargetPage() {
variant="outline"
size="sm"
onClick={() => confirmDelete(row.original)}
disabled={!canManageDestinations}
disabled={!canManageAction || !canManageDestinations}
>
<RiDeleteBin5Line className="size-4" aria-hidden />
<span>{t("Delete")}</span>
Expand All @@ -258,7 +263,7 @@ export default function EventsTargetPage() {
),
},
],
[canManageDestinations, confirmDelete, expandedRowId, t, toggleSubscriptions],
[canManageAction, canManageDestinations, confirmDelete, expandedRowId, t, toggleSubscriptions],
)

const { table } = useDataTable<RowData>({
Expand Down Expand Up @@ -321,7 +326,7 @@ export default function EventsTargetPage() {
count={!loading && !loadFailed ? data.length : undefined}
actions={
<>
<Button onClick={() => setNewFormOpen(true)} disabled={!canManageDestinations}>
<Button onClick={() => setNewFormOpen(true)} disabled={!canManageAction || !canManageDestinations}>
<RiAddLine className="size-4" aria-hidden />
<span>{t("Add Event Destination")}</span>
</Button>
Expand Down
Loading