Skip to content

Commit e4c1523

Browse files
committed
Displayed profile name in users table
1 parent a56b618 commit e4c1523

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Added more keywords to match SLURM errors (\#843).
77
* Fixed bug in sandbox pages (\#839);
88
* Displayed all kinds of recent task activities in tasks management page. (\#835);
9-
* Managed resources and profiles (\#845):
9+
* Managed resources and profiles (\#845, \#862):
1010
* Added new admin pages for resources and profiles;
1111
* Updated admin user pages to associate users with profiles;
1212
* Updated admin settings page;

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,32 @@ export async function getResource(fetch, resourceId) {
4444
return await response.json();
4545
}
4646

47+
/**
48+
* @param {typeof fetch} fetch
49+
* @returns {Promise<import('fractal-components/types/api').Profile[]>}
50+
*/
51+
export async function getProfiles(fetch) {
52+
logger.debug(`Retrieving profiles`);
53+
const response = await fetch(`${env.FRACTAL_SERVER_HOST}/admin/v2/profile/`, {
54+
method: 'GET',
55+
credentials: 'include'
56+
});
57+
58+
if (!response.ok) {
59+
await responseError(response);
60+
}
61+
62+
return await response.json();
63+
}
64+
4765
/**
4866
* @param {typeof fetch} fetch
4967
* @param {number} profileId
50-
* @returns {Promise<import('fractal-components/types/api').Resource>}
68+
* @returns {Promise<import('fractal-components/types/api').Profile>}
5169
*/
5270
export async function getProfile(fetch, profileId) {
5371
logger.debug(`Retrieving profile ${profileId}`);
54-
const response = await fetch(`${env.FRACTAL_SERVER_HOST}/admin/v2/profile/${profileId}`, {
72+
const response = await fetch(`${env.FRACTAL_SERVER_HOST}/admin/v2/profile/${profileId}/`, {
5573
method: 'GET',
5674
credentials: 'include'
5775
});

src/routes/v2/admin/users/+page.server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { listUsers } from '$lib/server/api/auth_api';
2+
import { getProfiles } from '$lib/server/api/v2/admin_api.js';
23
import { getLogger } from '$lib/server/logger.js';
34

45
const logger = getLogger('admin users page');
@@ -8,8 +9,10 @@ export async function load({ fetch }) {
89

910
// Load users from server
1011
const users = await listUsers(fetch);
12+
const profiles = await getProfiles(fetch);
1113

1214
return {
13-
users
15+
users,
16+
profiles
1417
};
1518
}

src/routes/v2/admin/users/+page.svelte

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
99
const currentUserId = $derived(page.data.userInfo?.id);
1010
const currentUserEmail = $derived(page.data.userInfo?.email);
11+
/** @type {Array<import('fractal-components/types/api').Profile>} */
12+
const profiles = $derived(page.data.profiles);
1113
1214
/** @type {Array<import('fractal-components/types/api').User & {id: number}>} */
1315
let users = $state([]);
16+
/** @type {Record<string, import('fractal-components/types/api').Profile | undefined>} */
17+
const userProfiles = $derived(
18+
Object.fromEntries(users.map((u) => [u.id, profiles.find((p) => p.id === u.profile_id)]))
19+
);
1420
1521
const deleteEnabled = false;
1622
@@ -52,7 +58,7 @@
5258
<th>Active</th>
5359
<th>Superuser</th>
5460
<th>Verified</th>
55-
<th>Has Profile</th>
61+
<th>Profile</th>
5662
<th>Actions</th>
5763
</tr>
5864
</thead>
@@ -65,7 +71,18 @@
6571
<td><BooleanIcon value={user.is_active} /></td>
6672
<td><BooleanIcon value={user.is_superuser} /></td>
6773
<td><BooleanIcon value={user.is_verified} /></td>
68-
<td><BooleanIcon value={user.profile_id !== null} /></td>
74+
<td>
75+
{#if userProfiles[user.id]}
76+
<a
77+
href="/v2/admin/resources/{userProfiles[user.id]
78+
?.resource_id}/profiles/{userProfiles[user.id]?.id}"
79+
>
80+
{userProfiles[user.id]?.name}
81+
</a>
82+
{:else}
83+
-
84+
{/if}
85+
</td>
6986
<td>
7087
<a href="/v2/admin/users/{user.id}" class="btn btn-light">
7188
<i class="bi-info-circle"></i> Info

tests/v2/users_crud.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ test('Create and update a user', async ({ page }) => {
120120
await verifyChecked(userRowCells, 2, true);
121121
await verifyChecked(userRowCells, 3, false);
122122
await verifyChecked(userRowCells, 4, false);
123+
await expect(userRowCells[5]).toContainText('Local profile');
123124
});
124125

125126
await test.step('Display the user info page', async () => {

0 commit comments

Comments
 (0)