Software /
code /
prosody
Changeset
9053:ea9e1f8f3013
MUC: Allow restricting public/persistent room options to service admins (muc_room_allow_public/muc_room_allow_persistent)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 11:57:28 +0100 |
parents | 9052:5017e43ccc39 |
children | 9054:0bf0ff3b0f91 |
files | plugins/muc/hidden.lib.lua plugins/muc/persistent.lib.lua |
diffstat | 2 files changed, 20 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/muc/hidden.lib.lua Tue Jul 17 11:54:02 2018 +0100 +++ b/plugins/muc/hidden.lib.lua Tue Jul 17 11:57:28 2018 +0100 @@ -7,6 +7,9 @@ -- COPYING file in the source package for more information. -- +local restrict_public = not module:get_option_boolean("muc_room_allow_public", true); +local um_is_admin = require "core.usermanager".is_admin; + local function get_hidden(room) return room._data.hidden; end @@ -19,6 +22,10 @@ end module:hook("muc-config-form", function(event) + if restrict_public and not um_is_admin(event.actor, module.host) then + -- Don't show option if public rooms are restricted and user is not admin of this host + return; + end table.insert(event.form, { name = "muc#roomconfig_publicroom"; type = "boolean"; @@ -29,6 +36,9 @@ end, 100-9); module:hook("muc-config-submitted/muc#roomconfig_publicroom", function(event) + if restrict_public and not um_is_admin(event.actor, module.host) then + return; -- Not allowed + end if set_hidden(event.room, not event.value) then event.status_codes["104"] = true; end
--- a/plugins/muc/persistent.lib.lua Tue Jul 17 11:54:02 2018 +0100 +++ b/plugins/muc/persistent.lib.lua Tue Jul 17 11:57:28 2018 +0100 @@ -7,6 +7,9 @@ -- COPYING file in the source package for more information. -- +local restrict_persistent = not module:get_option_boolean("muc_room_allow_persistent", true); +local um_is_admin = require "core.usermanager".is_admin; + local function get_persistent(room) return room._data.persistent; end @@ -19,6 +22,10 @@ end module:hook("muc-config-form", function(event) + if restrict_persistent and not um_is_admin(event.actor, module.host) then + -- Don't show option if hidden rooms are restricted and user is not admin of this host + return; + end table.insert(event.form, { name = "muc#roomconfig_persistentroom"; type = "boolean"; @@ -29,6 +36,9 @@ end, 100-5); module:hook("muc-config-submitted/muc#roomconfig_persistentroom", function(event) + if restrict_persistent and not um_is_admin(event.actor, module.host) then + return; -- Not allowed + end if set_persistent(event.room, event.value) then event.status_codes["104"] = true; end