view mod_muc_config_restrict/mod_muc_config_restrict.lua @ 4326:f6fdefc5c6ac

mod_roster_command: Fix subscription when the "user JID" is a bare domain. Do not attempt to update the roster when the user is bare domain (e.g. a component), since they don't have rosters and the attempt results in an error: $ prosodyctl mod_roster_command subscribe proxy.example.com contact@example.com xxxxxxxxxxFailed to execute command: Error: /usr/lib/prosody/core/rostermanager.lua:104: attempt to concatenate local 'username' (a nil value) stack traceback: /usr/lib/prosody/core/rostermanager.lua:104: in function 'load_roster' /usr/lib/prosody/core/rostermanager.lua:305: in function 'set_contact_pending_out' mod_roster_command.lua:44: in function 'subscribe'
author Boris Grozev <boris@jitsi.org>
date Tue, 05 Jan 2021 13:15:00 -0600
parents ed7431fd3b47
children
line wrap: on
line source

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);