Comparison

plugins/muc/muc.lib.lua @ 9263:4285d1efaf03

MUC: Allow admins to include a registered nick when setting affiliation This is defined by XEP-0045 section 9.3 "Granting Membership"
author Matthew Wild <mwild1@gmail.com>
date Tue, 04 Sep 2018 11:59:17 +0100
parent 9239:03e37f7d6c97
child 9264:f13517b63e6c
comparison
equal deleted inserted replaced
9262:37b7cf3470f1 9263:4285d1efaf03
17 local jid_split = require "util.jid".split; 17 local jid_split = require "util.jid".split;
18 local jid_bare = require "util.jid".bare; 18 local jid_bare = require "util.jid".bare;
19 local jid_prep = require "util.jid".prep; 19 local jid_prep = require "util.jid".prep;
20 local jid_join = require "util.jid".join; 20 local jid_join = require "util.jid".join;
21 local jid_resource = require "util.jid".resource; 21 local jid_resource = require "util.jid".resource;
22 local resourceprep = require "util.encodings".stringprep.resourceprep;
22 local st = require "util.stanza"; 23 local st = require "util.stanza";
23 local base64 = require "util.encodings".base64; 24 local base64 = require "util.encodings".base64;
24 local md5 = require "util.hashes".md5; 25 local md5 = require "util.hashes".md5;
25 26
26 local log = module._log; 27 local log = module._log;
904 if not item.attr.jid then 905 if not item.attr.jid then
905 origin.send(st.error_reply(stanza, "modify", "jid-malformed")); 906 origin.send(st.error_reply(stanza, "modify", "jid-malformed"));
906 return true; 907 return true;
907 end 908 end
908 end 909 end
910 if item.attr.nick then -- Validate provided nick
911 item.attr.nick = resourceprep(item.attr.nick);
912 if not item.attr.nick then
913 origin.send(st.error_reply(stanza, "modify", "jid-malformed", "invalid nickname"));
914 return true;
915 end
916 end
909 if not item.attr.jid and item.attr.nick then 917 if not item.attr.jid and item.attr.nick then
910 -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation 918 -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation
911 local occupant = self:get_occupant_by_nick(self.jid.."/"..item.attr.nick); 919 local occupant = self:get_occupant_by_nick(self.jid.."/"..item.attr.nick);
912 if occupant then item.attr.jid = occupant.jid; end 920 if occupant then item.attr.jid = occupant.jid; end
913 elseif not item.attr.nick and item.attr.jid then 921 elseif item.attr.role and not item.attr.nick and item.attr.jid then
922 -- Role changes should use nick, but we have a JID so pull the nick from that
914 local nick = self:get_occupant_jid(item.attr.jid); 923 local nick = self:get_occupant_jid(item.attr.jid);
915 if nick then item.attr.nick = jid_resource(nick); end 924 if nick then item.attr.nick = jid_resource(nick); end
916 end 925 end
917 local actor = stanza.attr.from; 926 local actor = stanza.attr.from;
918 local reason = item:get_child_text("reason"); 927 local reason = item:get_child_text("reason");
919 local success, errtype, err 928 local success, errtype, err
920 if item.attr.affiliation and item.attr.jid and not item.attr.role then 929 if item.attr.affiliation and item.attr.jid and not item.attr.role then
921 success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, reason); 930 local registration_data;
931 if item.attr.nick then
932 local room_nick = self.jid.."/"..item.attr.nick;
933 if self:get_occupant_by_nick(room_nick) then
934 self:set_role(true, room_nick, nil, "This nickname is reserved");
935 end
936 registration_data = { reserved_nickname = item.attr.nick };
937 end
938 success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, reason, registration_data);
922 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then 939 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then
923 success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, reason); 940 success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, reason);
924 else 941 else
925 success, errtype, err = nil, "cancel", "bad-request"; 942 success, errtype, err = nil, "cancel", "bad-request";
926 end 943 end