comparison mod_server_contact_info/mod_server_contact_info.lua @ 2317:465b34fdeb60

mod_server_contact_info: Include both global and local admins in fallback mode
author Kim Alvefur <zash@zash.se>
date Sat, 01 Oct 2016 17:13:57 +0200
parents 4fdcb5c35021
children 3e5828e3f17f
comparison
equal deleted inserted replaced
2316:2a2de19413e7 2317:465b34fdeb60
1 -- This plugin implements http://xmpp.org/extensions/xep-0157.html 1 -- This plugin implements http://xmpp.org/extensions/xep-0157.html
2 local t_insert = table.insert; 2 local t_insert = table.insert;
3 local array = require "util.array";
3 local df_new = require "util.dataforms".new; 4 local df_new = require "util.dataforms".new;
4 5
5 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo 6 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo
6 local valid_types = { 7 local valid_types = {
7 abuse = true; 8 abuse = true;
12 support = true; 13 support = true;
13 } 14 }
14 15
15 local contact_config = module:get_option("contact_info"); 16 local contact_config = module:get_option("contact_info");
16 if not contact_config then -- we'll use admins from the config as default 17 if not contact_config then -- we'll use admins from the config as default
17 contact_config = { admin = {}; }; 18 local admins = module:get_option_inherited_set("admins", {});
18 local admins = module:get_option("admins"); 19 if admins:empty() then
19 if not admins or #admins == 0 then
20 module:log("debug", "No contact_info or admins in config"); 20 module:log("debug", "No contact_info or admins in config");
21 return -- Nothing to attach, so we'll just skip it. 21 return -- Nothing to attach, so we'll just skip it.
22 end 22 end
23 module:log("debug", "No contact_info in config, using admins as fallback"); 23 module:log("debug", "No contact_info in config, using admins as fallback");
24 --TODO fetch global admins too? 24 contact_config = {
25 for i = 1,#admins do 25 admin = array.collect( admins / function(admin) return "xmpp:" .. admin; end);
26 t_insert(contact_config.admin, "xmpp:" .. admins[i]) 26 };
27 module:log("debug", "Added %s to admin-addresses", admins[i]);
28 end
29 end 27 end
30 if not next(contact_config) then 28 if not next(contact_config) then
31 module:log("debug", "No contacts, skipping"); 29 module:log("debug", "No contacts, skipping");
32 return -- No use in serving an empty form. 30 return -- No use in serving an empty form.
33 end 31 end