# HG changeset patch
# User Matthew Wild <mwild1@gmail.com>
# Date 1648161014 0
# Node ID cf922f34e2645e5f93b4eaca5471a00842a3babf
# Parent  60eecdd9c65bac213f5013dc8e2202217df58dec# Parent  3dfcdcab5446abb4002955880ad02162a4b900fb
Merge 0.12->trunk

diff -r 60eecdd9c65b -r cf922f34e264 plugins/muc/muc.lib.lua
--- a/plugins/muc/muc.lib.lua	Wed Mar 23 16:25:37 2022 +0100
+++ b/plugins/muc/muc.lib.lua	Thu Mar 24 22:30:14 2022 +0000
@@ -1583,15 +1583,16 @@
 		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
+	local actor_affiliation = self:get_affiliation(actor) or "none";
+	local occupant_affiliation = self:get_affiliation(occupant.bare_jid) or "none";
+
+	-- Can't do anything to someone with higher affiliation
+	if valid_affiliations[actor_affiliation] < valid_affiliations[occupant_affiliation] then
 		return nil, "cancel", "not-allowed";
 	end
 
 	-- If you are trying to give or take moderator role you need to be an owner or admin
 	if occupant.role == "moderator" or role == "moderator" then
-		local actor_affiliation = self:get_affiliation(actor);
 		if actor_affiliation ~= "owner" and actor_affiliation ~= "admin" then
 			return nil, "cancel", "not-allowed";
 		end