# HG changeset patch # User Kim Alvefur # Date 1628438837 -7200 # Node ID f34b33cb1383398cfdad74226f31cd673faee272 # Parent d54364746a7c590e64e1ac40a874489ad0ddca25 MUC: Record reason for affiliation changes and return in list (fixes #1227) diff -r d54364746a7c -r f34b33cb1383 CHANGES --- a/CHANGES Tue Jan 23 13:00:58 2024 +0100 +++ b/CHANGES Sun Aug 08 18:07:17 2021 +0200 @@ -24,6 +24,7 @@ - Public rooms can only be created by local users (parent host) by default - muc_room_allow_public = false restricts to admins - Commands to show occupants and affiliations in the Shell +- Save 'reason' text supplied with affiliation change ### Security and authentication diff -r d54364746a7c -r f34b33cb1383 plugins/muc/muc.lib.lua --- a/plugins/muc/muc.lib.lua Tue Jan 23 13:00:58 2024 +0100 +++ b/plugins/muc/muc.lib.lua Sun Aug 08 18:07:17 2021 +0200 @@ -1079,7 +1079,10 @@ local reason = item:get_child_text("reason"); local success, errtype, err if item.attr.affiliation and item.attr.jid and not item.attr.role then - local registration_data; + local registration_data = self:get_affiliation_data(item.attr.jid) or {}; + if reason then + registration_data.reason = reason; + end if item.attr.nick then local room_nick = self.jid.."/"..item.attr.nick; local existing_occupant = self:get_occupant_by_nick(room_nick); @@ -1088,7 +1091,7 @@ self:set_role(true, room_nick, nil, "This nickname is reserved"); end module:log("debug", "Reserving %s for %s (%s)", item.attr.nick, item.attr.jid, item.attr.affiliation); - registration_data = { reserved_nickname = item.attr.nick }; + registration_data.reserved_nickname = item.attr.nick; end success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, reason, registration_data); elseif item.attr.role and item.attr.nick and not item.attr.affiliation then @@ -1119,9 +1122,13 @@ if (affiliation_rank >= valid_affiliations.admin and affiliation_rank >= _aff_rank) or (self:get_members_only() and self:get_whois() == "anyone" and affiliation_rank >= valid_affiliations.member) then local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); - for jid in self:each_affiliation(_aff or "none") do + for jid, _, data in self:each_affiliation(_aff or "none") do local nick = self:get_registered_nick(jid); - reply:tag("item", {affiliation = _aff, jid = jid, nick = nick }):up(); + reply:tag("item", {affiliation = _aff, jid = jid, nick = nick }); + if data and data.reason then + reply:text_tag("reason", data.reason); + end + reply:up(); end origin.send(reply:up()); return true; diff -r d54364746a7c -r f34b33cb1383 spec/scansion/muc_outcast_reason.scs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/scansion/muc_outcast_reason.scs Sun Aug 08 18:07:17 2021 +0200 @@ -0,0 +1,72 @@ +# Save ban reason + +[Client] Romeo + password: password + jid: user@localhost + +----- + +Romeo connects + +Romeo sends: + + + + +Romeo receives: + + + + + + + + +Romeo receives: + + + + +Romeo sends: + + + + Hey calm down + + + + +Romeo receives: + + + + + Hey calm down + + + + +Romeo receives: + + +Romeo sends: + + + + + + +Romeo receives: + + + + Hey calm down + + + + +Romeo disconnects + +Romeo sends: + +