Mercurial > prosody-modules
comparison mod_muc_moderation/mod_muc_moderation.lua @ 5170:4d6af8950016
mod_muc_moderation: Derive role from reserved nickname if occupant
When using a different client to moderate than the one used to
participate in the chat, e.g. a command line tool like clix, there's no
occupant and no role to use in the permission check. Previously the
default role based on affiliation was used. Now if you are present in
the room using your reserved nick, the role you have there is used in
the permission check instead of the default affiliation-derived role.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 19 Feb 2023 18:17:37 +0100 |
parents | 1071a420ff6f |
children | 06fad22672e1 |
comparison
equal
deleted
inserted
replaced
5169:1071a420ff6f | 5170:4d6af8950016 |
---|---|
39 -- moderate : function (string, string, string, boolean, string) : boolean, enum, enum, string | 39 -- moderate : function (string, string, string, boolean, string) : boolean, enum, enum, string |
40 local function moderate(actor, room_jid, stanza_id, retract, reason) | 40 local function moderate(actor, room_jid, stanza_id, retract, reason) |
41 local room_node = jid.split(room_jid); | 41 local room_node = jid.split(room_jid); |
42 local room = mod_muc.get_room_from_jid(room_jid); | 42 local room = mod_muc.get_room_from_jid(room_jid); |
43 | 43 |
44 -- Permissions | 44 -- Permissions is based on role, which is a property of a current occupant, |
45 -- so check if the actor is an occupant, otherwise if they have a reserved | |
46 -- nickname that can be used to retrieve the role. | |
45 local actor_nick = room:get_occupant_jid(actor); | 47 local actor_nick = room:get_occupant_jid(actor); |
46 local affiliation = room:get_affiliation(actor); | |
47 -- Retrieve their current role, iff they are in the room, otherwise what they | |
48 -- would have based on affiliation. | |
49 local role = room:get_role(actor_nick) or room:get_default_role(affiliation); | |
50 if valid_roles[role or "none"] < valid_roles.moderator then | |
51 return false, "auth", "forbidden", "You need a role of at least 'moderator'"; | |
52 end | |
53 | |
54 if not actor_nick then | 48 if not actor_nick then |
55 local reserved_nickname = room:get_affiliation_data(jid.bare(actor), "reserved_nickname"); | 49 local reserved_nickname = room:get_affiliation_data(jid.bare(actor), "reserved_nickname"); |
56 if reserved_nickname then | 50 if reserved_nickname then |
57 actor_nick = room.jid .. "/" .. reserved_nickname; | 51 actor_nick = room.jid .. "/" .. reserved_nickname; |
58 end | 52 end |
53 end | |
54 | |
55 -- Retrieve their current role, iff they are in the room, otherwise what they | |
56 -- would have based on affiliation. | |
57 local affiliation = room:get_affiliation(actor); | |
58 local role = room:get_role(actor_nick) or room:get_default_role(affiliation); | |
59 if valid_roles[role or "none"] < valid_roles.moderator then | |
60 return false, "auth", "forbidden", "You need a role of at least 'moderator'"; | |
59 end | 61 end |
60 | 62 |
61 -- Original stanza to base tombstone on | 63 -- Original stanza to base tombstone on |
62 local original, err; | 64 local original, err; |
63 if muc_log_archive.get then | 65 if muc_log_archive.get then |