Mercurial > prosody-hg
comparison plugins/muc/restrict_pm.lib.lua @ 13888:0dd82a8f1913 13.0 13.0.2
MUC: Ensure allow MUC PM setting has valid value (fixes #1933)
In case allow PM is set to "affiliated" or something other than a valid
role name, but the user is not affiliated, the valid_roles lookup would
return nil, triggering a comparison error.
This ensures that the setting is validated going in and out of the
database and that the "affiliated" case proceeds correctly.
Also adds a compat mapping for the value "anyone", used in XEP-0045 and
submitted by default by Gajim.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 25 May 2025 15:36:17 +0200 |
| parents | 5fb7b9a9346f |
| children |
comparison
equal
deleted
inserted
replaced
| 13886:cbb8dc92daa9 | 13888:0dd82a8f1913 |
|---|---|
| 9 local compat_map = { | 9 local compat_map = { |
| 10 everyone = "visitor"; | 10 everyone = "visitor"; |
| 11 participants = "participant"; | 11 participants = "participant"; |
| 12 moderators = "moderator"; | 12 moderators = "moderator"; |
| 13 members = "affiliated"; | 13 members = "affiliated"; |
| 14 anyone = "visitor"; | |
| 14 }; | 15 }; |
| 15 | 16 |
| 16 local function get_allow_pm(room) | 17 local function get_allow_pm(room) |
| 17 local val = room._data.allow_pm; | 18 local val = room._data.allow_pm; |
| 18 return compat_map[val] or val or "visitor"; | 19 val = compat_map[val] or val or "visitor"; |
| 20 if not (val == "affiliated" or valid_roles[val]) then return "visitor"; end | |
| 21 return val; | |
| 19 end | 22 end |
| 20 | 23 |
| 21 local function set_allow_pm(room, val) | 24 local function set_allow_pm(room, val) |
| 22 if get_allow_pm(room) == val then return false; end | 25 if get_allow_pm(room) == val then return false; end |
| 26 if not (val == "affiliated" or valid_roles[val]) then return false end | |
| 23 room._data.allow_pm = val; | 27 room._data.allow_pm = val; |
| 24 return true; | 28 return true; |
| 25 end | 29 end |
| 26 | 30 |
| 27 local function get_allow_modpm(room) | 31 local function get_allow_modpm(room) |
| 91 end | 95 end |
| 92 | 96 |
| 93 local pmval = get_allow_pm(room); | 97 local pmval = get_allow_pm(room); |
| 94 | 98 |
| 95 if pmval ~= "none" then | 99 if pmval ~= "none" then |
| 96 if pmval == "affiliated" and room:get_affiliation(from_occupant.bare_jid) then | 100 if pmval == "affiliated" then |
| 97 return; -- Allow from affiliated users | 101 if room:get_affiliation(from_occupant.bare_jid) then |
| 102 return; -- Allow from affiliated users | |
| 103 end | |
| 98 elseif valid_roles[from_occupant.role] >= valid_roles[pmval] then | 104 elseif valid_roles[from_occupant.role] >= valid_roles[pmval] then |
| 99 module:log("debug", "Allowing PM: %s(%d) >= %s(%d)", from_occupant.role, valid_roles[from_occupant.role], pmval, valid_roles[pmval]); | 105 module:log("debug", "Allowing PM: %s(%d) >= %s(%d)", from_occupant.role, valid_roles[from_occupant.role], pmval, valid_roles[pmval]); |
| 100 return; -- Allow from a permitted role | 106 return; -- Allow from a permitted role |
| 101 end | 107 end |
| 102 end | 108 end |
