@makolabs/ripple 1.6.2 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -275,19 +275,23 @@ async function fetchUserPermissions(userId) {
|
|
|
275
275
|
if (userData?.data?.data && Array.isArray(userData.data.data)) {
|
|
276
276
|
// Deduplicate permissions by using a Set
|
|
277
277
|
const allPermissions = userData.data.data.flatMap((key) => key.scopes || []);
|
|
278
|
-
|
|
278
|
+
const dedupedPermissions = Array.from(new Set(allPermissions));
|
|
279
|
+
return dedupedPermissions;
|
|
279
280
|
}
|
|
280
281
|
else if (userData?.scopes) {
|
|
281
|
-
|
|
282
|
+
const permissions = Array.isArray(userData.scopes) ? userData.scopes : [userData.scopes];
|
|
283
|
+
return permissions;
|
|
282
284
|
}
|
|
283
285
|
return [];
|
|
284
286
|
}
|
|
285
|
-
catch {
|
|
287
|
+
catch (error) {
|
|
288
|
+
console.error('[fetchUserPermissions] Error fetching user permissions:', error);
|
|
286
289
|
try {
|
|
287
290
|
const allKeysData = await makeAdminRequest('/admin/keys');
|
|
288
291
|
const userKey = allKeysData.data.data.find((key) => key.sub === userId && key.client_id === CLIENT_ID && key.status === 'active');
|
|
289
292
|
if (userKey) {
|
|
290
|
-
|
|
293
|
+
const permissions = Array.isArray(userKey.scopes) ? userKey.scopes : [userKey.scopes];
|
|
294
|
+
return permissions;
|
|
291
295
|
}
|
|
292
296
|
return [];
|
|
293
297
|
}
|
|
@@ -345,20 +349,20 @@ async function refreshTokenIfSelfUpdate(userId) {
|
|
|
345
349
|
export const updateUserPermissions = command('unchecked', async (options) => {
|
|
346
350
|
const { userId, permissions } = options;
|
|
347
351
|
try {
|
|
348
|
-
// Fetch all keys
|
|
349
|
-
const allKeysData = await makeAdminRequest(
|
|
352
|
+
// Fetch all keys for this specific user (not paginated, gets all keys)
|
|
353
|
+
const allKeysData = await makeAdminRequest(`/admin/keys?client_id=${CLIENT_ID}&sub=${userId}`);
|
|
350
354
|
// Find ALL active keys for this user (not just one)
|
|
351
|
-
const userKeys = allKeysData
|
|
352
|
-
//
|
|
353
|
-
|
|
355
|
+
const userKeys = (allKeysData?.data?.data || []).filter((key) => key.status === 'active');
|
|
356
|
+
// Create new key first, then delete old ones (safer order)
|
|
357
|
+
const newKey = await createUserPermissions(userId, permissions);
|
|
358
|
+
// Only delete old keys after new key is successfully created
|
|
359
|
+
if (userKeys.length > 0 && newKey) {
|
|
354
360
|
await Promise.all(userKeys.map((key) => makeAdminRequest(`/admin/keys/${key.id}`, {
|
|
355
361
|
method: 'DELETE'
|
|
356
362
|
}).catch((err) => {
|
|
357
363
|
console.warn(`[updateUserPermissions] Failed to delete key ${key.id}:`, err);
|
|
358
364
|
})));
|
|
359
365
|
}
|
|
360
|
-
// Create one new key with updated permissions
|
|
361
|
-
await createUserPermissions(userId, permissions);
|
|
362
366
|
await refreshTokenIfSelfUpdate(userId);
|
|
363
367
|
}
|
|
364
368
|
catch (error) {
|
|
@@ -164,10 +164,11 @@
|
|
|
164
164
|
role: formData.role,
|
|
165
165
|
permissions: formData.permissions
|
|
166
166
|
};
|
|
167
|
+
|
|
167
168
|
await onSave(userData, mode);
|
|
168
169
|
handleClose();
|
|
169
170
|
} catch (error) {
|
|
170
|
-
console.error('Error saving user:', error);
|
|
171
|
+
console.error('[UserModal] Error saving user:', error);
|
|
171
172
|
formErrors.submit = error instanceof Error ? error.message : 'Failed to save user';
|
|
172
173
|
} finally {
|
|
173
174
|
saving = false;
|
|
@@ -176,7 +177,8 @@
|
|
|
176
177
|
|
|
177
178
|
function handleRoleChange(roleValue: string) {
|
|
178
179
|
const role = roles?.find((r: Role) => r.value === roleValue);
|
|
179
|
-
|
|
180
|
+
|
|
181
|
+
// Reassign entire formData object to ensure Svelte 5 reactivity
|
|
180
182
|
formData = {
|
|
181
183
|
...formData,
|
|
182
184
|
role: roleValue,
|