aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2014-03-28 14:15:18 -0400
committerdaurnimator <quae@daurnimator.com>2014-03-28 14:15:18 -0400
commitad1ec83264f36e03d2ae9a2292bc1aac6963350c (patch)
treed54d224b7bd37f08ea16498b2dc50dfb89dd9a5f
parenta30f58b1d31331c490bf65b1ad1e0af59b0af28a (diff)
downloadprosody-ad1ec83264f36e03d2ae9a2292bc1aac6963350c.tar.gz
prosody-ad1ec83264f36e03d2ae9a2292bc1aac6963350c.zip
plugins/muc/muc.lib: Smarter validation in set_affiliation
-rw-r--r--plugins/muc/muc.lib.lua16
1 files changed, 14 insertions, 2 deletions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 02a2dc37..d001800d 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -1311,12 +1311,24 @@ function room_mt:get_affiliation(jid)
if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned
return result;
end
+
+local valid_affiliations = {
+ outcast = true;
+ none = true;
+ member = true;
+ admin = true;
+ owner = true;
+};
function room_mt:set_affiliation(actor, jid, affiliation, reason)
+ if not actor then return nil, "modify", "not-acceptable"; end;
+
jid = jid_bare(jid);
- if affiliation == "none" then affiliation = nil; end
- if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then
+
+ if valid_affiliations[affiliation or "none"] == nil then
return nil, "modify", "not-acceptable";
end
+ affiliation = affiliation ~= "none" and affiliation or nil; -- coerces `affiliation == false` to `nil`
+
if actor ~= true then
local actor_affiliation = self:get_affiliation(actor);
local target_affiliation = self:get_affiliation(jid);