@kumori/aurora-backend-handler 1.1.5 → 1.1.7
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/helpers/user-helper.ts +46 -38
- package/package.json +1 -1
package/helpers/user-helper.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
Notification,
|
|
3
|
+
Plan,
|
|
4
|
+
Tenant,
|
|
5
|
+
UserData,
|
|
6
|
+
tenantRole,
|
|
7
|
+
} from "@kumori/aurora-interfaces";
|
|
4
8
|
|
|
5
9
|
interface HandleUserEventParams {
|
|
6
10
|
eventData: any;
|
|
@@ -34,31 +38,33 @@ export const handleUserEvent = ({
|
|
|
34
38
|
const userId = eventData.id.name;
|
|
35
39
|
const userTenants = Object.keys(eventData.status.tenants);
|
|
36
40
|
const deletedTenantKeys: string[] = [];
|
|
37
|
-
Object.entries(eventData.status.tenants).forEach(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
Object.entries(eventData.status.tenants).forEach(
|
|
42
|
+
([tenantId, tenantInfo]: [string, any]) => {
|
|
43
|
+
if (tenantInfo.status === "rejected") {
|
|
44
|
+
const tenant = tenantsMap.get(tenantId);
|
|
45
|
+
if (tenant) {
|
|
46
|
+
tenantsMap.set(tenantId, { ...tenant, status: "leaving" });
|
|
47
|
+
}
|
|
42
48
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
49
|
+
},
|
|
50
|
+
);
|
|
45
51
|
for (const key of tenantsMap.keys()) {
|
|
46
52
|
if (!userTenants.includes(key)) {
|
|
47
53
|
const tenantToDelete = tenantsMap.get(key);
|
|
48
54
|
if (tenantToDelete) {
|
|
49
|
-
const currentUserInTenant = tenantToDelete.users.find(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (currentUserInTenant
|
|
55
|
+
const currentUserInTenant = tenantToDelete.users.find(
|
|
56
|
+
(u) => u.id === userId,
|
|
57
|
+
);
|
|
58
|
+
const isRejectedOrLeaving =
|
|
59
|
+
currentUserInTenant?.status === "rejected" ||
|
|
60
|
+
tenantToDelete.status === "leaving";
|
|
61
|
+
|
|
62
|
+
if (currentUserInTenant && !isRejectedOrLeaving) {
|
|
57
63
|
const onlyOneUser = tenantToDelete.users.length === 1;
|
|
58
64
|
const isSoloOwner =
|
|
59
|
-
onlyOneUser &&
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
onlyOneUser &&
|
|
66
|
+
currentUserInTenant.role === tenantRole.OWNER &&
|
|
67
|
+
currentUserInTenant.id === userId;
|
|
62
68
|
|
|
63
69
|
if (isSoloOwner) {
|
|
64
70
|
eventHelper.tenant.publish.deleted(tenantToDelete);
|
|
@@ -72,7 +78,9 @@ export const handleUserEvent = ({
|
|
|
72
78
|
tenant: tenantToDelete.name,
|
|
73
79
|
},
|
|
74
80
|
};
|
|
75
|
-
eventHelper.notification.publish.creation(
|
|
81
|
+
eventHelper.notification.publish.creation(
|
|
82
|
+
tenantDeletedNotification,
|
|
83
|
+
);
|
|
76
84
|
} else {
|
|
77
85
|
const userRemovedNotification: Notification = {
|
|
78
86
|
type: "info",
|
|
@@ -114,14 +122,14 @@ export const handleUserEvent = ({
|
|
|
114
122
|
};
|
|
115
123
|
userPlans.push(basicPlan);
|
|
116
124
|
}
|
|
117
|
-
}
|
|
125
|
+
},
|
|
118
126
|
);
|
|
119
127
|
}
|
|
120
128
|
const tempProviders: Record<string, string> = eventData.spec.providers || {};
|
|
121
129
|
const providers: { name: string; email: string; password?: string }[] = [];
|
|
122
130
|
|
|
123
131
|
const existingProvidersMap = new Map(
|
|
124
|
-
(currentUserData.provider || []).map((p) => [p.name, p])
|
|
132
|
+
(currentUserData.provider || []).map((p) => [p.name, p]),
|
|
125
133
|
);
|
|
126
134
|
|
|
127
135
|
for (const [providerName, providerId] of Object.entries(tempProviders)) {
|
|
@@ -161,18 +169,18 @@ export const handleUserEvent = ({
|
|
|
161
169
|
};
|
|
162
170
|
};
|
|
163
171
|
export const handleUserOperationError = (): UserData => {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
172
|
+
return {
|
|
173
|
+
id: "",
|
|
174
|
+
name: "",
|
|
175
|
+
surname: "",
|
|
176
|
+
provider: [],
|
|
177
|
+
notificationsEnabled: "",
|
|
178
|
+
organizations: [],
|
|
179
|
+
clusterTokens: [],
|
|
180
|
+
tokens: [],
|
|
181
|
+
tenants: [],
|
|
182
|
+
axebowPlan: "freemium",
|
|
183
|
+
companyName: "",
|
|
184
|
+
rol: "",
|
|
185
|
+
};
|
|
178
186
|
};
|