Commit 4e0e4b7f authored by Romain Courteaud's avatar Romain Courteaud

ERP5: do not activate view attachment code by default.

view attachment only works if default_view_reference is specified during the storage creation.
parent 28566d87
...@@ -94,8 +94,14 @@ ...@@ -94,8 +94,14 @@
}; };
ERP5Storage.prototype.allAttachments = function (id) { ERP5Storage.prototype.allAttachments = function (id) {
var context = this;
return getDocumentAndHateoas(this, id) return getDocumentAndHateoas(this, id)
.push(function () { .push(function () {
if (context._default_view_reference === undefined) {
return {
links: {}
};
}
return { return {
view: {}, view: {},
links: {} links: {}
...@@ -106,6 +112,12 @@ ...@@ -106,6 +112,12 @@
ERP5Storage.prototype.getAttachment = function (id, action) { ERP5Storage.prototype.getAttachment = function (id, action) {
if (action === "view") { if (action === "view") {
if (this._default_view_reference === undefined) {
throw new jIO.util.jIOError(
"Cannot find attachment view for: " + id,
404
);
}
return getDocumentAndHateoas(this, id, return getDocumentAndHateoas(this, id,
{"_view": this._default_view_reference}) {"_view": this._default_view_reference})
.push(function (response) { .push(function (response) {
......
...@@ -221,6 +221,62 @@ ...@@ -221,6 +221,62 @@
stop(); stop();
expect(10); expect(10);
this.jio.allAttachments(id)
.then(function (result) {
deepEqual(result, {
links: {}
}, "Check document");
equal(server.requests.length, 2);
equal(server.requests[0].method, "GET");
equal(server.requests[0].url, domain);
equal(server.requests[0].requestBody, undefined);
equal(server.requests[0].withCredentials, true);
equal(server.requests[1].method, "GET");
equal(server.requests[1].url, traverse_url);
equal(server.requests[1].requestBody, undefined);
equal(server.requests[1].withCredentials, true);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("allAttachments ERP5 document with default view", function () {
var id = "person_module/20150119_azerty",
traverse_url = domain + "?mode=traverse&relative_url=" +
encodeURIComponent(id),
document_hateoas = JSON.stringify({
// Kept property
"title": "foo",
// Remove all _ properties
"_bar": "john doo",
"_links": {
type: {
name: "Person"
}
}
}),
server = this.server;
this.jio = jIO.createJIO({
type: "erp5",
url: domain,
default_view_reference: "bar_view"
});
this.server.respondWith("GET", domain, [200, {
"Content-Type": "application/hal+json"
}, root_hateoas]);
this.server.respondWith("GET", traverse_url, [200, {
"Content-Type": "application/hal+json"
}, document_hateoas]);
stop();
expect(10);
this.jio.allAttachments(id) this.jio.allAttachments(id)
.then(function (result) { .then(function (result) {
deepEqual(result, { deepEqual(result, {
...@@ -466,6 +522,34 @@ ...@@ -466,6 +522,34 @@
}); });
}); });
test("getAttachment: view without being specified", function () {
var id = "person_module/1";
this.jio = jIO.createJIO({
type: "erp5",
url: domain
});
stop();
expect(3);
this.jio.getAttachment(id, "view")
.then(function (result) {
ok(false, result);
})
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find attachment view for: " + id);
equal(error.status_code, 404);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("getAttachment: links on inexistent document", function () { test("getAttachment: links on inexistent document", function () {
var id = "person_module/1", var id = "person_module/1",
traverse_url = domain + "?mode=traverse&relative_url=" + traverse_url = domain + "?mode=traverse&relative_url=" +
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment