@makolabs/ripple 1.6.0 → 1.6.2
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.
|
@@ -345,39 +345,21 @@ async function refreshTokenIfSelfUpdate(userId) {
|
|
|
345
345
|
export const updateUserPermissions = command('unchecked', async (options) => {
|
|
346
346
|
const { userId, permissions } = options;
|
|
347
347
|
try {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
await
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const allKeysData = await makeAdminRequest('/admin/keys');
|
|
360
|
-
const userKey = allKeysData.data.data.find((key) => key.sub === userId && key.client_id === CLIENT_ID && key.status === 'active');
|
|
361
|
-
if (userKey) {
|
|
362
|
-
adminKeyId = userKey.id;
|
|
363
|
-
await makeAdminRequest(`/admin/keys/${adminKeyId}`, {
|
|
364
|
-
method: 'PUT',
|
|
365
|
-
body: JSON.stringify({ scopes: permissions })
|
|
366
|
-
});
|
|
367
|
-
await refreshTokenIfSelfUpdate(userId);
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
await createUserPermissions(userId, permissions);
|
|
372
|
-
await refreshTokenIfSelfUpdate(userId);
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
catch (searchError) {
|
|
377
|
-
console.error('[updateUserPermissions] Error during permission update:', searchError);
|
|
378
|
-
throw new Error('Failed to update permissions');
|
|
379
|
-
}
|
|
348
|
+
// Fetch all keys to find user's active keys
|
|
349
|
+
const allKeysData = await makeAdminRequest('/admin/keys');
|
|
350
|
+
// Find ALL active keys for this user (not just one)
|
|
351
|
+
const userKeys = allKeysData.data.data.filter((key) => key.sub === userId && key.client_id === CLIENT_ID && key.status === 'active');
|
|
352
|
+
// Delete all old active keys to ensure clean state
|
|
353
|
+
if (userKeys.length > 0) {
|
|
354
|
+
await Promise.all(userKeys.map((key) => makeAdminRequest(`/admin/keys/${key.id}`, {
|
|
355
|
+
method: 'DELETE'
|
|
356
|
+
}).catch((err) => {
|
|
357
|
+
console.warn(`[updateUserPermissions] Failed to delete key ${key.id}:`, err);
|
|
358
|
+
})));
|
|
380
359
|
}
|
|
360
|
+
// Create one new key with updated permissions
|
|
361
|
+
await createUserPermissions(userId, permissions);
|
|
362
|
+
await refreshTokenIfSelfUpdate(userId);
|
|
381
363
|
}
|
|
382
364
|
catch (error) {
|
|
383
365
|
console.error('[updateUserPermissions] Error:', error);
|
|
@@ -175,11 +175,13 @@
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
function handleRoleChange(roleValue: string) {
|
|
178
|
-
formData.role = roleValue;
|
|
179
178
|
const role = roles?.find((r: Role) => r.value === roleValue);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
// Reassign entire formData object to ensure reactivity
|
|
180
|
+
formData = {
|
|
181
|
+
...formData,
|
|
182
|
+
role: roleValue,
|
|
183
|
+
permissions: role ? [...role.permissions] : []
|
|
184
|
+
};
|
|
183
185
|
}
|
|
184
186
|
|
|
185
187
|
async function handleRegenerateApiKey() {
|