Annotate

plugins/mod_server_contact_info.lua @ 8498:85f60424a8b1

CHANGES: Mention move to Busted for tests
author Kim Alvefur <zash@zash.se>
date Sat, 30 Dec 2017 22:45:14 +0100
parent 8257:c24837f57259
child 9333:fd704adc62e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8257
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- XEP-0157: Contact Addresses for XMPP Services for Prosody
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 --
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2011-2016 Kim Alvefur
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 --
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- This file is MIT/X11 licensed.
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 --
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local t_insert = table.insert;
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local array = require "util.array";
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local df_new = require "util.dataforms".new;
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local valid_types = {
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 abuse = true;
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 admin = true;
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 feedback = true;
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 sales = true;
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 security = true;
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 support = true;
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 }
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local contact_config = module:get_option("contact_info");
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 if not contact_config or not next(contact_config) then -- we'll use admins from the config as default
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local admins = module:get_option_inherited_set("admins", {});
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 if admins:empty() then
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 module:log("error", "No contact_info or admins set in config");
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 return -- Nothing to attach, so we'll just skip it.
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 module:log("info", "No contact_info in config, using admins as fallback");
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 contact_config = {
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 admin = array.collect( admins / function(admin) return "xmpp:" .. admin; end);
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 };
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 end
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 local form_layout = {
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 { value = "http://jabber.org/network/serverinfo"; type = "hidden"; name = "FORM_TYPE"; };
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 };
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 local form_values = {};
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 for t in pairs(valid_types) do
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 local addresses = contact_config[t];
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 if addresses then
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 t_insert(form_layout, { name = t .. "-addresses", type = "list-multi" });
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 form_values[t .. "-addresses"] = addresses;
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 end
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 end
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48
c24837f57259 mod_server_contact_info: Import from prosody-modules 2c59f2f0c37d (fixes #778)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 module:add_extension(df_new(form_layout):form(form_values, "result"));