Skip to content

Commit 1788d4b

Browse files
authored
Merge pull request #557 from fractal-analytics-platform/warning-banners
Supported warning banner, FRACTAL_API_V1_MODE=include_read_only, and displayed OAuth2 accounts in user profile page
2 parents 7cfe289 + 6b17d18 commit 1788d4b

File tree

13 files changed

+110
-19
lines changed

13 files changed

+110
-19
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ LOG_LEVEL_FILE=info
1919
LOG_LEVEL_CONSOLE=warn
2020

2121
FRACTAL_API_V1_MODE=include
22+
#WARNING_BANNER_PATH=/path/to/banner.txt

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ LOG_LEVEL_FILE=debug
1818
LOG_LEVEL_CONSOLE=info
1919

2020
FRACTAL_API_V1_MODE=include
21+
#WARNING_BANNER_PATH=/path/to/banner.txt

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# Unreleased
44

5+
* Displayed OAuth2 accounts in user profile page (\#557);
6+
* Supported `FRACTAL_API_V1_MODE=include_read_only` (\#557);
7+
* Added support for displaying temporary warning banner using the `WARNING_BANNER_PATH` environment variable (\#557);
58
* Deprecated support for legacy tasks in V2 workflows (\#554);
69

710
# 1.5.0

docs/development/tests.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,24 @@ By default v2 tests are run. These tests require running a fractal-server instan
2020

2121
To run v1 tests start playwright setting the environment variable `TEST_VERSION` to `v1`. These tests require running a fractal-server instance using `FRACTAL_RUNNER_BACKEND=local`.
2222

23-
OAuth2 test requires a running instance of dexidp test image and a fractal-server instance configured to use it. To skip OAuth2 test set the environment variable `SKIP_OAUTH_TEST` to `true`.
23+
OAuth2 test requires a running instance of dexidp test image and a fractal-server instance configured to use it.
24+
25+
To skip OAuth2 test set the environment variable `SKIP_OAUTH_TEST` to `true`.
26+
27+
To run the OAuth2 test locally add the following configuration to `.fractal_server.env`:
28+
29+
```
30+
OAUTH_DEXIDP_CLIENT_ID=client_test_web_id
31+
OAUTH_DEXIDP_CLIENT_SECRET=client_test_web_secret
32+
OAUTH_DEXIDP_REDIRECT_URL=http://localhost:5173/auth/login/oauth2/
33+
OAUTH_DEXIDP_OIDC_CONFIGURATION_ENDPOINT=http://127.0.0.1:5556/dex/.well-known/openid-configuration
34+
```
35+
36+
And then start the test IdP container:
37+
38+
```sh
39+
docker run -d --rm -p 5556:5556 ghcr.io/fractal-analytics-platform/oauth:0.1
40+
```
2441

2542
## Coverage
2643

docs/environment-variables.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ The following environment variables can be used to configure fractal-web.
1616
* `LOG_FILE`: the path of the file where logs will be written; by default is unset and no file will be created;
1717
* `LOG_LEVEL_FILE`: the log level of logs that will be written to the file; the default value is `info`;
1818
* `LOG_LEVEL_CONSOLE`: the log level of logs that will be written to the console; the default value is `warn`;
19-
* `FRACTAL_API_V1_MODE`: include/exclude V1 pages and version switcher; the default value is `include`;
20-
* `PUBLIC_FRACTAL_VIZARR_VIEWER_URL`: URL to [fractal-vizarr-viewer](https://github.com/fractal-analytics-platform/fractal-vizarr-viewer) service (e.g. http://localhost:3000/vizarr for testing).
19+
* `FRACTAL_API_V1_MODE`: include/exclude V1 pages and version switcher; supported values are: `include`, `include_read_only`, `exclude`; the default value is `include`;
20+
* `PUBLIC_FRACTAL_VIZARR_VIEWER_URL`: URL to [fractal-vizarr-viewer](https://github.com/fractal-analytics-platform/fractal-vizarr-viewer) service (e.g. http://localhost:3000/vizarr for testing);
21+
* `WARNING_BANNER_PATH`: specifies the path to a text file containing the warning banner message displayed on the site; the banner is used to inform users about important issues, such as external resources downtime or maintenance alerts; if the variable is empty or unset no banner is displayed.
2122

2223
When running directly using `node` command these extra variables can also be configured:
2324

docs/quickstart.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export LOG_FILE=fractal-web.log
5757

5858
export FRACTAL_API_V1_MODE=include
5959

60+
#export PUBLIC_FRACTAL_VIZARR_VIEWER_URL=
61+
#export WARNING_BANNER_PATH=
62+
6063
# default values are usually fine for the following variables; remove comments if needed
6164
#export AUTH_COOKIE_NAME=fastapiusersauth
6265
#export AUTH_COOKIE_PATH=/

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.5.0a0',
110+
command: './tests/start-test-server.sh 2.5.0a1',
111111
port: 8000,
112112
waitForPort: true,
113113
stdout: 'pipe',

src/lib/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ export type User = {
117117
slurm_accounts: string[]
118118
group_names?: string[]
119119
group_ids?: number[]
120+
oauth_accounts: Array<{
121+
id: number
122+
account_email: string
123+
oauth_name: string
124+
}>
120125
}
121126

122127
export type Group = {

src/routes/+layout.server.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { env } from '$env/dynamic/private';
22
import { getLogger } from '$lib/server/logger.js';
3+
import fs from 'fs/promises';
34

45
const logger = getLogger('page layout');
56

@@ -16,8 +17,24 @@ export async function load({ locals, request, url }) {
1617
logger.error('pageInfo is missing, it should have been loaded by hooks.server.js');
1718
}
1819

20+
const warningBanner = await getWarningBanner();
21+
1922
return {
2023
...pageInfo,
21-
v1Enabled: env.FRACTAL_API_V1_MODE !== 'exclude'
24+
warningBanner,
25+
apiV1Mode: env.FRACTAL_API_V1_MODE
2226
};
2327
}
28+
29+
async function getWarningBanner() {
30+
if (!env.WARNING_BANNER_PATH) {
31+
return null;
32+
}
33+
try {
34+
const bannerData = await fs.readFile(env.WARNING_BANNER_PATH, { encoding: 'utf-8' });
35+
return bannerData.trim();
36+
} catch (err) {
37+
logger.error('An error happened reading warning banner file %s', env.WARNING_BANNER_PATH, err);
38+
return null;
39+
}
40+
}

src/routes/+layout.svelte

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
$: server = $page.data.serverInfo || {};
1212
/** @type {'v1'|'v2'} */
1313
$: apiVersion = $page.url.pathname.startsWith('/v1') ? 'v1' : 'v2';
14+
$: warningBanner = $page.data.warningBanner;
1415
// @ts-ignore
1516
// eslint-disable-next-line no-undef
1617
let clientVersion = __APP_VERSION__;
1718
1819
$: displayVersionSelector =
19-
$page.data.v1Enabled &&
20+
$page.data.apiV1Mode !== 'exclude' &&
2021
(!isSubPage($page.url.pathname, apiVersion) ||
2122
$page.url.pathname === '/v2/admin/jobs' ||
2223
$page.url.pathname === '/v1/admin/jobs') &&
@@ -220,6 +221,19 @@
220221
Sorry, we are performing some maintenance on fractal-server. It will be back online soon.
221222
</div>
222223
{/if}
224+
{#if apiVersion === 'v1' && $page.data.apiV1Mode === 'include_read_only'}
225+
<div class="alert alert-warning">Warning: legacy API is in read-only mode.</div>
226+
{/if}
227+
{#if warningBanner}
228+
<div class="alert alert-warning">
229+
{#each warningBanner.split('\n') as line, index}
230+
{#if index > 0}
231+
<br />
232+
{/if}
233+
{line}
234+
{/each}
235+
</div>
236+
{/if}
223237
{#if userLoggedIn && !$page.data.userInfo.is_verified}
224238
<div class="row">
225239
<div class="col">

0 commit comments

Comments
 (0)