@autofleet/zehut 3.1.2-beta.14 → 3.1.2-beta.15
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/lib/user/ApiUser.js +10 -3
- package/lib/utils.js +5 -4
- package/package.json +1 -1
package/lib/user/ApiUser.js
CHANGED
|
@@ -82,13 +82,13 @@ class ApiUser {
|
|
|
82
82
|
return Object.keys(this.privatePermissions[key] || {});
|
|
83
83
|
}
|
|
84
84
|
get elevatedPermissions() {
|
|
85
|
-
|
|
85
|
+
const permissions = {
|
|
86
86
|
fleets: {},
|
|
87
87
|
businessModels: {},
|
|
88
88
|
demandSources: {},
|
|
89
89
|
};
|
|
90
90
|
[...this.privateElevatedPermissionsHash.values()].forEach((elevatedPermissions) => {
|
|
91
|
-
|
|
91
|
+
(0, utils_1.mergePermissions)(permissions, elevatedPermissions);
|
|
92
92
|
});
|
|
93
93
|
return permissions;
|
|
94
94
|
}
|
|
@@ -96,7 +96,14 @@ class ApiUser {
|
|
|
96
96
|
if (!this.privatePermissions) {
|
|
97
97
|
throw new Error('Cannot get permissions without calling (async) getUserPermissions before');
|
|
98
98
|
}
|
|
99
|
-
const permissions =
|
|
99
|
+
const permissions = {
|
|
100
|
+
...this.privatePermissions,
|
|
101
|
+
fleets: { ...this.privatePermissions.fleets },
|
|
102
|
+
businessModels: { ...this.privatePermissions.businessModels },
|
|
103
|
+
demandSources: { ...this.privatePermissions.demandSources },
|
|
104
|
+
// Clone other nested objects as needed
|
|
105
|
+
};
|
|
106
|
+
(0, utils_1.mergePermissions)(permissions, this.elevatedPermissions);
|
|
100
107
|
return permissions;
|
|
101
108
|
}
|
|
102
109
|
elevatePermissions(addedPermissions) {
|
package/lib/utils.js
CHANGED
|
@@ -98,13 +98,14 @@ const getContextAttributes = (contextId, decodedToken) => {
|
|
|
98
98
|
};
|
|
99
99
|
exports.getContextAttributes = getContextAttributes;
|
|
100
100
|
const mergePermissions = (target, sources) => {
|
|
101
|
-
const base = structuredClone(target);
|
|
102
101
|
Object.keys(sources).forEach((topLevelKey) => {
|
|
103
|
-
|
|
102
|
+
// eslint-disable-next-line no-param-reassign
|
|
103
|
+
target[topLevelKey] ?? (target[topLevelKey] = {});
|
|
104
104
|
Object.entries(sources[topLevelKey]).forEach(([entityId, perms]) => {
|
|
105
|
-
|
|
105
|
+
// eslint-disable-next-line no-param-reassign
|
|
106
|
+
target[topLevelKey][entityId] = (target[topLevelKey][entityId] || []).concat(perms);
|
|
106
107
|
});
|
|
107
108
|
});
|
|
108
|
-
return
|
|
109
|
+
return target;
|
|
109
110
|
};
|
|
110
111
|
exports.mergePermissions = mergePermissions;
|