Comparison

plugins/muc/muc.lib.lua @ 6195:9f6a003baf2e

plugins/muc/muc.lib: Add pre-invite event. Move role check to it
author daurnimator <quae@daurnimator.com>
date Mon, 31 Mar 2014 13:54:27 -0400
parent 6194:9b6c2d89f143
child 6196:e73bb1568d87
comparison
equal deleted inserted replaced
6194:9b6c2d89f143 6195:9f6a003baf2e
1190 stanza.attr.to = to; 1190 stanza.attr.to = to;
1191 end 1191 end
1192 return handled; 1192 return handled;
1193 end 1193 end
1194 1194
1195 -- Need visitor role or higher to invite
1196 module:hook("muc-pre-invite", function(event)
1197 local room, stanza = event.room, event.stanza;
1198 local _from, _to = stanza.attr.from, stanza.attr.to;
1199 local inviter = room:get_occupant_by_real_jid(_from);
1200 local role = inviter and inviter.role or room:get_default_role(room:get_affiliation(_from));
1201 if valid_roles[role or "none"] <= valid_roles.visitor then
1202 event.origin.send(st.error_reply(stanza, "auth", "forbidden"));
1203 return true;
1204 end
1205 end);
1206
1195 function room_mt:handle_mediated_invite(origin, stanza) 1207 function room_mt:handle_mediated_invite(origin, stanza)
1196 local payload = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite") 1208 local payload = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite");
1197 local _from, _to = stanza.attr.from, stanza.attr.to; 1209 local invitee = jid_prep(payload.attr.to);
1198 local current_nick = self:get_occupant_jid(_from) 1210 if not invitee then
1199 -- Need visitor role or higher to invite
1200 if not self:get_role(current_nick) or not self:get_default_role(self:get_affiliation(_from)) then
1201 origin.send(st.error_reply(stanza, "auth", "forbidden"));
1202 return true;
1203 end
1204 local _invitee = jid_prep(payload.attr.to);
1205 if _invitee then
1206 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id})
1207 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
1208 :tag('invite', {from=_from})
1209 :tag('reason'):text(payload:get_child_text("reason")):up()
1210 :up()
1211 :up();
1212 if not module:fire_event("muc-invite", {room = self, stanza = invite, origin = origin, incoming = stanza}) then
1213 self:route_stanza(invite);
1214 end
1215 return true;
1216 else
1217 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); 1211 origin.send(st.error_reply(stanza, "cancel", "jid-malformed"));
1218 return true; 1212 return true;
1219 end 1213 elseif not module:fire_event("muc-pre-invite", {room = self, origin = origin, stanza = stanza}) then
1214 return true;
1215 end
1216 local invite = st.message({from = self.jid, to = invitee, id = stanza.attr.id})
1217 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
1218 :tag('invite', {from = stanza.attr.from;})
1219 :tag('reason'):text(payload:get_child_text("reason")):up()
1220 :up()
1221 :up();
1222 if not module:fire_event("muc-invite", {room = self, stanza = invite, origin = origin, incoming = stanza}) then
1223 self:route_stanza(invite);
1224 end
1225 return true;
1220 end 1226 end
1221 1227
1222 -- Add password to outgoing invite 1228 -- Add password to outgoing invite
1223 module:hook("muc-invite", function(event) 1229 module:hook("muc-invite", function(event)
1224 local password = event.room:get_password(); 1230 local password = event.room:get_password();