Skip to content

Commit

Permalink
Fixed the PROPPATCH method => returned LOCKED instead of NOT AUTHORIZ…
Browse files Browse the repository at this point in the history
…ED (authentication)
  • Loading branch information
AdrienCastex committed Jan 22, 2018
1 parent 2cec981 commit 90acbe1
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 84 deletions.
90 changes: 51 additions & 39 deletions lib/server/v2/commands/Proppatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,63 +85,75 @@ var default_1 = (function () {
.done(function (_) { return finalize_1(); });
});
};
r.fs.isLocked(ctx, r.path, function (e, locked) {
if (e || locked) {
r.fs.checkPrivilege(ctx, r.path, 'canWriteProperties', function (e, can) {
console.log(e, can);
if (e || !can) {
if (e) {
if (!ctx.setCodeFromError(e))
ctx.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError);
}
else if (locked)
ctx.setCode(WebDAVRequest_1.HTTPCodes.Locked);
else if (!can)
ctx.setCodeFromError(Errors_1.Errors.NotEnoughPrivilege);
return callback();
}
r.propertyManager(function (e, pm) {
if (e) {
if (!ctx.setCodeFromError(e))
ctx.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError);
r.fs.isLocked(ctx, r.path, function (e, locked) {
if (e || locked) {
if (e) {
if (!ctx.setCodeFromError(e))
ctx.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError);
}
else if (locked)
ctx.setCode(WebDAVRequest_1.HTTPCodes.Locked);
return callback();
}
pm.getProperties(function (e, props) {
r.propertyManager(function (e, pm) {
if (e) {
if (!ctx.setCodeFromError(e))
ctx.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError);
return callback();
}
var properties = JSON.parse(JSON.stringify(props));
var pushSetReverseAction = function (el) {
var prop = properties[el.name];
if (prop)
reverse_1.push(function (cb) { return pm.setProperty(el.name, prop.value, prop.attributes, cb); });
else
reverse_1.push(function (cb) { return pm.removeProperty(el.name, cb); });
};
var pushRemoveReverseAction = function (el) {
var prop = properties[el.name];
reverse_1.push(function (cb) { return pm.setProperty(el.name, prop.value, prop.attributes, cb); });
};
execute_1('DAV:set', 'setProperty', function (el, callback) {
if (el.name.indexOf('DAV:') === 0) {
pushSetReverseAction(el);
return callback(Errors_1.Errors.Forbidden);
pm.getProperties(function (e, props) {
if (e) {
if (!ctx.setCodeFromError(e))
ctx.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError);
return callback();
}
pm.setProperty(el.name, el.elements, el.attributes, function (e) {
if (!e)
var properties = JSON.parse(JSON.stringify(props));
var pushSetReverseAction = function (el) {
var prop = properties[el.name];
if (prop)
reverse_1.push(function (cb) { return pm.setProperty(el.name, prop.value, prop.attributes, cb); });
else
reverse_1.push(function (cb) { return pm.removeProperty(el.name, cb); });
};
var pushRemoveReverseAction = function (el) {
var prop = properties[el.name];
reverse_1.push(function (cb) { return pm.setProperty(el.name, prop.value, prop.attributes, cb); });
};
execute_1('DAV:set', 'setProperty', function (el, callback) {
if (el.name.indexOf('DAV:') === 0) {
pushSetReverseAction(el);
callback(e);
return callback(Errors_1.Errors.Forbidden);
}
pm.setProperty(el.name, el.elements, el.attributes, function (e) {
if (!e)
pushSetReverseAction(el);
callback(e);
});
});
});
execute_1('DAV:remove', 'removeProperty', function (el, callback) {
if (el.name.indexOf('DAV:') === 0) {
pushRemoveReverseAction(el);
return callback(Errors_1.Errors.Forbidden);
}
pm.removeProperty(el.name, function (e) {
if (!e)
execute_1('DAV:remove', 'removeProperty', function (el, callback) {
if (el.name.indexOf('DAV:') === 0) {
pushRemoveReverseAction(el);
callback(e);
return callback(Errors_1.Errors.Forbidden);
}
pm.removeProperty(el.name, function (e) {
if (!e)
pushRemoveReverseAction(el);
callback(e);
});
});
});
}, false);
}, false);
});
});
});
}
Expand Down
105 changes: 60 additions & 45 deletions src/server/v2/commands/Proppatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,76 +102,91 @@ export default class implements HTTPMethod
.done((_) => finalize())
})
}

r.fs.isLocked(ctx, r.path, (e, locked) => {
if(e || locked)

r.fs.checkPrivilege(ctx, r.path, 'canWriteProperties', (e, can) => {
console.log(e, can);
if(e || !can)
{
if(e)
{
if(!ctx.setCodeFromError(e))
ctx.setCode(HTTPCodes.InternalServerError)
}
else if(locked)
ctx.setCode(HTTPCodes.Locked);
else if(!can)
ctx.setCodeFromError(Errors.NotEnoughPrivilege);
return callback();
}
r.propertyManager((e, pm) => {
if(e)

r.fs.isLocked(ctx, r.path, (e, locked) => {
if(e || locked)
{
if(!ctx.setCodeFromError(e))
ctx.setCode(HTTPCodes.InternalServerError)
if(e)
{
if(!ctx.setCodeFromError(e))
ctx.setCode(HTTPCodes.InternalServerError)
}
else if(locked)
ctx.setCode(HTTPCodes.Locked);
return callback();
}

pm.getProperties((e, props) => {
r.propertyManager((e, pm) => {
if(e)
{
if(!ctx.setCodeFromError(e))
ctx.setCode(HTTPCodes.InternalServerError)
return callback();
}

const properties = JSON.parse(JSON.stringify(props));

const pushSetReverseAction = (el : XMLElement) => {
const prop = properties[el.name];
if(prop)
reverse.push((cb) => pm.setProperty(el.name, prop.value, prop.attributes, cb));
else
reverse.push((cb) => pm.removeProperty(el.name, cb));
}
const pushRemoveReverseAction = (el : XMLElement) => {
const prop = properties[el.name];
reverse.push((cb) => pm.setProperty(el.name, prop.value, prop.attributes, cb));
}
execute('DAV:set', 'setProperty', (el : XMLElement, callback) => {
if(el.name.indexOf('DAV:') === 0)
pm.getProperties((e, props) => {
if(e)
{
pushSetReverseAction(el);
return callback(Errors.Forbidden);
if(!ctx.setCodeFromError(e))
ctx.setCode(HTTPCodes.InternalServerError)
return callback();
}

pm.setProperty(el.name, el.elements, el.attributes, (e) => {
if(!e)
pushSetReverseAction(el);
callback(e);
})
})
execute('DAV:remove', 'removeProperty', (el : XMLElement, callback) => {
if(el.name.indexOf('DAV:') === 0)
{
pushRemoveReverseAction(el);
return callback(Errors.Forbidden);
const properties = JSON.parse(JSON.stringify(props));

const pushSetReverseAction = (el : XMLElement) => {
const prop = properties[el.name];
if(prop)
reverse.push((cb) => pm.setProperty(el.name, prop.value, prop.attributes, cb));
else
reverse.push((cb) => pm.removeProperty(el.name, cb));
}
const pushRemoveReverseAction = (el : XMLElement) => {
const prop = properties[el.name];
reverse.push((cb) => pm.setProperty(el.name, prop.value, prop.attributes, cb));
}
execute('DAV:set', 'setProperty', (el : XMLElement, callback) => {
if(el.name.indexOf('DAV:') === 0)
{
pushSetReverseAction(el);
return callback(Errors.Forbidden);
}

pm.removeProperty(el.name, (e) => {
if(!e)
pm.setProperty(el.name, el.elements, el.attributes, (e) => {
if(!e)
pushSetReverseAction(el);
callback(e);
})
})
execute('DAV:remove', 'removeProperty', (el : XMLElement, callback) => {
if(el.name.indexOf('DAV:') === 0)
{
pushRemoveReverseAction(el);
callback(e);
return callback(Errors.Forbidden);
}

pm.removeProperty(el.name, (e) => {
if(!e)
pushRemoveReverseAction(el);
callback(e);
})
})
})
}, false)
}, false)
})
})
})
}
Expand Down

0 comments on commit 90acbe1

Please sign in to comment.