From 0a9ca377a7e873e60cb96937e781bfb2f8029782 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Mon, 19 Jun 2017 15:05:20 +0200 Subject: [PATCH] Allowed a lock to not have a 'userUid' leading to skip the user checking when testing the user privileges --- lib/user/privilege/IPrivilegeManager.js | 2 +- src/user/privilege/IPrivilegeManager.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/user/privilege/IPrivilegeManager.js b/lib/user/privilege/IPrivilegeManager.js index 375fe032..d97e4666 100644 --- a/lib/user/privilege/IPrivilegeManager.js +++ b/lib/user/privilege/IPrivilegeManager.js @@ -18,7 +18,7 @@ function requirePrivilege(privilege, arg, resource, callback) { exports.requirePrivilege = requirePrivilege; function hasNoWriteLock(arg, resource, callback) { resource.getLocks(function (e, locks) { - var hasNoLock = locks ? locks.filter(function (l) { return l.userUid !== arg.user.uid && l.lockKind.type.isSame(LockType_1.LockType.Write); }).length === 0 : false; + var hasNoLock = locks ? locks.filter(function (l) { return (!l.userUid || l.userUid !== arg.user.uid) && l.lockKind.type.isSame(LockType_1.LockType.Write); }).length === 0 : false; if (!hasNoLock || !resource.parent) callback(e, hasNoLock); else diff --git a/src/user/privilege/IPrivilegeManager.ts b/src/user/privilege/IPrivilegeManager.ts index f037ef00..abe8306e 100644 --- a/src/user/privilege/IPrivilegeManager.ts +++ b/src/user/privilege/IPrivilegeManager.ts @@ -85,7 +85,7 @@ export interface IPrivilegeManager export function hasNoWriteLock(arg : MethodCallArgs, resource : IResource, callback : PrivilegeManagerCallback) { resource.getLocks((e, locks) => { - const hasNoLock = locks ? locks.filter((l) => l.userUid !== arg.user.uid && l.lockKind.type.isSame(LockType.Write)).length === 0 : false; + const hasNoLock = locks ? locks.filter((l) => (!l.userUid || l.userUid !== arg.user.uid) && l.lockKind.type.isSame(LockType.Write)).length === 0 : false; if(!hasNoLock || !resource.parent) callback(e, hasNoLock); else