Mercurial > prosody-hg
comparison plugins/muc/hidden.lib.lua @ 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 | 173c0e16e704 |
| children | 9061f9621330 |
comparison
equal
deleted
inserted
replaced
| 9052:5017e43ccc39 | 9053:ea9e1f8f3013 |
|---|---|
| 4 -- Copyright (C) 2014 Daurnimator | 4 -- Copyright (C) 2014 Daurnimator |
| 5 -- | 5 -- |
| 6 -- This project is MIT/X11 licensed. Please see the | 6 -- This project is MIT/X11 licensed. Please see the |
| 7 -- COPYING file in the source package for more information. | 7 -- COPYING file in the source package for more information. |
| 8 -- | 8 -- |
| 9 | |
| 10 local restrict_public = not module:get_option_boolean("muc_room_allow_public", true); | |
| 11 local um_is_admin = require "core.usermanager".is_admin; | |
| 9 | 12 |
| 10 local function get_hidden(room) | 13 local function get_hidden(room) |
| 11 return room._data.hidden; | 14 return room._data.hidden; |
| 12 end | 15 end |
| 13 | 16 |
| 17 room._data.hidden = hidden; | 20 room._data.hidden = hidden; |
| 18 return true; | 21 return true; |
| 19 end | 22 end |
| 20 | 23 |
| 21 module:hook("muc-config-form", function(event) | 24 module:hook("muc-config-form", function(event) |
| 25 if restrict_public and not um_is_admin(event.actor, module.host) then | |
| 26 -- Don't show option if public rooms are restricted and user is not admin of this host | |
| 27 return; | |
| 28 end | |
| 22 table.insert(event.form, { | 29 table.insert(event.form, { |
| 23 name = "muc#roomconfig_publicroom"; | 30 name = "muc#roomconfig_publicroom"; |
| 24 type = "boolean"; | 31 type = "boolean"; |
| 25 label = "Include room information in public lists"; | 32 label = "Include room information in public lists"; |
| 26 desc = "Enable this to allow people to find the room"; | 33 desc = "Enable this to allow people to find the room"; |
| 27 value = not get_hidden(event.room); | 34 value = not get_hidden(event.room); |
| 28 }); | 35 }); |
| 29 end, 100-9); | 36 end, 100-9); |
| 30 | 37 |
| 31 module:hook("muc-config-submitted/muc#roomconfig_publicroom", function(event) | 38 module:hook("muc-config-submitted/muc#roomconfig_publicroom", function(event) |
| 39 if restrict_public and not um_is_admin(event.actor, module.host) then | |
| 40 return; -- Not allowed | |
| 41 end | |
| 32 if set_hidden(event.room, not event.value) then | 42 if set_hidden(event.room, not event.value) then |
| 33 event.status_codes["104"] = true; | 43 event.status_codes["104"] = true; |
| 34 end | 44 end |
| 35 end); | 45 end); |
| 36 | 46 |
