bugfix to permissions
This commit is contained in:
parent
1c3b75579b
commit
137d77acaa
@ -43,7 +43,7 @@ class Entity
|
|||||||
this.#_id = id;
|
this.#_id = id;
|
||||||
this.#_name = name;
|
this.#_name = name;
|
||||||
this.#_disabled = disabled ?? false;
|
this.#_disabled = disabled ?? false;
|
||||||
this.#_permissions = PermissionManager.merge(PermissionManager.DefaultPermissions, permissions || {});
|
this.#_permissions = PermissionManager.merge(permissions || {}, PermissionManager.DefaultPermissions);
|
||||||
this.#_createdTimestamp = createdTimestamp ?? Date.now();
|
this.#_createdTimestamp = createdTimestamp ?? Date.now();
|
||||||
this.#_cachedTimestamp = Date.now();
|
this.#_cachedTimestamp = Date.now();
|
||||||
this.#_note = note ?? null;
|
this.#_note = note ?? null;
|
||||||
@ -63,7 +63,7 @@ class Entity
|
|||||||
updatePermissions (perms: Permissions)
|
updatePermissions (perms: Permissions)
|
||||||
{
|
{
|
||||||
PermissionManager.validatePermissions(perms);
|
PermissionManager.validatePermissions(perms);
|
||||||
this.#_permissions = PermissionManager.merge(this.#_permissions, perms);
|
this.#_permissions = PermissionManager.merge(this.#_permissions, perms, true);
|
||||||
return this.save();
|
return this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,10 +100,11 @@ class PermissionManager
|
|||||||
* @static
|
* @static
|
||||||
* @param {Object} to Object into which to write the permissions
|
* @param {Object} to Object into which to write the permissions
|
||||||
* @param {Object} from Object from which to draw the permissions
|
* @param {Object} from Object from which to draw the permissions
|
||||||
|
* @param {boolean} overwrite If a permission exists in both objects, overwrite the permission in the target with the value from the source
|
||||||
* @return {Object} Merged permissions
|
* @return {Object} Merged permissions
|
||||||
* @memberof PermissionManager
|
* @memberof PermissionManager
|
||||||
*/
|
*/
|
||||||
static merge (to: Permissions, from: Permissions): Permissions
|
static merge (to: Permissions, from: Permissions, overwrite?: boolean): Permissions
|
||||||
{
|
{
|
||||||
const keys = Object.keys(from);
|
const keys = Object.keys(from);
|
||||||
for (const key of keys)
|
for (const key of keys)
|
||||||
@ -116,9 +117,8 @@ class PermissionManager
|
|||||||
{
|
{
|
||||||
to[key] = { default: to[key] || 0 };
|
to[key] = { default: to[key] || 0 };
|
||||||
PermissionManager.merge(to[key] as Permissions, from[key] as Permissions);
|
PermissionManager.merge(to[key] as Permissions, from[key] as Permissions);
|
||||||
// eslint-disable-next-line no-undefined
|
|
||||||
}
|
}
|
||||||
else // if (!(key in to))
|
else if (!(key in to) || overwrite)
|
||||||
{
|
{
|
||||||
to[key] = from[key];
|
to[key] = from[key];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user