MUC: Fire an event to allow affecting decision of whether to allow a role change
authorKim Alvefur <zash@zash.se>
Sun, 24 Feb 2019 16:30:11 +0100
changeset 9835 43f81e85cec2
parent 9834 d935a0f0de24
child 9838 a657df70cc31
MUC: Fire an event to allow affecting decision of whether to allow a role change
plugins/muc/muc.lib.lua
--- a/plugins/muc/muc.lib.lua	Sun Feb 24 16:18:30 2019 +0100
+++ b/plugins/muc/muc.lib.lua	Sun Feb 24 16:30:11 2019 +0100
@@ -1369,6 +1369,18 @@
 end
 
 function room_mt:may_set_role(actor, occupant, role)
+	local event = {
+		room = self,
+		actor = actor,
+		occupant = occupant,
+		role = role,
+	};
+
+	module:fire_event("muc-pre-set-role", event);
+	if event.allowed ~= nil then
+		return event.allowed, event.error, event.condition;
+	end
+
 	-- Can't do anything to other owners or admins
 	local occupant_affiliation = self:get_affiliation(occupant.bare_jid);
 	if occupant_affiliation == "owner" or occupant_affiliation == "admin" then