@micha.bigler/ui-core-micha 1.4.26 → 1.4.27
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.
- package/dist/auth/authApi.js +61 -0
- package/package.json +1 -1
- package/src/auth/authApi.jsx +60 -0
package/dist/auth/authApi.js
CHANGED
|
@@ -315,3 +315,64 @@ export async function loginWithRecoveryPassword(email, password, token) {
|
|
|
315
315
|
const user = await fetchCurrentUser();
|
|
316
316
|
return { user, needsMfa: false };
|
|
317
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Ruft eine Liste von Benutzern ab (oft mit Pagination/Search).
|
|
320
|
+
* Backend: GET /api/users/
|
|
321
|
+
*/
|
|
322
|
+
export async function fetchUsersList(params = {}) {
|
|
323
|
+
try {
|
|
324
|
+
// params kann { page: 1, search: "...", ordering: "email" } enthalten
|
|
325
|
+
const res = await apiClient.get(`${USERS_BASE}/`, { params });
|
|
326
|
+
return res.data;
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
throw normaliseApiError(error, 'Auth.USER_LIST_FAILED');
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Löscht einen Benutzer.
|
|
334
|
+
* Backend: DELETE /api/users/{id}/
|
|
335
|
+
*/
|
|
336
|
+
export async function deleteUser(userId) {
|
|
337
|
+
try {
|
|
338
|
+
await apiClient.delete(`${USERS_BASE}/${userId}/`);
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
throw normaliseApiError(error, 'Auth.USER_DELETE_FAILED');
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Aktualisiert die Rolle eines Benutzers über die Custom Action.
|
|
346
|
+
* Backend: PATCH /api/users/{id}/update-role/
|
|
347
|
+
*/
|
|
348
|
+
export async function updateUserRole(userId, newRole) {
|
|
349
|
+
try {
|
|
350
|
+
const res = await apiClient.patch(`${USERS_BASE}/${userId}/update-role/`, {
|
|
351
|
+
role: newRole,
|
|
352
|
+
});
|
|
353
|
+
return res.data;
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
throw normaliseApiError(error, 'Auth.USER_ROLE_UPDATE_FAILED');
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Aktualisiert den Support-Status (z.B. is_support_agent Flag).
|
|
361
|
+
* Backend: PATCH /api/users/{id}/ (Standard DRF Update mit Nested Profile)
|
|
362
|
+
*/
|
|
363
|
+
export async function updateUserSupportStatus(userId, isSupportAgent) {
|
|
364
|
+
try {
|
|
365
|
+
// Wir gehen davon aus, dass dein Serializer "profile" nested akzeptiert
|
|
366
|
+
// (siehe BaseUserSerializer.update Logik im Backend)
|
|
367
|
+
const payload = {
|
|
368
|
+
profile: {
|
|
369
|
+
is_support_agent: isSupportAgent,
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
const res = await apiClient.patch(`${USERS_BASE}/${userId}/`, payload);
|
|
373
|
+
return res.data;
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
throw normaliseApiError(error, 'Auth.USER_SUPPORT_UPDATE_FAILED');
|
|
377
|
+
}
|
|
378
|
+
}
|
package/package.json
CHANGED
package/src/auth/authApi.jsx
CHANGED
|
@@ -328,4 +328,64 @@ export async function loginWithRecoveryPassword(email, password, token) {
|
|
|
328
328
|
}
|
|
329
329
|
const user = await fetchCurrentUser();
|
|
330
330
|
return { user, needsMfa: false };
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Ruft eine Liste von Benutzern ab (oft mit Pagination/Search).
|
|
334
|
+
* Backend: GET /api/users/
|
|
335
|
+
*/
|
|
336
|
+
export async function fetchUsersList(params = {}) {
|
|
337
|
+
try {
|
|
338
|
+
// params kann { page: 1, search: "...", ordering: "email" } enthalten
|
|
339
|
+
const res = await apiClient.get(`${USERS_BASE}/`, { params });
|
|
340
|
+
return res.data;
|
|
341
|
+
} catch (error) {
|
|
342
|
+
throw normaliseApiError(error, 'Auth.USER_LIST_FAILED');
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Löscht einen Benutzer.
|
|
348
|
+
* Backend: DELETE /api/users/{id}/
|
|
349
|
+
*/
|
|
350
|
+
export async function deleteUser(userId) {
|
|
351
|
+
try {
|
|
352
|
+
await apiClient.delete(`${USERS_BASE}/${userId}/`);
|
|
353
|
+
} catch (error) {
|
|
354
|
+
throw normaliseApiError(error, 'Auth.USER_DELETE_FAILED');
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Aktualisiert die Rolle eines Benutzers über die Custom Action.
|
|
360
|
+
* Backend: PATCH /api/users/{id}/update-role/
|
|
361
|
+
*/
|
|
362
|
+
export async function updateUserRole(userId, newRole) {
|
|
363
|
+
try {
|
|
364
|
+
const res = await apiClient.patch(`${USERS_BASE}/${userId}/update-role/`, {
|
|
365
|
+
role: newRole,
|
|
366
|
+
});
|
|
367
|
+
return res.data;
|
|
368
|
+
} catch (error) {
|
|
369
|
+
throw normaliseApiError(error, 'Auth.USER_ROLE_UPDATE_FAILED');
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Aktualisiert den Support-Status (z.B. is_support_agent Flag).
|
|
375
|
+
* Backend: PATCH /api/users/{id}/ (Standard DRF Update mit Nested Profile)
|
|
376
|
+
*/
|
|
377
|
+
export async function updateUserSupportStatus(userId, isSupportAgent) {
|
|
378
|
+
try {
|
|
379
|
+
// Wir gehen davon aus, dass dein Serializer "profile" nested akzeptiert
|
|
380
|
+
// (siehe BaseUserSerializer.update Logik im Backend)
|
|
381
|
+
const payload = {
|
|
382
|
+
profile: {
|
|
383
|
+
is_support_agent: isSupportAgent,
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
const res = await apiClient.patch(`${USERS_BASE}/${userId}/`, payload);
|
|
387
|
+
return res.data;
|
|
388
|
+
} catch (error) {
|
|
389
|
+
throw normaliseApiError(error, 'Auth.USER_SUPPORT_UPDATE_FAILED');
|
|
390
|
+
}
|
|
331
391
|
}
|