aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-01-28 01:49:04 +0100
committerKim Alvefur <zash@zash.se>2019-01-28 01:49:04 +0100
commit428da9fe8a8af9170f3cd5578767d0a17503fe95 (patch)
tree65d3820152086166dd80ccafd4e97ef8eb19c863
parente6e8b9acf0b9d3227759a647e6103091b3450a05 (diff)
parent6d84bd44ba3a8bde48580b0f772e8278969af5cc (diff)
downloadprosody-428da9fe8a8af9170f3cd5578767d0a17503fe95.tar.gz
prosody-428da9fe8a8af9170f3cd5578767d0a17503fe95.zip
Merge 0.11->trunk
-rw-r--r--plugins/mod_pubsub/pubsub.lib.lua12
-rw-r--r--spec/util_pubsub_spec.lua31
-rw-r--r--util/pubsub.lua21
3 files changed, 53 insertions, 11 deletions
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index 1bd5fa33..50ef7ddf 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -295,14 +295,20 @@ end
function handlers.get_items(origin, stanza, items, service)
local node = items.attr.node;
- local item = items:get_child("item");
- local item_id = item and item.attr.id;
+
+ local requested_items = {};
+ for item in items:childtags("item") do
+ table.insert(requested_items, item.attr.id);
+ end
+ if requested_items[1] == nil then
+ requested_items = nil;
+ end
if not node then
origin.send(pubsub_error_reply(stanza, "nodeid-required"));
return true;
end
- local ok, results = service:get_items(node, stanza.attr.from, item_id);
+ local ok, results = service:get_items(node, stanza.attr.from, requested_items);
if not ok then
origin.send(pubsub_error_reply(stanza, results));
return true;
diff --git a/spec/util_pubsub_spec.lua b/spec/util_pubsub_spec.lua
index 6386100b..551aedd6 100644
--- a/spec/util_pubsub_spec.lua
+++ b/spec/util_pubsub_spec.lua
@@ -170,6 +170,37 @@ describe("util.pubsub", function ()
end);
+ describe("the thing", function ()
+ randomize(false); -- These tests are ordered
+
+ local service = pubsub.new();
+
+ it("creates a node with some items", function ()
+ assert.truthy(service:create("node", true, { max_items = 3 }));
+ assert.truthy(service:publish("node", true, "1", "item 1"));
+ assert.truthy(service:publish("node", true, "2", "item 2"));
+ assert.truthy(service:publish("node", true, "3", "item 3"));
+ end);
+
+ it("should return the requested item", function ()
+ local ok, ret = service:get_items("node", true, "1");
+ assert.truthy(ok);
+ assert.same({ "1", ["1"] = "item 1" }, ret);
+ end);
+
+ it("should return multiple requested items", function ()
+ local ok, ret = service:get_items("node", true, { "1", "2" });
+ assert.truthy(ok);
+ assert.same({
+ "1",
+ "2",
+ ["1"] = "item 1",
+ ["2"] = "item 2",
+ }, ret);
+ end);
+ end);
+
+
describe("node config", function ()
local service;
before_each(function ()
diff --git a/util/pubsub.lua b/util/pubsub.lua
index 47e526a7..a53e8b95 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -600,7 +600,7 @@ function service:purge(node, actor, notify) --> ok, err
return true
end
-function service:get_items(node, actor, id) --> (true, { id, [id] = node }) or (false, err)
+function service:get_items(node, actor, ids) --> (true, { id, [id] = node }) or (false, err)
-- Access checking
if not self:may(node, actor, "get_items") then
return false, "forbidden";
@@ -610,20 +610,25 @@ function service:get_items(node, actor, id) --> (true, { id, [id] = node }) or (
if not node_obj then
return false, "item-not-found";
end
- if id then -- Restrict results to a single specific item
- local with_id = self.data[node]:get(id);
- if not with_id then
- return true, { };
+ if type(ids) == "string" then -- COMPAT see #1305
+ ids = { ids };
+ end
+ local data = {};
+ if ids then
+ for _, key in ipairs(ids) do
+ local value = self.data[node]:get(key);
+ if value then
+ data[#data+1] = key;
+ data[key] = value;
+ end
end
- return true, { id, [id] = with_id };
else
- local data = {}
for key, value in self.data[node]:items() do
data[#data+1] = key;
data[key] = value;
end
- return true, data;
end
+ return true, data;
end
function service:get_last_item(node, actor) --> (true, id, node) or (false, err)