Skip to content

Commit 3009e32

Browse files
authored
Merge pull request #655 from fractal-analytics-platform/user-groups
User groups removal and user settings import
2 parents 36cd993 + 347fbad commit 3009e32

File tree

13 files changed

+568
-111
lines changed

13 files changed

+568
-111
lines changed

CHANGELOG.md

Lines changed: 5 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, \#652):
5+
* Alignment with fractal-server 2.9.0 (\#640, \#643, \#652, \#655):
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);
@@ -13,6 +13,10 @@
1313
* Added last used timestamp filter to task-group admin page (\#643);
1414
* Used new `GET /auth/current-user/allowed-viewer-paths/` endpoint (\#652);
1515
* Added "Download token" button in "My profile" page (\#652);
16+
* Implemented removal of users from group (\#655);
17+
* Implemented import of user settings from another user (\#655);
18+
* Used new set-groups endpoint (\#655);
19+
* Sorted task-group activities by timestamp_started (more recent first) (\#655);
1620

1721
# 1.10.1
1822

__tests__/user_utilities.test.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { it, expect } from 'vitest';
2-
import { sortUsers, sortGroupByNameAllFirstComparator } from '$lib/components/admin/user_utilities';
2+
import {
3+
sortUsers,
4+
sortGroupByNameAllFirstComparator,
5+
sortUserToImportSettings
6+
} from '$lib/components/admin/user_utilities';
37

48
it('should sort user by current superuser, then by superuser, then by email', () => {
59
let users = [
@@ -44,3 +48,27 @@ it('should sort groups by name, but keeping the All group first', () => {
4448
expect(groups[1].name).eq('g2');
4549
expect(groups[2].name).eq('g3');
4650
});
51+
52+
it('should sort users to import settings', () => {
53+
const users = [
54+
{ id: 1, email: '[email protected]' }, // groups: 1
55+
{ id: 2, email: '[email protected]' }, // groups: 1, 2, 4
56+
{ id: 3, email: '[email protected]' }, // groups: 1, 3
57+
{ id: 4, email: '[email protected]' } // groups: 1, 4
58+
];
59+
60+
const desiredGroups = [2, 3];
61+
const allGroups = [
62+
{ id: 1, name: 'All', user_ids: [1, 2, 3, 4] },
63+
{ id: 2, name: 'g2', user_ids: [2] },
64+
{ id: 3, name: 'g3', user_ids: [3] },
65+
{ id: 4, name: 'g4', user_ids: [2, 4] }
66+
];
67+
68+
const sortedUsers = sortUserToImportSettings(users, desiredGroups, allGroups);
69+
70+
expect(sortedUsers[0].email).eq('[email protected]');
71+
expect(sortedUsers[1].email).eq('[email protected]');
72+
expect(sortedUsers[2].email).eq('[email protected]');
73+
expect(sortedUsers[3].email).eq('[email protected]');
74+
});

__tests__/v2/admin_group_edit_page.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Admin group edit page', () => {
4444
fireEvent.drop(result.getByText(/drag the users here/i));
4545

4646
await result.findByText(/No more users available/);
47-
expect(result.queryByRole('button', { name: '[email protected]' })).null;
47+
expect(await result.findByLabelText('Remove user [email protected]')).not.null;
4848
});
4949

5050
it('Error happens when user is dragged and dropped', async () => {
@@ -61,5 +61,6 @@ describe('Admin group edit page', () => {
6161

6262
await result.findByText(/An error happened/);
6363
expect(result.queryByRole('button', { name: '[email protected]' })).not.null;
64+
expect(result.queryByRole('button', { name: 'Remove user [email protected]' })).null;
6465
});
6566
});

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

src/lib/components/admin/user_utilities.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,28 @@ export const sortGroupByNameAllFirstComparator = function (g1, g2) {
3838
? 1
3939
: g1.name.localeCompare(g2.name, undefined, { sensitivity: 'base' });
4040
};
41+
42+
/**
43+
* @param {Array<import('$lib/types').User & {id: number}>} users
44+
* @param {number[]} desiredGroups
45+
* @param {Array<import('$lib/types').Group & {user_ids: number[]}>} allGroups
46+
* @returns
47+
*/
48+
export const sortUserToImportSettings = function (users, desiredGroups, allGroups) {
49+
users.sort((u1, u2) => {
50+
const u1Groups = allGroups.filter((g) => g.user_ids.includes(u1.id)).map((g) => g.id);
51+
const u2Groups = allGroups.filter((g) => g.user_ids.includes(u2.id)).map((g) => g.id);
52+
for (const u1g of u1Groups) {
53+
if (desiredGroups.includes(u1g)) {
54+
return -1;
55+
}
56+
}
57+
for (const u2g of u2Groups) {
58+
if (desiredGroups.includes(u2g)) {
59+
return 1;
60+
}
61+
}
62+
return 0;
63+
});
64+
return users;
65+
};

0 commit comments

Comments
 (0)