Mercurial > prosody-hg
comparison plugins/muc/muc.lib.lua @ 13415:f34b33cb1383
MUC: Record reason for affiliation changes and return in list (fixes #1227)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 08 Aug 2021 18:07:17 +0200 |
| parents | 74b9e05af71e |
| children | ccf389f54a93 |
comparison
equal
deleted
inserted
replaced
| 13414:d54364746a7c | 13415:f34b33cb1383 |
|---|---|
| 1077 end | 1077 end |
| 1078 local actor = stanza.attr.from; | 1078 local actor = stanza.attr.from; |
| 1079 local reason = item:get_child_text("reason"); | 1079 local reason = item:get_child_text("reason"); |
| 1080 local success, errtype, err | 1080 local success, errtype, err |
| 1081 if item.attr.affiliation and item.attr.jid and not item.attr.role then | 1081 if item.attr.affiliation and item.attr.jid and not item.attr.role then |
| 1082 local registration_data; | 1082 local registration_data = self:get_affiliation_data(item.attr.jid) or {}; |
| 1083 if reason then | |
| 1084 registration_data.reason = reason; | |
| 1085 end | |
| 1083 if item.attr.nick then | 1086 if item.attr.nick then |
| 1084 local room_nick = self.jid.."/"..item.attr.nick; | 1087 local room_nick = self.jid.."/"..item.attr.nick; |
| 1085 local existing_occupant = self:get_occupant_by_nick(room_nick); | 1088 local existing_occupant = self:get_occupant_by_nick(room_nick); |
| 1086 if existing_occupant and existing_occupant.bare_jid ~= item.attr.jid then | 1089 if existing_occupant and existing_occupant.bare_jid ~= item.attr.jid then |
| 1087 module:log("debug", "Existing occupant for %s: %s does not match %s", room_nick, existing_occupant.bare_jid, item.attr.jid); | 1090 module:log("debug", "Existing occupant for %s: %s does not match %s", room_nick, existing_occupant.bare_jid, item.attr.jid); |
| 1088 self:set_role(true, room_nick, nil, "This nickname is reserved"); | 1091 self:set_role(true, room_nick, nil, "This nickname is reserved"); |
| 1089 end | 1092 end |
| 1090 module:log("debug", "Reserving %s for %s (%s)", item.attr.nick, item.attr.jid, item.attr.affiliation); | 1093 module:log("debug", "Reserving %s for %s (%s)", item.attr.nick, item.attr.jid, item.attr.affiliation); |
| 1091 registration_data = { reserved_nickname = item.attr.nick }; | 1094 registration_data.reserved_nickname = item.attr.nick; |
| 1092 end | 1095 end |
| 1093 success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, reason, registration_data); | 1096 success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, reason, registration_data); |
| 1094 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then | 1097 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then |
| 1095 success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, reason); | 1098 success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, reason); |
| 1096 else | 1099 else |
| 1117 -- e.g. an admin can't ask for a list of owners | 1120 -- e.g. an admin can't ask for a list of owners |
| 1118 local affiliation_rank = valid_affiliations[affiliation or "none"]; | 1121 local affiliation_rank = valid_affiliations[affiliation or "none"]; |
| 1119 if (affiliation_rank >= valid_affiliations.admin and affiliation_rank >= _aff_rank) | 1122 if (affiliation_rank >= valid_affiliations.admin and affiliation_rank >= _aff_rank) |
| 1120 or (self:get_members_only() and self:get_whois() == "anyone" and affiliation_rank >= valid_affiliations.member) then | 1123 or (self:get_members_only() and self:get_whois() == "anyone" and affiliation_rank >= valid_affiliations.member) then |
| 1121 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); | 1124 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); |
| 1122 for jid in self:each_affiliation(_aff or "none") do | 1125 for jid, _, data in self:each_affiliation(_aff or "none") do |
| 1123 local nick = self:get_registered_nick(jid); | 1126 local nick = self:get_registered_nick(jid); |
| 1124 reply:tag("item", {affiliation = _aff, jid = jid, nick = nick }):up(); | 1127 reply:tag("item", {affiliation = _aff, jid = jid, nick = nick }); |
| 1128 if data and data.reason then | |
| 1129 reply:text_tag("reason", data.reason); | |
| 1130 end | |
| 1131 reply:up(); | |
| 1125 end | 1132 end |
| 1126 origin.send(reply:up()); | 1133 origin.send(reply:up()); |
| 1127 return true; | 1134 return true; |
| 1128 else | 1135 else |
| 1129 origin.send(st.error_reply(stanza, "auth", "forbidden")); | 1136 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
