Skip to content

Commit 6735011

Browse files
committed
Used new viewer paths endpoint and added download token button
1 parent 2d13474 commit 6735011

File tree

8 files changed

+42
-16
lines changed

8 files changed

+42
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Unreleased
44

5-
* Alignment with fractal-server 2.9.0 (\#640, \#643):
5+
* Alignment with fractal-server 2.9.0 (\#640, \#643, \#652):
66
* Updated task collections logic and created task-group activities pages for standard users and administrators (\#640);
77
* Removed active checkbox from task group edit modal (\#640);
88
* Added Manage button to deactivate and reactivate task groups (\#640);
@@ -11,6 +11,8 @@
1111
* Viewer paths page improvements (\#643);
1212
* Added manage buttons on admin task-groups page (\#643);
1313
* Added last used timestamp filter to task-group admin page (\#643);
14+
* Used new `GET /auth/current-user/allowed-viewer-paths/` endpoint (\#652);
15+
* Added "Download token" button in "My profile" page (\#652);
1416

1517
# 1.10.1
1618

playwright.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default defineConfig({
107107

108108
webServer: [
109109
{
110-
command: './tests/start-test-server.sh 2.9.0a5',
110+
command: './tests/start-test-server.sh 2.9.0a9',
111111
port: 8000,
112112
waitForPort: true,
113113
stdout: 'pipe',

src/lib/server/api/auth_api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ export async function getCurrentUserSettings(fetch) {
7474
* @param {typeof fetch} fetch
7575
* @returns {Promise<string[]>}
7676
*/
77-
export async function getCurrentUserViewerPaths(fetch) {
77+
export async function getCurrentUserAllowedViewerPaths(fetch) {
7878
logger.debug('Retrieving current user viewer paths');
79-
const url = `${env.FRACTAL_SERVER_HOST}/auth/current-user/viewer-paths/`;
79+
const url = `${env.FRACTAL_SERVER_HOST}/auth/current-user/allowed-viewer-paths/`;
8080
const response = await fetch(url, {
8181
method: 'GET',
8282
credentials: 'include'
8383
});
8484

8585
if (!response.ok) {
86-
logger.error('Unable to retrieve the current user viewer paths');
86+
logger.error('Unable to retrieve the current user allowed viewer paths');
8787
await responseError(response);
8888
}
8989

src/routes/profile/+page.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,7 @@
6868
</tr>
6969
</tbody>
7070
</table>
71+
72+
<a class="btn btn-primary mt-3" href="/profile/token" download>Download token</a>
7173
</div>
7274
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export async function GET({ cookies }) {
2+
const cookie = cookies.get('fastapiusersauth');
3+
4+
return new Response(cookie, {
5+
status: 200,
6+
headers: {
7+
'Content-Disposition': 'Attachment;filename=fractal-token.txt'
8+
}
9+
});
10+
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import { getCurrentUserSettings, getCurrentUserViewerPaths } from '$lib/server/api/auth_api.js';
1+
import { getCurrentUserAllowedViewerPaths } from '$lib/server/api/auth_api.js';
22
import { getLogger } from '$lib/server/logger.js';
33

44
const logger = getLogger('viewer paths page');
55

66
export async function load({ fetch }) {
77
logger.trace('Load viewer paths page');
88

9-
const viewerPaths = await getCurrentUserViewerPaths(fetch);
10-
const settings = await getCurrentUserSettings(fetch);
9+
const viewerPaths = await getCurrentUserAllowedViewerPaths(fetch);
1110

1211
return {
13-
viewerPaths,
14-
settings
12+
viewerPaths
1513
};
1614
}

src/routes/viewer-paths/+page.svelte

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
44
/** @type {string[]} */
55
const viewerPaths = $page.data.viewerPaths;
6-
/** @type {import('$lib/types').UserSettings} */
7-
const settings = $page.data.settings;
86
</script>
97

108
<h1 class="fw-light mb-3">Viewer paths</h1>
@@ -18,17 +16,14 @@
1816
<p>
1917
Note that access to image data is restricted to OME-Zarrs within certain paths (and their
2018
subfolders).
21-
{#if settings.project_dir || viewerPaths.length > 0}
19+
{#if viewerPaths.length > 0}
2220
The list of paths accessible to the current user includes:
2321
{:else}
2422
The list of paths accessible to the current user is empty.
2523
{/if}
2624
</p>
2725

2826
<ul>
29-
{#if settings.project_dir}
30-
<li><code>{settings.project_dir}</code></li>
31-
{/if}
3227
{#each viewerPaths as viewerPath}
3328
<li><code>{viewerPath}</code></li>
3429
{/each}

tests/download_token_test.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitPageLoading } from './utils.js';
3+
import path from 'path';
4+
import fs from 'fs/promises';
5+
import os from 'os';
6+
7+
test('Download token test', async ({ page }) => {
8+
await page.goto('/profile');
9+
await waitPageLoading(page);
10+
await page.getByRole('button', { name: '[email protected]' }).click();
11+
const downloadPromise = page.waitForEvent('download');
12+
await page.getByRole('link', { name: 'Download token' }).click();
13+
const download = await downloadPromise;
14+
const file = path.join(os.tmpdir(), download.suggestedFilename());
15+
await download.saveAs(file);
16+
const data = (await fs.readFile(file)).toString();
17+
expect(data.length).toBeGreaterThan(0);
18+
await fs.rm(file);
19+
});

0 commit comments

Comments
 (0)