@noatgnu/cupcake-core 1.2.2 → 1.2.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.
|
@@ -149,26 +149,41 @@ class AuthService {
|
|
|
149
149
|
return true;
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
+
convertUserFromSnakeToCamel(user) {
|
|
153
|
+
return {
|
|
154
|
+
id: user.id || user.user_id,
|
|
155
|
+
username: user.username || '',
|
|
156
|
+
email: user.email || '',
|
|
157
|
+
firstName: user.firstName || user.first_name || '',
|
|
158
|
+
lastName: user.lastName || user.last_name || '',
|
|
159
|
+
isStaff: user.isStaff !== undefined ? user.isStaff : (user.is_staff || false),
|
|
160
|
+
isSuperuser: user.isSuperuser !== undefined ? user.isSuperuser : (user.is_superuser || false),
|
|
161
|
+
isActive: user.isActive !== undefined ? user.isActive : (user.is_active !== undefined ? user.is_active : true),
|
|
162
|
+
dateJoined: user.dateJoined || user.date_joined || '',
|
|
163
|
+
lastLogin: user.lastLogin || user.last_login || null,
|
|
164
|
+
hasOrcid: user.hasOrcid !== undefined ? user.hasOrcid : (user.orcid_id ? true : false),
|
|
165
|
+
orcidId: user.orcidId || user.orcid_id
|
|
166
|
+
};
|
|
167
|
+
}
|
|
152
168
|
getUserFromToken() {
|
|
153
169
|
const token = this.getAccessToken();
|
|
154
170
|
if (!token)
|
|
155
171
|
return null;
|
|
156
172
|
try {
|
|
157
173
|
const payload = JSON.parse(atob(token.split('.')[1]));
|
|
158
|
-
return {
|
|
174
|
+
return this.convertUserFromSnakeToCamel({
|
|
159
175
|
id: payload.user_id,
|
|
160
|
-
username: payload.username
|
|
161
|
-
email: payload.email
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
};
|
|
176
|
+
username: payload.username,
|
|
177
|
+
email: payload.email,
|
|
178
|
+
first_name: payload.first_name,
|
|
179
|
+
last_name: payload.last_name,
|
|
180
|
+
is_staff: payload.is_staff,
|
|
181
|
+
is_superuser: payload.is_superuser,
|
|
182
|
+
is_active: payload.is_active,
|
|
183
|
+
date_joined: payload.date_joined,
|
|
184
|
+
last_login: payload.last_login,
|
|
185
|
+
orcid_id: payload.orcid_id
|
|
186
|
+
});
|
|
172
187
|
}
|
|
173
188
|
catch {
|
|
174
189
|
return null;
|
|
@@ -218,10 +233,10 @@ class AuthService {
|
|
|
218
233
|
}
|
|
219
234
|
fetchUserProfile() {
|
|
220
235
|
return this.http.get(`${this.apiUrl}/auth/profile/`)
|
|
221
|
-
.pipe(
|
|
222
|
-
this.currentUserSubject.next(
|
|
236
|
+
.pipe(map(response => this.convertUserFromSnakeToCamel(response.user)), tap(user => {
|
|
237
|
+
this.currentUserSubject.next(user);
|
|
223
238
|
this.isAuthenticatedSubject.next(true);
|
|
224
|
-
})
|
|
239
|
+
}));
|
|
225
240
|
}
|
|
226
241
|
getCurrentUser() {
|
|
227
242
|
return this.currentUserSubject.value;
|
|
@@ -240,7 +255,8 @@ class AuthService {
|
|
|
240
255
|
const refreshToken = response.refreshToken || response.refresh_token || response.refresh;
|
|
241
256
|
localStorage.setItem('ccvAccessToken', accessToken);
|
|
242
257
|
localStorage.setItem('ccvRefreshToken', refreshToken);
|
|
243
|
-
this.
|
|
258
|
+
const convertedUser = this.convertUserFromSnakeToCamel(response.user);
|
|
259
|
+
this.currentUserSubject.next(convertedUser);
|
|
244
260
|
this.isAuthenticatedSubject.next(true);
|
|
245
261
|
}
|
|
246
262
|
tryRefreshToken() {
|
|
@@ -568,10 +584,10 @@ class ApiService {
|
|
|
568
584
|
httpParams = httpParams.set('is_active', params.isActive.toString());
|
|
569
585
|
if (params?.search)
|
|
570
586
|
httpParams = httpParams.set('search', params.search);
|
|
571
|
-
if (params?.
|
|
572
|
-
httpParams = httpParams.set('
|
|
573
|
-
if (params?.
|
|
574
|
-
httpParams = httpParams.set('
|
|
587
|
+
if (params?.limit)
|
|
588
|
+
httpParams = httpParams.set('limit', params.limit.toString());
|
|
589
|
+
if (params?.offset !== undefined)
|
|
590
|
+
httpParams = httpParams.set('offset', params.offset.toString());
|
|
575
591
|
return this.http.get(`${this.apiUrl}/users/`, { params: httpParams });
|
|
576
592
|
}
|
|
577
593
|
getUser(id) {
|
|
@@ -1684,6 +1700,13 @@ class LabGroupService extends BaseApiService {
|
|
|
1684
1700
|
removeMemberFromLabGroup(id, userId) {
|
|
1685
1701
|
return this.post(`${this.apiUrl}/lab-groups/${id}/remove_member/`, { userId });
|
|
1686
1702
|
}
|
|
1703
|
+
getRootLabGroups(params) {
|
|
1704
|
+
const httpParams = this.buildHttpParams({ ...params, parentGroup__isnull: 'true' });
|
|
1705
|
+
return this.get(`${this.apiUrl}/lab-groups/`, { params: httpParams });
|
|
1706
|
+
}
|
|
1707
|
+
getSubGroups(parentGroupId, params) {
|
|
1708
|
+
return this.getLabGroups({ ...params, parentGroup: parentGroupId });
|
|
1709
|
+
}
|
|
1687
1710
|
// LAB GROUP INVITATIONS
|
|
1688
1711
|
getLabGroupInvitations(params) {
|
|
1689
1712
|
const httpParams = this.buildHttpParams(params);
|
|
@@ -2385,12 +2408,13 @@ class UserManagementComponent {
|
|
|
2385
2408
|
loadUsers() {
|
|
2386
2409
|
this.isLoading.set(true);
|
|
2387
2410
|
this.errorMessage.set('');
|
|
2411
|
+
const offset = (this.currentPage() - 1) * this.pageSize();
|
|
2388
2412
|
const searchParams = {
|
|
2389
2413
|
search: this.searchTerm() || undefined,
|
|
2390
2414
|
isStaff: this.staffFilter() !== '' ? this.staffFilter() === 'true' : undefined,
|
|
2391
2415
|
isActive: this.activeFilter() !== '' ? this.activeFilter() === 'true' : undefined,
|
|
2392
|
-
|
|
2393
|
-
|
|
2416
|
+
limit: this.pageSize(),
|
|
2417
|
+
offset: offset
|
|
2394
2418
|
};
|
|
2395
2419
|
this.userManagementService.getUsers(searchParams).subscribe({
|
|
2396
2420
|
next: (response) => {
|