# HG changeset patch # User Matthew Wild # Date 1368887474 -3600 # Node ID ed7431fd3b47100ce9744412877ae0d8775a78bd # Parent 8285c35021004b92d92d832237328361281f0005 mod_muc_config_restrict: Allow restricting specific options in the MUC config form to service admins diff -r 8285c3502100 -r ed7431fd3b47 mod_muc_config_restrict/mod_muc_config_restrict.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_muc_config_restrict/mod_muc_config_restrict.lua Sat May 18 15:31:14 2013 +0100 @@ -0,0 +1,26 @@ +local is_admin = require "core.usermanager".is_admin; +local t_remove = table.remove; + +local restricted_options = module:get_option_set("muc_config_restricted", {})._items; + +function handle_config_submit(event) + local stanza = event.stanza; + if is_admin(stanza.attr.from, module.host) then return; end -- Don't restrict admins + local fields = event.fields; + for option in restricted_options do + fields[option] = nil; -- Like it was never there + end +end + +function handle_config_request(event) + if is_admin(event.actor, module.host) then return; end -- Don't restrict admins + local form = event.form; + for i = #form, 1, -1 do + if restricted_options[form[i].name] then + t_remove(form, i); + end + end +end + +module:hook("muc-config-submitted", handle_config_submit); +module:hook("muc-config-form", handle_config_request);