# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1530037773 -7200
# Node ID 384ef9732b8143cfd0b493e28e4c6400abb7601e
# Parent  0ae46e6ea6474edbb22f586f241f5ad449d5ceed
mod_pubsub: Support for setting affiliations (#622)

diff -r 0ae46e6ea647 -r 384ef9732b81 plugins/mod_pubsub/pubsub.lib.lua
--- a/plugins/mod_pubsub/pubsub.lib.lua	Tue Jun 26 20:00:07 2018 +0200
+++ b/plugins/mod_pubsub/pubsub.lib.lua	Tue Jun 26 20:29:33 2018 +0200
@@ -88,7 +88,7 @@
 	purge = { "purge-nodes" };
 	retract = { "delete-items", "retract-items" };
 	set_node_config = { "config-node" };
-	-- TODO -- set_affiliation = { "modify-affiliations" };
+	set_affiliation = { "modify-affiliations" };
 };
 local service_config_feature_map = {
 	autocreate_on_publish = { "auto-create" };
@@ -500,7 +500,16 @@
 		return true;
 	end
 
-	local reply = st.error_reply(stanza, "wait", "not-implemented", "yet");
+	for affiliation_tag in affiliations:childtags("affiliation") do
+		local jid = affiliation_tag.attr.jid;
+		local affiliation = affiliation_tag.attr.affiliation;
+
+		if affiliation == "none" then affiliation = nil; end
+
+		local ok, err = service:set_affiliation(node, stanza.attr.from, jid, affiliation);
+	end
+
+	local reply = st.reply(stanza);
 	origin.send(reply);
 	return true;
 end