Skip to content

Commit 1a8cc7a

Browse files
committed
Adapted to new endpoints
1 parent aa55af3 commit 1a8cc7a

File tree

11 files changed

+42
-24
lines changed

11 files changed

+42
-24
lines changed

__tests__/v2/UserEditor.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('UserEditor', () => {
6565

6666
render(UserEditor, {
6767
props: {
68-
runnerBackend: 'slurm',
68+
runnerBackend: 'slurm_sudo',
6969
user: selectedUser,
7070
settings: { ...initialSettings },
7171
saveUser: mockSaveUser
@@ -107,12 +107,12 @@ describe('UserEditor', () => {
107107
);
108108
});
109109

110-
it('Update settings with slurm runner backend - validation error', async () => {
110+
it('Update settings with slurm_sudo runner backend - validation error', async () => {
111111
const user = userEvent.setup();
112112

113113
render(UserEditor, {
114114
props: {
115-
runnerBackend: 'slurm',
115+
runnerBackend: 'slurm_sudo',
116116
user: selectedUser,
117117
settings: { ...initialSettings },
118118
saveUser: mockSaveUser

components/src/lib/types/api.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ export type Resource = {
344344
tasks_local_dir: string;
345345
tasks_python_config: Record<string, any>;
346346
tasks_pixi_config: Record<string, any>;
347-
tasks_pip_cache_dir: string | null;
348347
};
349348

350349
export type Profile = {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@
294294
if (autoselectProfile && resources.length > 0) {
295295
selectedResourceId = resources[0].id;
296296
selectedResource = resources[0];
297+
await resourceChanged();
297298
}
298299
if (selectedResourceId) {
299300
await loadProfiles(false);
@@ -314,11 +315,11 @@
314315
if (!editableUser || editableUser.profile_id === null) {
315316
return;
316317
}
317-
const response = await fetch(`/api/admin/v2/resource-of-profile/${editableUser.profile_id}`);
318+
const response = await fetch(`/api/admin/v2/profile/${editableUser.profile_id}`);
318319
if (response.ok) {
319-
/** @type {import('fractal-components/types/api').Resource} */
320-
const resource = await response.json();
321-
selectedResourceId = resource.id;
320+
/** @type {import('fractal-components/types/api').Profile} */
321+
const profile = await response.json();
322+
selectedResourceId = profile.resource_id;
322323
} else {
323324
profilesErrorAlert = displayStandardErrorAlert(
324325
await getAlertErrorFromResponse(response),

src/lib/server/api/v2/admin_api.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,15 @@ export async function getResource(fetch, resourceId) {
4646

4747
/**
4848
* @param {typeof fetch} fetch
49-
* @param {number} resourceId
5049
* @param {number} profileId
5150
* @returns {Promise<import('fractal-components/types/api').Resource>}
5251
*/
53-
export async function getProfile(fetch, resourceId, profileId) {
54-
logger.debug(`Retrieving profile ${profileId} of resource ${resourceId}`);
55-
const response = await fetch(
56-
`${env.FRACTAL_SERVER_HOST}/admin/v2/resource/${resourceId}/profile/${profileId}`,
57-
{
58-
method: 'GET',
59-
credentials: 'include'
60-
}
61-
);
52+
export async function getProfile(fetch, profileId) {
53+
logger.debug(`Retrieving profile ${profileId}`);
54+
const response = await fetch(`${env.FRACTAL_SERVER_HOST}/admin/v2/profile/${profileId}`, {
55+
method: 'GET',
56+
credentials: 'include'
57+
});
6258

6359
if (!response.ok) {
6460
await responseError(response);

src/routes/v2/admin/resources/[resourceId]/edit/+page.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<script>
22
import { page } from '$app/state';
3-
import { displayStandardErrorAlert, getAlertErrorFromResponse } from '$lib/common/errors';
3+
import {
4+
AlertError,
5+
displayStandardErrorAlert,
6+
getAlertErrorFromResponse
7+
} from '$lib/common/errors';
48
import StandardDismissableAlert from '$lib/components/common/StandardDismissableAlert.svelte';
59
import { normalizePayload } from 'fractal-components';
610
import { onMount } from 'svelte';
@@ -74,6 +78,8 @@
7478
'saveError'
7579
);
7680
}
81+
} catch (err) {
82+
saveErrorAlert = displayStandardErrorAlert(new AlertError(err), 'saveError');
7783
} finally {
7884
saving = false;
7985
}

src/routes/v2/admin/resources/[resourceId]/profiles/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @param {number} id
3131
*/
3232
async function handleDeleteProfile(id) {
33-
const response = await fetch(`/api/admin/v2/resource/${resource.id}/profile/${id}`, {
33+
const response = await fetch(`/api/admin/v2/profile/${id}`, {
3434
method: 'DELETE'
3535
});
3636

src/routes/v2/admin/resources/[resourceId]/profiles/[profileId]/+page.server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function load({ fetch, params }) {
77
logger.debug('Loading resource %d', params.resourceId);
88
const resource = await getResource(fetch, Number(params.resourceId));
99
logger.debug('Loading profile %d', params.profileId);
10-
const profile = await getProfile(fetch, Number(params.resourceId), Number(params.profileId));
10+
const profile = await getProfile(fetch, Number(params.profileId));
1111
return {
1212
resource,
1313
profile

src/routes/v2/admin/resources/[resourceId]/profiles/[profileId]/edit/+page.server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function load({ fetch, params }) {
77
logger.debug('Loading resource %d', params.resourceId);
88
const resource = await getResource(fetch, Number(params.resourceId));
99
logger.debug('Loading profile %d', params.profileId);
10-
const profile = await getProfile(fetch, Number(params.resourceId), Number(params.profileId));
10+
const profile = await getProfile(fetch, Number(params.profileId));
1111
return {
1212
resource,
1313
profile

src/routes/v2/admin/resources/[resourceId]/profiles/[profileId]/edit/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
const headers = new Headers();
2121
headers.set('Content-Type', 'application/json');
2222
23-
return await fetch(`/api/admin/v2/resource/${resource.id}/profile/${profile.id}`, {
23+
return await fetch(`/api/admin/v2/profile/${profile.id}`, {
2424
method: 'PUT',
2525
credentials: 'include',
2626
headers,

src/routes/v2/admin/users/[userId]/+page.server.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { env } from '$env/dynamic/private';
22
import { getUser, getUserSettings, listGroups } from '$lib/server/api/auth_api';
3+
import { getProfile } from '$lib/server/api/v2/admin_api';
34
import { getLogger } from '$lib/server/logger.js';
45

56
const logger = getLogger('admin user page');
@@ -8,11 +9,16 @@ export async function load({ fetch, params }) {
89
logger.debug('Loading user %d', params.userId);
910

1011
const user = await getUser(fetch, params.userId);
12+
let profile = undefined;
13+
if (user.profile_id) {
14+
profile = await getProfile(fetch, user.profile_id);
15+
}
1116
const settings = await getUserSettings(fetch, params.userId);
1217
const groups = await listGroups(fetch);
1318

1419
return {
1520
user,
21+
profile,
1622
settings,
1723
groups,
1824
runnerBackend: env.FRACTAL_RUNNER_BACKEND

0 commit comments

Comments
 (0)