@kumori/aurora-backend-handler 1.1.6 → 1.1.8
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 +73 -53
- 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,46 +38,62 @@ 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
|
|
50
|
-
|
|
55
|
+
const currentUserInTenant = tenantToDelete.users.find(
|
|
56
|
+
(u) => u.id === userId,
|
|
57
|
+
);
|
|
58
|
+
const isRejectedOrLeaving =
|
|
59
|
+
currentUserInTenant?.status === "rejected" ||
|
|
60
|
+
tenantToDelete.status === "leaving";
|
|
51
61
|
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
if (currentUserInTenant && !isRejectedOrLeaving) {
|
|
63
|
+
const onlyOneUser = tenantToDelete.users.length === 1;
|
|
64
|
+
const isSoloOwner =
|
|
65
|
+
onlyOneUser &&
|
|
66
|
+
currentUserInTenant.role === tenantRole.OWNER &&
|
|
67
|
+
currentUserInTenant.id === userId;
|
|
68
|
+
|
|
69
|
+
if (isSoloOwner) {
|
|
70
|
+
eventHelper.tenant.publish.deleted(tenantToDelete);
|
|
71
|
+
const tenantDeletedNotification: Notification = {
|
|
72
|
+
type: "success",
|
|
73
|
+
subtype: "tenant-deleted",
|
|
74
|
+
date: Date.now().toString(),
|
|
75
|
+
callToAction: false,
|
|
76
|
+
status: "unread",
|
|
77
|
+
data: {
|
|
78
|
+
tenant: tenantToDelete.name,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
eventHelper.notification.publish.creation(
|
|
82
|
+
tenantDeletedNotification,
|
|
83
|
+
);
|
|
84
|
+
} else {
|
|
85
|
+
const userRemovedNotification: Notification = {
|
|
86
|
+
type: "info",
|
|
87
|
+
subtype: "user-removed-from-tenant",
|
|
88
|
+
date: Date.now().toString(),
|
|
89
|
+
callToAction: false,
|
|
90
|
+
status: "unread",
|
|
91
|
+
data: {
|
|
92
|
+
tenant: tenantToDelete.name,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
eventHelper.notification.publish.creation(userRemovedNotification);
|
|
96
|
+
}
|
|
77
97
|
}
|
|
78
98
|
deletedTenantKeys.push(key);
|
|
79
99
|
}
|
|
@@ -102,14 +122,14 @@ export const handleUserEvent = ({
|
|
|
102
122
|
};
|
|
103
123
|
userPlans.push(basicPlan);
|
|
104
124
|
}
|
|
105
|
-
}
|
|
125
|
+
},
|
|
106
126
|
);
|
|
107
127
|
}
|
|
108
128
|
const tempProviders: Record<string, string> = eventData.spec.providers || {};
|
|
109
129
|
const providers: { name: string; email: string; password?: string }[] = [];
|
|
110
130
|
|
|
111
131
|
const existingProvidersMap = new Map(
|
|
112
|
-
(currentUserData.provider || []).map((p) => [p.name, p])
|
|
132
|
+
(currentUserData.provider || []).map((p) => [p.name, p]),
|
|
113
133
|
);
|
|
114
134
|
|
|
115
135
|
for (const [providerName, providerId] of Object.entries(tempProviders)) {
|
|
@@ -149,18 +169,18 @@ export const handleUserEvent = ({
|
|
|
149
169
|
};
|
|
150
170
|
};
|
|
151
171
|
export const handleUserOperationError = (): UserData => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
+
};
|
|
166
186
|
};
|