Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/js/oc-backbone-webdav.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@
convertModelAttributesToDavProperties(model.changed, options.davProperties),
headers
).then(function(result) {
if (result.status === 207 && result.body && result.body.length > 0) {
if (_.find(result.body[0].propStat, function(propStat) {
var statusCode = parseInt(propStat.status.split(' ')[1], 10);
return statusCode >= 400;
})) {
// in REST, validation errors are usually represented with 422 Unprocessable Entity,
result.status = 422;
}
}

if (isSuccessStatus(result.status)) {
if (_.isFunction(options.success)) {
// pass the object's own values because the server
Expand Down
65 changes: 62 additions & 3 deletions core/js/tests/specs/oc-backbone-webdavSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,18 @@ describe('Backbone Webdav extension', function() {
.toEqual('XMLHttpRequest');

deferredRequest.resolve({
status: 201,
body: ''
status: 207,
body: [{
href: 'http://example.com/owncloud/remote.php/test/123',
propStat: [{
status: 'HTTP/1.1 200 OK',
properties: {
'{http://owncloud.org/ns}first-name': '',
'{http://owncloud.org/ns}age-name': '',
'{http://owncloud.org/ns}married': ''
}
}]
}]
});

expect(model.id).toEqual('123');
Expand All @@ -281,6 +291,51 @@ describe('Backbone Webdav extension', function() {
expect(model.get('married')).toEqual(true);
});

it('calls error callback with status code 422 in case of failed PROPPATCH properties', function() {
var successHandler = sinon.stub();
var errorHandler = sinon.stub();
var model = new TestModel({
id: '123',
firstName: 'Hello',
lastName: 'World',
age: 32,
married: false
});

model.save({
firstName: 'Hey',
lastName: 'low'
}, {
success: successHandler,
error: errorHandler
});

deferredRequest.resolve({
status: 207,
body: [{
href: 'http://example.com/owncloud/remote.php/test/123',
propStat: [{
status: 'HTTP/1.1 200 OK',
properties: {
'{http://owncloud.org/ns}last-name': ''
}
}, {
status: 'HTTP/1.1 403 Forbidden',
properties: {
'{http://owncloud.org/ns}first-name': ''
}
}]
}]
});

expect(davClientPropPatchStub.calledOnce).toEqual(true);

expect(successHandler.notCalled).toEqual(true);
expect(errorHandler.calledOnce).toEqual(true);
expect(errorHandler.getCall(0).args[0]).toEqual(model);
expect(errorHandler.getCall(0).args[1].status).toEqual(422);
});

it('uses PROPFIND to fetch single model', function() {
var model = new TestModel({
id: '123'
Expand Down Expand Up @@ -774,7 +829,11 @@ describe('Backbone Webdav extension', function() {

deferredRequest.resolve({
status: 201,
body: '',
body: [{
propStat: {
status: 'HTTP/1.1 200 OK'
}
}],
xhr: {
getResponseHeader: _.noop
}
Expand Down