@noatgnu/cupcake-core 1.2.3 → 1.2.5
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() {
|
|
@@ -578,7 +594,7 @@ class ApiService {
|
|
|
578
594
|
return this.http.get(`${this.apiUrl}/users/${id}/`);
|
|
579
595
|
}
|
|
580
596
|
createUser(userData) {
|
|
581
|
-
return this.
|
|
597
|
+
return this.post(`${this.apiUrl}/users/admin_create/`, userData);
|
|
582
598
|
}
|
|
583
599
|
updateUser(id, userData) {
|
|
584
600
|
return this.http.patch(`${this.apiUrl}/users/${id}/`, userData);
|
|
@@ -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);
|