Skip to content

Commit

Permalink
Implemented DAV:lockdiscovery in PROPFIND
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 23, 2017
1 parent bb9b575 commit 9009ad1
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 4 deletions.
55 changes: 53 additions & 2 deletions lib/server/commands/Propfind.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
67 changes: 65 additions & 2 deletions src/server/commands/Propfind.ts
Original file line number Diff line number Diff line change
@@ -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<any>)
{
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) => {
Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit 9009ad1

Please sign in to comment.