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
8 changes: 6 additions & 2 deletions frontend/src/components/common/MediaPreviewDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
<template #default="{ close }">
<div class="flex items-center gap-2 border-b border-outline-gray-1 px-4 py-2">
<p class="flex-1 truncate text-base font-medium text-ink-gray-8">{{ name }}</p>
<Dropdown v-if="downloadMenu?.length" :options="downloadMenu" align="end">
<Button variant="ghost" icon-left="lucide-download" label="Download" />
</Dropdown>
<Button
v-if="downloadUrl"
v-else-if="downloadUrl"
variant="ghost"
icon-left="lucide-download"
label="Download"
Expand Down Expand Up @@ -62,14 +65,15 @@

<script setup lang="ts">
import { computed, onScopeDispose, ref, watch } from 'vue'
import { Button, Dialog } from 'frappe-ui'
import { Button, Dialog, Dropdown, type DropdownOption } from 'frappe-ui'

const props = defineProps<{
open: boolean
url: string
name: string
mime: string
downloadUrl?: string
downloadMenu?: DropdownOption[]
hasPrevious?: boolean
hasNext?: boolean
}>()
Expand Down
43 changes: 42 additions & 1 deletion frontend/src/pages/SharedProjectPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,20 @@
/>
</p>
</div>
<Dropdown
v-if="isConvertibleStill(asset.file_type, asset.file_name)"
:options="downloadMenu(asset)"
align="end"
>
<Button
variant="ghost"
icon="lucide-download"
label="Download"
@click.stop
/>
</Dropdown>
<Button
v-else
variant="ghost"
icon="lucide-download"
label="Download"
Expand Down Expand Up @@ -169,6 +182,11 @@
:name="preview.asset.file_name"
:mime="preview.asset.file_type ?? ''"
:download-url="preview.downloadUrl"
:download-menu="
isConvertibleStill(preview.asset.file_type, preview.asset.file_name)
? downloadMenu(preview.asset)
: undefined
"
@update:open="preview = null"
/>
</div>
Expand All @@ -180,16 +198,18 @@ import { useRoute } from 'vue-router'
import {
Badge,
Button,
Dropdown,
PageHeaderBase,
PageHeaderTitle,
Spinner,
toast,
useCall,
usePageMeta,
type DropdownOption,
} from 'frappe-ui'
import type { ViewUrlResponse } from '@/types'
import EmptyState from '@/components/common/EmptyState.vue'
import { fileKindStyle } from '@/lib/fileType'
import { fileKindStyle, isConvertibleStill } from '@/lib/fileType'
import MediaPreviewDialog from '@/components/common/MediaPreviewDialog.vue'
import { formatBytes, serverMessage } from '@/lib/format'

Expand Down Expand Up @@ -342,6 +362,27 @@ async function downloadAll() {
}
}

function downloadConverted(asset: SharedAsset, format: 'jpeg' | 'png') {
const params = new URLSearchParams({ asset_name: asset.name, format, token: token.value })
if (isFolder.value) params.set('folder', props.folderId ?? '')
else params.set('project', props.projectId ?? '')
const outName = asset.file_name.replace(/\.[^.]+$/, '') + (format === 'jpeg' ? '.jpg' : '.png')
toast.info(`Preparing ${format.toUpperCase()}…`)
triggerDownload(
`/api/v2/method/vms.api.download_shared_converted_asset?${params.toString()}`,
outName,
)
}

function downloadMenu(asset: SharedAsset): DropdownOption[] {
const ext = asset.file_name.match(/\.([^.]+)$/)?.[1]?.toUpperCase() ?? 'file'
return [
{ label: `Original (${ext})`, icon: 'lucide-download', onClick: () => download(asset) },
{ label: 'JPEG', icon: 'lucide-image', onClick: () => downloadConverted(asset, 'jpeg') },
{ label: 'PNG', icon: 'lucide-image', onClick: () => downloadConverted(asset, 'png') },
]
}

function triggerDownload(url: string, fileName: string) {
const anchor = document.createElement('a')
anchor.href = url
Expand Down
32 changes: 32 additions & 0 deletions vms/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2250,3 +2250,35 @@ def get_shared_asset_download_url(

url = generate_presigned_download_url(asset.r2_key, asset.file_name)
return {"url": url}


# nosemgrep: frappe-semgrep-rules.rules.security.guest-whitelisted-method
@frappe.whitelist(allow_guest=True)
@rate_limit(key="asset_name", limit=15, seconds=60, methods=["GET"])
def download_shared_converted_asset(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Guest Endpoint Lacks Tests

The new guest-accessible endpoint has no automated regression coverage for valid project and folder shares, invalid tokens, or assets outside the shared scope. These authorization branches protect a public download path, so relying only on manual probes makes future scope-validation regressions difficult to detect. Please add focused endpoint tests for successful project and folder downloads and the rejection cases.

Prompt To Fix With AI
This is a comment left during a code review.
Path: vms/api.py
Line: 2258

Comment:
**Guest Endpoint Lacks Tests**

The new guest-accessible endpoint has no automated regression coverage for valid project and folder shares, invalid tokens, or assets outside the shared scope. These authorization branches protect a public download path, so relying only on manual probes makes future scope-validation regressions difficult to detect. Please add focused endpoint tests for successful project and folder downloads and the rejection cases.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

asset_name: str,
format: str,
project: str | None = None,
token: str | None = None,
folder: str | None = None,
):
scope_field, scope_value = _validate_shared_asset_scope(project, token, folder)

meta = frappe.db.get_value(
"VMS Asset",
asset_name,
["project", "folder", "status", "deleted_at"],
as_dict=True,
)

if not meta or meta.deleted_at or meta.status == "Uploading" or meta.get(scope_field) != scope_value:
frappe.throw(_("Asset not found in this share"), frappe.DoesNotExistError)

asset = frappe.get_doc("VMS Asset", asset_name)

if not asset.r2_key:
frappe.throw(_("Asset has no R2 key"))

from vms.image_export import serve_converted_download

serve_converted_download(asset, format)
Loading