aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES4
-rw-r--r--plugins/mod_pep.lua11
-rw-r--r--plugins/mod_pubsub/mod_pubsub.lua6
-rw-r--r--plugins/mod_pubsub/pubsub.lib.lua40
-rw-r--r--spec/util_dataforms_spec.lua39
-rw-r--r--util/dataforms.lua6
-rw-r--r--util/pubsub.lua19
7 files changed, 103 insertions, 22 deletions
diff --git a/CHANGES b/CHANGES
index 58dd38fd..489578d9 100644
--- a/CHANGES
+++ b/CHANGES
@@ -14,7 +14,9 @@ New features
- PubSub features
- Persistence
- Affiliations
- - mod\_pep\_plus
+ - Access models
+ - "publish-options"
+- PEP now uses our pubsub code and now shares the above features
- Asynchronous operations
- Busted for tests
- mod\_muc\_mam (XEP-0313 in groupchats)
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index 3b818c8d..1d81c82f 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -81,12 +81,17 @@ local function nodestore(username)
function store:set(node, data)
if data then
-- Save the data without subscriptions
- -- TODO Save explicit subscriptions maybe?
+ local subscribers = {};
+ for jid, sub in pairs(data.subscribers) do
+ if type(sub) ~= "table" or not sub.presence then
+ subscribers[jid] = sub;
+ end
+ end
data = {
name = data.name;
config = data.config;
affiliations = data.affiliations;
- subscribers = {};
+ subscribers = subscribers;
};
end
return node_config:set(username, node, data);
@@ -353,7 +358,7 @@ local function update_subscriptions(recipient, service_name, nodes)
end
for node in nodes - current do
- service:add_subscription(node, recipient, recipient);
+ service:add_subscription(node, recipient, recipient, { presence = true });
resend_last_item(recipient, node, service);
end
diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index 113ee2b3..25b5192d 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -150,6 +150,10 @@ local function get_affiliation(jid)
end
end
+function get_service()
+ return service;
+end
+
function set_service(new_service)
service = new_service;
module.environment.service = service;
@@ -196,6 +200,7 @@ function module.load()
publish = true;
retract = true;
get_nodes = true;
+ get_configuration = true;
subscribe = true;
unsubscribe = true;
@@ -220,6 +225,7 @@ function module.load()
delete = true;
get_nodes = true;
configure = true;
+ get_configuration = true;
subscribe = true;
unsubscribe = true;
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index 3d75c2e3..40a664f2 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -12,8 +12,6 @@ local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
-local enable_publish_options = module:get_option_boolean("enable_publish_options", false);
-
local _M = {};
local handlers = {};
@@ -86,6 +84,16 @@ local node_config_form = dataform {
};
{
type = "list-single";
+ name = "pubsub#publish_model";
+ label = "Specify the publisher model";
+ options = {
+ { value = "publishers" };
+ { value = "subscribers" };
+ { value = "open" };
+ };
+ };
+ {
+ type = "list-single";
name = "pubsub#notification_type";
label = "Specify the delivery style for notifications";
options = {
@@ -131,6 +139,7 @@ local config_field_map = {
persist_items = "pubsub#persist_items";
notification_type = "pubsub#notification_type";
access_model = "pubsub#access_model";
+ publish_model = "pubsub#publish_model";
};
local reverse_config_field_map = {};
for k, v in pairs(config_field_map) do reverse_config_field_map[v] = k; end
@@ -144,6 +153,7 @@ local function config_to_xep0060(node_config)
["pubsub#persist_items"] = node_config["persist_items"];
["pubsub#notification_type"] = node_config["notification_type"];
["pubsub#access_model"] = node_config["access_model"];
+ ["pubsub#publish_model"] = node_config["publish_model"];
}
end
@@ -152,6 +162,9 @@ local function config_from_xep0060(config, strict)
for config_field, config_value in pairs(config) do
local mapped_name = reverse_config_field_map[config_field];
if mapped_name then
+ -- FIXME: The intention is to add "subtype" support to
+ -- util.dataforms, which will remove the need for this
+ -- ugly hack
if mapped_name == "max_items" then
config_value = tonumber(config_value);
end
@@ -183,7 +196,7 @@ local service_method_feature_map = {
get_items = { "retrieve-items" };
get_subscriptions = { "retrieve-subscriptions" };
node_defaults = { "retrieve-default" };
- publish = { "publish", "multi-items", enable_publish_options and "publish-options" or nil };
+ publish = { "publish", "multi-items", "publish-options" };
purge = { "purge-nodes" };
retract = { "delete-items", "retract-items" };
set_node_config = { "config-node" };
@@ -548,7 +561,7 @@ function handlers.set_publish(origin, stanza, publish, service)
return true;
end
local publish_options = stanza.tags[1]:get_child("publish-options");
- if enable_publish_options and publish_options then
+ if publish_options then
-- Ensure that the node configuration matches the values in publish-options
local publish_options_form = publish_options:get_child("x", "jabber:x:data");
local required_config = config_from_xep0060(node_config_form:data(publish_options_form), true);
@@ -642,18 +655,12 @@ function handlers.owner_get_configure(origin, stanza, config, service)
return true;
end
- if not service:may(node, stanza.attr.from, "configure") then
- origin.send(pubsub_error_reply(stanza, "forbidden"));
- return true;
- end
-
- local node_obj = service.nodes[node];
- if not node_obj then
- origin.send(pubsub_error_reply(stanza, "item-not-found"));
+ local ok, node_config = service:get_node_config(node, stanza.attr.from);
+ if not ok then
+ origin.send(pubsub_error_reply(stanza, node_config));
return true;
end
- local node_config = node_obj.config;
local pubsub_form_data = config_to_xep0060(node_config);
local reply = st.reply(stanza)
:tag("pubsub", { xmlns = xmlns_pubsub_owner })
@@ -678,7 +685,12 @@ function handlers.owner_set_configure(origin, stanza, config, service)
origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform"));
return true;
end
- local form_data, err = node_config_form:data(config_form);
+ local ok, old_config = service:get_node_config(node, stanza.attr.from);
+ if not ok then
+ origin.send(pubsub_error_reply(stanza, old_config));
+ return true;
+ end
+ local form_data, err = node_config_form:data(config_form, old_config);
if not form_data then
origin.send(st.error_reply(stanza, "modify", "bad-request", err));
return true;
diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua
index 66236e96..863a3290 100644
--- a/spec/util_dataforms_spec.lua
+++ b/spec/util_dataforms_spec.lua
@@ -347,5 +347,44 @@ describe("util.dataforms", function ()
assert.truthy(f:find("field/option"));
end);
end);
+
+ describe("using current values in place of missing fields", function ()
+ it("gets back the previous values when given an empty form", function ()
+ local current = {
+ ["list-multi-field"] = {
+ "list-multi-option-value#2";
+ };
+ ["list-single-field"] = "list-single-value#2";
+ ["hidden-field"] = "hidden-value";
+ ["boolean-field"] = false;
+ ["text-multi-field"] = "words\ngo\nhere";
+ ["jid-single-field"] = "alice@example.com";
+ ["text-private-field"] = "hunter2";
+ ["text-single-field"] = "text-single-value";
+ ["jid-multi-field"] = {
+ "bob@example.net";
+ };
+ };
+ local expect = {
+ -- FORM_TYPE = "xmpp:prosody.im/spec/util.dataforms#1"; -- does this need to be included?
+ ["list-multi-field"] = {
+ "list-multi-option-value#2";
+ };
+ ["list-single-field"] = "list-single-value#2";
+ ["hidden-field"] = "hidden-value";
+ ["boolean-field"] = false;
+ ["text-multi-field"] = "words\ngo\nhere";
+ ["jid-single-field"] = "alice@example.com";
+ ["text-private-field"] = "hunter2";
+ ["text-single-field"] = "text-single-value";
+ ["jid-multi-field"] = {
+ "bob@example.net";
+ };
+ };
+ local data, err = some_form:data(st.stanza("x", {xmlns="jabber:x:data"}), current);
+ assert.is.table(data, err);
+ assert.same(expect, data, "got back the same data");
+ end);
+ end);
end);
diff --git a/util/dataforms.lua b/util/dataforms.lua
index a75e8db0..a5733b83 100644
--- a/util/dataforms.lua
+++ b/util/dataforms.lua
@@ -142,7 +142,7 @@ end
local field_readers = {};
-function form_t.data(layout, stanza)
+function form_t.data(layout, stanza, current)
local data = {};
local errors = {};
local present = {};
@@ -157,7 +157,9 @@ function form_t.data(layout, stanza)
end
if not tag then
- if field.required then
+ if current and current[field.name] ~= nil then
+ data[field.name] = current[field.name];
+ elseif field.required then
errors[field.name] = "Required value missing";
end
elseif field.name then
diff --git a/util/pubsub.lua b/util/pubsub.lua
index 381c449a..f9255a55 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -17,6 +17,7 @@ local default_node_config = {
["persist_items"] = false;
["max_items"] = 20;
["access_model"] = "open";
+ ["publish_model"] = "publishers";
};
local default_node_config_mt = { __index = default_node_config };
@@ -365,7 +366,19 @@ end
function service:publish(node, actor, id, item)
-- Access checking
- if not self:may(node, actor, "publish") then
+ local may_publish = false;
+
+ if self:may(node, actor, "publish") then
+ may_publish = true;
+ else
+ local node_obj = self.nodes[node];
+ local publish_model = node_obj and node_obj.config.publish_model;
+ if publish_model == "open"
+ or (publish_model == "subscribers" and node_obj.subscribers[actor]) then
+ may_publish = true;
+ end
+ end
+ if not may_publish then
return false, "forbidden";
end
--
@@ -565,6 +578,8 @@ function service:set_node_config(node, actor, new_config)
return false, "item-not-found";
end
+ setmetatable(new_config, {__index=self.node_defaults})
+
if self.config.check_node_config then
local ok = self.config.check_node_config(node, actor, new_config);
if not ok then
@@ -573,7 +588,7 @@ function service:set_node_config(node, actor, new_config)
end
local old_config = node_obj.config;
- node_obj.config = setmetatable(new_config, {__index=self.node_defaults});
+ node_obj.config = new_config;
if self.config.nodestore then
local ok, err = save_node_to_store(self, node_obj);