mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
fix(ui): swap native key prompt for a dialog; add favicon
This commit is contained in:
@@ -5,3 +5,6 @@ VITE_BACKEND_URL=http://localhost:8080
|
||||
# Frontend dev server port
|
||||
# The Vite development server will run on this port
|
||||
VITE_PORT=5173
|
||||
|
||||
# Origin sent on the dev WebSocket proxy, for a backend with an allowed-origins list
|
||||
# VITE_WS_ORIGIN=https://gohoarder.example.com
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="color-scheme" content="light dark" />
|
||||
<link rel="icon" href="data:," />
|
||||
<title>GoHoarder dashboard</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -137,6 +137,24 @@
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<Dialog v-model:open="showKeyDialog">
|
||||
<DialogContent size="sm">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Admin API key</DialogTitle>
|
||||
<DialogDescription>Enter your admin API key to manage bypasses.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form class="flex flex-col gap-4" @submit.prevent="submitApiKey">
|
||||
<Field label="API key" required>
|
||||
<Input v-model="keyInput" type="password" autocomplete="off" />
|
||||
</Field>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" @click="showKeyDialog = false">Cancel</Button>
|
||||
<Button type="submit" :disabled="keyInput.trim() === ''">Continue</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<ConfirmDialog
|
||||
v-model:open="showDeleteModal"
|
||||
title="Delete bypass?"
|
||||
@@ -222,6 +240,8 @@ const bypassForm = ref({ ...EMPTY_FORM })
|
||||
|
||||
// Get API key from localStorage or prompt user
|
||||
const apiKey = ref<string>('')
|
||||
const keyInput = ref('')
|
||||
const showKeyDialog = ref(false)
|
||||
|
||||
const filteredBypasses = computed(() => {
|
||||
let filtered = bypasses.value
|
||||
@@ -264,16 +284,23 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
function promptForApiKey() {
|
||||
const key = prompt('Enter your admin API key:')
|
||||
if (key) {
|
||||
apiKey.value = key
|
||||
localStorage.setItem('admin_api_key', key)
|
||||
fetchBypasses()
|
||||
} else {
|
||||
error.value = 'Admin API key required to manage bypasses'
|
||||
}
|
||||
keyInput.value = ''
|
||||
showKeyDialog.value = true
|
||||
}
|
||||
|
||||
function submitApiKey() {
|
||||
const key = keyInput.value.trim()
|
||||
if (!key) return
|
||||
apiKey.value = key
|
||||
localStorage.setItem('admin_api_key', key)
|
||||
showKeyDialog.value = false
|
||||
fetchBypasses()
|
||||
}
|
||||
|
||||
watch(showKeyDialog, (open) => {
|
||||
if (!open && !apiKey.value) error.value = 'Admin API key required to manage bypasses'
|
||||
})
|
||||
|
||||
async function fetchBypasses() {
|
||||
if (!apiKey.value) {
|
||||
promptForApiKey()
|
||||
|
||||
@@ -140,6 +140,31 @@ describe('view smoke tests (strict mode throw, fixture data)', () => {
|
||||
expect(document.body.querySelector('textarea')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('BypassManagementPanel asks for the admin key in a dialog, not a native prompt', async () => {
|
||||
localStorage.clear()
|
||||
const prompt = vi.spyOn(window, 'prompt')
|
||||
const { wrapper, problems } = await smoke(BypassManagementPanel, '/admin/bypasses')
|
||||
await flushPromises()
|
||||
expect(problems).toEqual([])
|
||||
expect(prompt).not.toHaveBeenCalled()
|
||||
expect(document.body.textContent).toContain('Enter your admin API key to manage bypasses.')
|
||||
|
||||
const input = document.body.querySelector<HTMLInputElement>('input[type="password"]')
|
||||
expect(input).not.toBeNull()
|
||||
input!.value = 'secret-key'
|
||||
input!.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
await flushPromises()
|
||||
document.body.querySelector<HTMLFormElement>('input[type="password"]')!.form!.requestSubmit()
|
||||
await flushPromises()
|
||||
|
||||
expect(localStorage.getItem('admin_api_key')).toBe('secret-key')
|
||||
expect(vi.mocked(axios.get)).toHaveBeenCalledWith(
|
||||
expect.stringContaining('/api/admin/bypasses'),
|
||||
expect.objectContaining({ headers: { Authorization: 'Bearer secret-key' } }),
|
||||
)
|
||||
expect(wrapper.text()).toContain('CVE-2026-0002')
|
||||
})
|
||||
|
||||
it('Stats renders totals, the storage tile and the registry table', async () => {
|
||||
const { wrapper, problems } = await smoke(Stats, '/stats')
|
||||
expect(problems).toEqual([])
|
||||
|
||||
@@ -5,6 +5,7 @@ import { themeBootScript } from '@perfect-design/ui/stores/theme-boot'
|
||||
|
||||
// Get backend URL from environment or use default
|
||||
const BACKEND_URL = process.env.VITE_BACKEND_URL || 'http://localhost:8080'
|
||||
const WS_ORIGIN = process.env.VITE_WS_ORIGIN
|
||||
const FRONTEND_PORT = parseInt(process.env.VITE_PORT || '5173')
|
||||
|
||||
// Applies the saved colour mode before first paint so a dark system never flashes light.
|
||||
@@ -33,6 +34,8 @@ export default defineConfig({
|
||||
target: BACKEND_URL.replace('http', 'ws'),
|
||||
ws: true,
|
||||
changeOrigin: true,
|
||||
// A backend with an origin allowlist refuses the dev server origin; set this to an allowed one.
|
||||
...(WS_ORIGIN ? { headers: { Origin: WS_ORIGIN } } : {}),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user