diff --git a/lib/server/commands/Propfind.js b/lib/server/commands/Propfind.js index 014f952a..ebf2521c 100644 --- a/lib/server/commands/Propfind.js +++ b/lib/server/commands/Propfind.js @@ -2,8 +2,35 @@ Object.defineProperty(exports, "__esModule", { value: true }); var WebDAVRequest_1 = require("../WebDAVRequest"); var IResource_1 = require("../../resource/IResource"); +var FSPath_1 = require("../../manager/FSPath"); var XML_1 = require("../../helper/XML"); var http = require("http"); +function lockDiscovery(arg, path, resource, callback) { + arg.requireErPrivilege('canListLocks', resource, function (e, can) { + if (e || !can) { + callback(e, {}); + return; + } + resource.getLocks(function (e, locks) { + if (resource.parent) { + var parentPath = path.getParent(); + lockDiscovery(arg, parentPath, resource.parent, function (e, l) { + if (e) + callback(e, null); + else { + l[path.toString()] = locks; + callback(null, l); + } + }); + } + else + callback(null, (_a = {}, + _a[path.toString()] = locks, + _a)); + var _a; + }); + }); +} function default_1(arg, callback) { arg.getResource(function (e, resource) { if (e || !resource) { @@ -80,9 +107,33 @@ function default_1(arg, callback) { nbOut(e); }); }); arg.getResourcePath(resource, function (e, path) { - if (!e) + if (!e) { response.ele('D:href').add(arg.fullUri(path).replace(' ', '%20')); - nbOut(e); + var lockdiscovery_1 = prop.ele('D:lockdiscovery'); + lockDiscovery(arg, new FSPath_1.FSPath(path), resource, function (e, l) { + if (e) { + nbOut(e); + return; + } + for (var path_1 in l) { + for (var _i = 0, _a = l[path_1]; _i < _a.length; _i++) { + var _lock = _a[_i]; + var lock = _lock; + var activelock = lockdiscovery_1.ele('D:activelock'); + activelock.ele('D:lockscope').ele('D:' + lock.lockKind.scope.value.toLowerCase()); + activelock.ele('D:locktype').ele('D:' + lock.lockKind.type.value.toLowerCase()); + activelock.ele('D:depth').add('Infinity'); + activelock.ele('D:owner').add(lock.owner); + activelock.ele('D:timeout').add('Second-' + (lock.expirationDate - Date.now())); + activelock.ele('D:locktoken').ele('D:href').add(lock.uuid); + activelock.ele('D:lockroot').ele('D:href').add(arg.fullUri(path_1).replace(' ', '%20')); + } + } + nbOut(null); + }); + } + else + nbOut(e); }); resource.webName(function (e, name) { return process.nextTick(function () { if (!e) diff --git a/src/server/commands/Propfind.ts b/src/server/commands/Propfind.ts index 87fa5b45..f1e70c17 100644 --- a/src/server/commands/Propfind.ts +++ b/src/server/commands/Propfind.ts @@ -1,9 +1,42 @@ import { HTTPCodes, MethodCallArgs, WebDAVRequest } from '../WebDAVRequest' -import { IResource, ETag } from '../../resource/IResource' +import { IResource, ETag, ReturnCallback } from '../../resource/IResource' import { BasicPrivilege } from '../../user/privilege/IPrivilegeManager' +import { FSPath } from '../../manager/FSPath' +import { Lock } from '../../resource/lock/Lock' import { XML } from '../../helper/XML' import * as http from 'http' +function lockDiscovery(arg : MethodCallArgs, path : FSPath, resource : IResource, callback : ReturnCallback) +{ + arg.requireErPrivilege('canListLocks', resource, (e, can) => { + if(e || !can) + { + callback(e, {}); + return; + } + + resource.getLocks((e, locks) => { + if(resource.parent) + { + const parentPath = path.getParent(); + lockDiscovery(arg, parentPath, resource.parent, (e, l) => { + if(e) + callback(e, null); + else + { + l[path.toString()] = locks; + callback(null, l); + } + }); + } + else + callback(null, { + [path.toString()]: locks + }); + }); + }) +} + export default function(arg : MethodCallArgs, callback) { arg.getResource((e, resource) => { @@ -108,8 +141,38 @@ export default function(arg : MethodCallArgs, callback) arg.getResourcePath(resource, (e, path) => { if(!e) + { response.ele('D:href').add(arg.fullUri(path).replace(' ', '%20')); - nbOut(e); + const lockdiscovery = prop.ele('D:lockdiscovery'); + lockDiscovery(arg, new FSPath(path), resource, (e, l) => { + if(e) + { + nbOut(e); + return; + } + + for(const path in l) + { + for(const _lock of l[path]) + { + const lock : Lock = _lock; + const activelock = lockdiscovery.ele('D:activelock'); + + activelock.ele('D:lockscope').ele('D:' + lock.lockKind.scope.value.toLowerCase()) + activelock.ele('D:locktype').ele('D:' + lock.lockKind.type.value.toLowerCase()) + activelock.ele('D:depth').add('Infinity') + activelock.ele('D:owner').add(lock.owner) + activelock.ele('D:timeout').add('Second-' + (lock.expirationDate - Date.now())) + activelock.ele('D:locktoken').ele('D:href').add(lock.uuid) + activelock.ele('D:lockroot').ele('D:href').add(arg.fullUri(path).replace(' ', '%20')) + } + } + + nbOut(null); + }) + } + else + nbOut(e); }) resource.webName((e, name) => process.nextTick(() => {