Skip to content

Commit 45eea4b

Browse files
authored
Merge pull request #570 from fractal-analytics-platform/user-settings-changes
Changes to user settings
2 parents 058ce85 + 8b3b6fd commit 45eea4b

File tree

13 files changed

+78
-43
lines changed

13 files changed

+78
-43
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
*Note: Numbers like (\#123) point to closed Pull Requests on the fractal-web repository.*
22

3+
# Unreleased
4+
5+
* Allowed null values in settings API requests (\#570);
6+
* Hided cache dir from user settings page when using SSH Slurm (\#570);
7+
* Made FRACTAL_RUNNER_BACKEND environment variable mandatory (\#570);
8+
39
# 1.7.0
410

511
* Added "My Settings" page and updated admin user editor (\#564);

__tests__/v2/UserEditor.test.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ describe('UserEditor', () => {
7878
expect.anything(),
7979
expect.objectContaining({
8080
body: JSON.stringify({
81+
slurm_accounts: [],
8182
slurm_user: 'user',
8283
cache_dir: '/path/to/cache/dir',
83-
slurm_accounts: []
84+
ssh_host: null,
85+
ssh_username: null,
86+
ssh_private_key_path: null,
87+
ssh_tasks_dir: null,
88+
ssh_jobs_dir: null
8489
})
8590
})
8691
);
@@ -123,8 +128,14 @@ describe('UserEditor', () => {
123128
expect.anything(),
124129
expect.objectContaining({
125130
body: JSON.stringify({
131+
slurm_accounts: [],
132+
slurm_user: null,
126133
cache_dir: 'xxx',
127-
slurm_accounts: []
134+
ssh_host: null,
135+
ssh_username: null,
136+
ssh_private_key_path: null,
137+
ssh_tasks_dir: null,
138+
ssh_jobs_dir: null
128139
})
129140
})
130141
);
@@ -170,12 +181,14 @@ describe('UserEditor', () => {
170181
expect.anything(),
171182
expect.objectContaining({
172183
body: JSON.stringify({
184+
slurm_accounts: [],
185+
slurm_user: null,
186+
cache_dir: null,
173187
ssh_host: 'localhost',
174188
ssh_username: 'username',
175189
ssh_private_key_path: 'xxx',
176190
ssh_tasks_dir: 'yyy',
177-
ssh_jobs_dir: 'zzz',
178-
slurm_accounts: []
191+
ssh_jobs_dir: 'zzz'
179192
})
180193
})
181194
);
@@ -237,12 +250,14 @@ describe('UserEditor', () => {
237250
expect.anything(),
238251
expect.objectContaining({
239252
body: JSON.stringify({
253+
slurm_accounts: [],
254+
slurm_user: null,
255+
cache_dir: null,
240256
ssh_host: 'localhost',
241257
ssh_username: 'username',
242258
ssh_private_key_path: '/path/to/private/key',
243259
ssh_tasks_dir: '/path/to/tasks/dir',
244-
ssh_jobs_dir: '/path/to/jobs/dir',
245-
slurm_accounts: []
260+
ssh_jobs_dir: '/path/to/jobs/dir'
246261
})
247262
})
248263
);

docs/environment-variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The following environment variables can be used to configure fractal-web.
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`;
1919
* `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-
* `FRACTAL_RUNNER_BACKEND`: specifies which runner backend is used; supported values are: `local`, `local_experimental`, `slurm`, `slurm_ssh`; the default value is `local`;
20+
* `FRACTAL_RUNNER_BACKEND`: specifies which runner backend is used; supported values are: `local`, `local_experimental`, `slurm`, `slurm_ssh`; setting this variable is mandatory;
2121
* `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);
2222
* `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.
2323

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

src/hooks.server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { error, redirect } from '@sveltejs/kit';
55

66
const logger = getLogger('hooks');
77

8+
if (!env.FRACTAL_RUNNER_BACKEND) {
9+
throw new Error('Environment variable FRACTAL_RUNNER_BACKEND is mandatory');
10+
}
11+
812
if (env.FRACTAL_SERVER_HOST.endsWith('/')) {
913
env.FRACTAL_SERVER_HOST = env.FRACTAL_SERVER_HOST.substring(
1014
0,

src/lib/common/component_utilities.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ export function nullifyEmptyStrings(inputValues) {
156156
for (let key in inputValues) {
157157
if (typeof inputValues[key] === 'string' && inputValues[key].trim() === '') {
158158
clearedValues[key] = null;
159+
} else if (
160+
inputValues[key] !== null &&
161+
typeof inputValues[key] === 'object' &&
162+
!Array.isArray(inputValues[key])
163+
) {
164+
clearedValues[key] = nullifyEmptyStrings(inputValues[key]);
159165
} else {
160166
clearedValues[key] = inputValues[key];
161167
}

src/lib/components/v2/admin/UserEditor.svelte

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import Modal from '$lib/components/common/Modal.svelte';
88
import { sortGroupByNameComparator } from '$lib/common/user_utilities';
99
import SlimSelect from 'slim-select';
10-
import { stripNullAndEmptyObjectsAndArrays } from 'fractal-jschema';
1110
import StandardDismissableAlert from '$lib/components/common/StandardDismissableAlert.svelte';
1211
1312
/** @type {import('$lib/types').User & {group_ids: number[]}} */
@@ -250,10 +249,7 @@
250249
method: 'PATCH',
251250
credentials: 'include',
252251
headers,
253-
body: JSON.stringify({
254-
...stripNullAndEmptyObjectsAndArrays({ ...settings, id: undefined }),
255-
slurm_accounts: settings?.slurm_accounts
256-
})
252+
body: JSON.stringify(nullifyEmptyStrings({ ...settings, id: undefined }))
257253
});
258254
if (!response.ok) {
259255
await settingsFormErrorHandler.handleErrorResponse(response);

src/routes/+layout.server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function load({ locals, request, url }) {
2323
...pageInfo,
2424
warningBanner,
2525
apiV1Mode: env.FRACTAL_API_V1_MODE,
26-
runnerBackend: env.FRACTAL_RUNNER_BACKEND || 'local'
26+
runnerBackend: env.FRACTAL_RUNNER_BACKEND
2727
};
2828
}
2929

src/routes/settings/+page.server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export async function load({ fetch }) {
1111

1212
return {
1313
settings,
14-
runnerBackend: env.FRACTAL_RUNNER_BACKEND || 'local'
14+
runnerBackend: env.FRACTAL_RUNNER_BACKEND
1515
};
1616
}

src/routes/settings/+page.svelte

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
22
import { page } from '$app/stores';
3+
import { nullifyEmptyStrings } from '$lib/common/component_utilities';
34
import {
45
AlertError,
56
displayStandardErrorAlert,
@@ -22,8 +23,6 @@
2223
let cacheDir = '';
2324
let cacheDirError = '';
2425
25-
let cacheDirSet = false;
26-
2726
let settingsUpdatedMessage = '';
2827
2928
function addSlurmAccount() {
@@ -42,19 +41,21 @@
4241
errorAlert.hide();
4342
}
4443
settingsUpdatedMessage = '';
44+
slurmAccountsError = '';
45+
cacheDirError = '';
4546
const headers = new Headers();
4647
headers.set('Content-Type', 'application/json');
4748
const payload = {
4849
slurm_accounts: slurmAccounts
4950
};
50-
if (cacheDirSet || cacheDir) {
51+
if ($page.data.runnerBackend === 'slurm') {
5152
payload.cache_dir = cacheDir;
5253
}
5354
const response = await fetch(`/api/auth/current-user/settings`, {
5455
method: 'PATCH',
5556
credentials: 'include',
5657
headers,
57-
body: JSON.stringify(payload)
58+
body: JSON.stringify(nullifyEmptyStrings(payload))
5859
});
5960
const result = await response.json();
6061
if (response.ok) {
@@ -88,7 +89,6 @@
8889
function initFields(settings) {
8990
slurmAccounts = settings.slurm_accounts;
9091
cacheDir = settings.cache_dir || '';
91-
cacheDirSet = !!settings.cache_dir;
9292
}
9393
9494
onMount(() => {
@@ -106,6 +106,23 @@
106106
{settings.slurm_user || '-'}
107107
</div>
108108
</div>
109+
<div class="row mb-3">
110+
<label class="col-lg-2 col-sm-4 fw-bold" for="cache-dir">Cache dir</label>
111+
<div class="col-lg-6 col-sm-8">
112+
<div class="input-group" class:has-validation={cacheDirError}>
113+
<input
114+
type="text"
115+
class="form-control"
116+
id="cache-dir"
117+
bind:value={cacheDir}
118+
class:is-invalid={cacheDirError}
119+
/>
120+
{#if cacheDirError}
121+
<div class="invalid-feedback">{cacheDirError}</div>
122+
{/if}
123+
</div>
124+
</div>
125+
</div>
109126
{/if}
110127
{#if $page.data.runnerBackend === 'slurm_ssh'}
111128
<div class="row mb-4">
@@ -150,24 +167,6 @@
150167
</div>
151168
</div>
152169

153-
<div class="row mb-3">
154-
<label class="col-lg-2 col-sm-4 fw-bold" for="cache-dir">Cache dir</label>
155-
<div class="col-lg-6 col-sm-8">
156-
<div class="input-group" class:has-validation={cacheDirError}>
157-
<input
158-
type="text"
159-
class="form-control"
160-
id="cache-dir"
161-
bind:value={cacheDir}
162-
class:is-invalid={cacheDirError}
163-
/>
164-
{#if cacheDirError}
165-
<div class="invalid-feedback">{cacheDirError}</div>
166-
{/if}
167-
</div>
168-
</div>
169-
</div>
170-
171170
<div class="row">
172171
<div class="col">
173172
<div id="settingsUpdate-error" />

0 commit comments

Comments
 (0)