comparison mod_muc_config_restrict/mod_muc_config_restrict.lua @ 1014:ed7431fd3b47

mod_muc_config_restrict: Allow restricting specific options in the MUC config form to service admins
author Matthew Wild <mwild1@gmail.com>
date Sat, 18 May 2013 15:31:14 +0100
parents
children
comparison
equal deleted inserted replaced
1013:8285c3502100 1014:ed7431fd3b47
1 local is_admin = require "core.usermanager".is_admin;
2 local t_remove = table.remove;
3
4 local restricted_options = module:get_option_set("muc_config_restricted", {})._items;
5
6 function handle_config_submit(event)
7 local stanza = event.stanza;
8 if is_admin(stanza.attr.from, module.host) then return; end -- Don't restrict admins
9 local fields = event.fields;
10 for option in restricted_options do
11 fields[option] = nil; -- Like it was never there
12 end
13 end
14
15 function handle_config_request(event)
16 if is_admin(event.actor, module.host) then return; end -- Don't restrict admins
17 local form = event.form;
18 for i = #form, 1, -1 do
19 if restricted_options[form[i].name] then
20 t_remove(form, i);
21 end
22 end
23 end
24
25 module:hook("muc-config-submitted", handle_config_submit);
26 module:hook("muc-config-form", handle_config_request);