Skip to content

Commit

Permalink
Added parents lock check
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 22, 2017
1 parent f3caaab commit 76f3340
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/user/privilege/IPrivilegeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ function requirePrivilege(privilege, arg, resource, callback) {
}
exports.requirePrivilege = requirePrivilege;
function hasNoWriteLock(arg, resource, callback) {
resource.getLocks(function (e, locks) { return callback(e, locks ? locks.filter(function (l) { return l.user !== arg.user && l.lockKind.type.isSame(LockType_1.LockType.Write); }).length === 0 : false); });
resource.getLocks(function (e, locks) {
var hasNoLock = locks ? locks.filter(function (l) { return l.user !== arg.user && l.lockKind.type.isSame(LockType_1.LockType.Write); }).length === 0 : false;
if (!hasNoLock || !resource.parent)
callback(e, hasNoLock);
else
hasNoWriteLock(arg, resource.parent, callback);
});
}
exports.hasNoWriteLock = hasNoWriteLock;
8 changes: 7 additions & 1 deletion src/user/privilege/IPrivilegeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,11 @@ export interface IPrivilegeManager

export function hasNoWriteLock(arg : MethodCallArgs, resource : IResource, callback : PrivilegeManagerCallback)
{
resource.getLocks((e, locks) => callback(e, locks ? locks.filter((l) => l.user !== arg.user && l.lockKind.type.isSame(LockType.Write)).length === 0 : false));
resource.getLocks((e, locks) => {
const hasNoLock = locks ? locks.filter((l) => l.user !== arg.user && l.lockKind.type.isSame(LockType.Write)).length === 0 : false;
if(!hasNoLock || !resource.parent)
callback(e, hasNoLock);
else
hasNoWriteLock(arg, resource.parent, callback);
});
}

0 comments on commit 76f3340

Please sign in to comment.