Comparison

plugins/muc/muc.lib.lua @ 12433:3dfcdcab5446 0.12

MUC: Allow kicking users with the same affiliation as the kicker (fixes #1724) This is allowed by XEP-0045, which states: "A moderator SHOULD NOT be allowed to revoke moderation privileges from someone with a higher affiliation than themselves (i.e., an unaffiliated moderator SHOULD NOT be allowed to revoke moderation privileges from an admin or an owner, and an admin SHOULD NOT be allowed to revoke moderation privileges from an owner)."
author Matthew Wild <mwild1@gmail.com>
date Wed, 23 Mar 2022 13:38:55 +0000
parent 12109:83bec90a352c
child 12977:74b9e05af71e
comparison
equal deleted inserted replaced
12431:95f33a006c03 12433:3dfcdcab5446
1581 module:fire_event("muc-pre-set-role", event); 1581 module:fire_event("muc-pre-set-role", event);
1582 if event.allowed ~= nil then 1582 if event.allowed ~= nil then
1583 return event.allowed, event.error, event.condition; 1583 return event.allowed, event.error, event.condition;
1584 end 1584 end
1585 1585
1586 -- Can't do anything to other owners or admins 1586 local actor_affiliation = self:get_affiliation(actor) or "none";
1587 local occupant_affiliation = self:get_affiliation(occupant.bare_jid); 1587 local occupant_affiliation = self:get_affiliation(occupant.bare_jid) or "none";
1588 if occupant_affiliation == "owner" or occupant_affiliation == "admin" then 1588
1589 -- Can't do anything to someone with higher affiliation
1590 if valid_affiliations[actor_affiliation] < valid_affiliations[occupant_affiliation] then
1589 return nil, "cancel", "not-allowed"; 1591 return nil, "cancel", "not-allowed";
1590 end 1592 end
1591 1593
1592 -- If you are trying to give or take moderator role you need to be an owner or admin 1594 -- If you are trying to give or take moderator role you need to be an owner or admin
1593 if occupant.role == "moderator" or role == "moderator" then 1595 if occupant.role == "moderator" or role == "moderator" then
1594 local actor_affiliation = self:get_affiliation(actor);
1595 if actor_affiliation ~= "owner" and actor_affiliation ~= "admin" then 1596 if actor_affiliation ~= "owner" and actor_affiliation ~= "admin" then
1596 return nil, "cancel", "not-allowed"; 1597 return nil, "cancel", "not-allowed";
1597 end 1598 end
1598 end 1599 end
1599 1600