Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 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 |
parent | 4201:9a8d2baf7a9c |
child | 4266:513485a11b85 |
comparison
equal
deleted
inserted
replaced
4201:9a8d2baf7a9c | 4202:dff7df4a191b |
---|---|
927 jid = jid_bare(jid); | 927 jid = jid_bare(jid); |
928 if affiliation == "none" then affiliation = nil; end | 928 if affiliation == "none" then affiliation = nil; end |
929 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then | 929 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then |
930 return nil, "modify", "not-acceptable"; | 930 return nil, "modify", "not-acceptable"; |
931 end | 931 end |
932 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end | 932 local actor_affiliation = self:get_affiliation(actor); |
933 if jid_bare(actor) == jid then return nil, "cancel", "not-allowed"; end | 933 local target_affiliation = self:get_affiliation(jid); |
934 if target_affiliation == affiliation then -- no change, shortcut | |
935 if callback then callback(); end | |
936 return true; | |
937 end | |
938 if actor_affiliation ~= "owner" then | |
939 if actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then | |
940 return nil, "cancel", "not-allowed"; | |
941 end | |
942 elseif target_affiliation == "owner" and jid_bare(actor) == jid then -- self change | |
943 local is_last = true; | |
944 for j, aff in pairs(self._affiliations) do if j ~= jid and aff == "owner" then is_last = false; break; end end | |
945 if is_last then | |
946 return nil, "cancel", "conflict"; | |
947 end | |
948 end | |
934 self._affiliations[jid] = affiliation; | 949 self._affiliations[jid] = affiliation; |
935 local role = self:get_default_role(affiliation); | 950 local role = self:get_default_role(affiliation); |
936 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) | 951 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
937 :tag("item", {affiliation=affiliation or "none", role=role or "none"}) | 952 :tag("item", {affiliation=affiliation or "none", role=role or "none"}) |
938 :tag("reason"):text(reason or ""):up() | 953 :tag("reason"):text(reason or ""):up() |