Software /
code /
prosody
Changeset
6243:b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Tue, 29 Apr 2014 19:00:45 -0400 |
parents | 6242:67efeadd9e77 |
children | 6244:dfaacf042cfe |
files | plugins/muc/mod_muc.lua |
diffstat | 1 files changed, 21 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/muc/mod_muc.lua Tue Apr 29 18:50:30 2014 -0400 +++ b/plugins/muc/mod_muc.lua Tue Apr 29 19:00:45 2014 -0400 @@ -12,15 +12,6 @@ error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0); end -local restrict_room_creation = module:get_option("restrict_room_creation"); -if restrict_room_creation then - if restrict_room_creation == true then - restrict_room_creation = "admin"; - elseif restrict_room_creation ~= "admin" and restrict_room_creation ~= "local" then - restrict_room_creation = nil; - end -end - local muclib = module:require "muc"; local muc_new_room = muclib.new_room; room_mt = muclib.room_mt; -- Yes, global. @@ -146,20 +137,31 @@ forget_room(room.jid) end) +do + local restrict_room_creation = module:get_option("restrict_room_creation"); + if restrict_room_creation == true then + restrict_room_creation = "admin"; + end + if restrict_room_creation then + local host_suffix = module.host:gsub("^[^%.]+%.", ""); + module:hook("muc-room-pre-create", function(event) + local user_jid = event.stanza.attr.from; + if not is_admin(user_jid) and not ( + restrict_room_creation == "local" and + select(2, jid_split(user_jid)) == host_suffix + ) then + origin.send(st.error_reply(stanza, "cancel", "not-allowed")); + return true; + end + end); + end +end + -- Watch presence to create rooms local function attempt_room_creation(event) local origin, stanza = event.origin, event.stanza; local room_jid = jid_bare(stanza.attr.to); - if stanza.attr.type == nil and - get_room_from_jid(room_jid) == nil and - ( - not(restrict_room_creation) or - is_admin(stanza.attr.from) or - ( - restrict_room_creation == "local" and - select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "") - ) - ) then + if stanza.attr.type == nil and get_room_from_jid(room_jid) == nil then create_room(room_jid); end end