Software /
code /
prosody
Changeset
4202:dff7df4a191b
MUC: Don't limit affiliation changes to owners, and allow owners to remove themselves if they are not the last owner.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 24 Feb 2011 07:11:35 +0500 |
parents | 4201:9a8d2baf7a9c |
children | 4203:e3d937eec3fa 4205:ffa5384130a7 |
files | plugins/muc/muc.lib.lua |
diffstat | 1 files changed, 17 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua Thu Feb 24 07:09:38 2011 +0500 +++ b/plugins/muc/muc.lib.lua Thu Feb 24 07:11:35 2011 +0500 @@ -929,8 +929,23 @@ if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then return nil, "modify", "not-acceptable"; end - if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end - if jid_bare(actor) == jid then return nil, "cancel", "not-allowed"; end + local actor_affiliation = self:get_affiliation(actor); + local target_affiliation = self:get_affiliation(jid); + if target_affiliation == affiliation then -- no change, shortcut + if callback then callback(); end + return true; + end + if actor_affiliation ~= "owner" then + if actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then + return nil, "cancel", "not-allowed"; + end + elseif target_affiliation == "owner" and jid_bare(actor) == jid then -- self change + local is_last = true; + for j, aff in pairs(self._affiliations) do if j ~= jid and aff == "owner" then is_last = false; break; end end + if is_last then + return nil, "cancel", "conflict"; + end + end self._affiliations[jid] = affiliation; local role = self:get_default_role(affiliation); local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"})