Software /
code /
prosody
Comparison
plugins/muc/persistent.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 |
parent | 9035:173c0e16e704 |
child | 12642: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_persistent = not module:get_option_boolean("muc_room_allow_persistent", true); | |
11 local um_is_admin = require "core.usermanager".is_admin; | |
9 | 12 |
10 local function get_persistent(room) | 13 local function get_persistent(room) |
11 return room._data.persistent; | 14 return room._data.persistent; |
12 end | 15 end |
13 | 16 |
17 room._data.persistent = persistent; | 20 room._data.persistent = persistent; |
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_persistent and not um_is_admin(event.actor, module.host) then | |
26 -- Don't show option if hidden 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_persistentroom"; | 30 name = "muc#roomconfig_persistentroom"; |
24 type = "boolean"; | 31 type = "boolean"; |
25 label = "Persistent (room should remain even when it is empty)"; | 32 label = "Persistent (room should remain even when it is empty)"; |
26 desc = "Rooms are automatically deleted when they are empty, unless this option is enabled"; | 33 desc = "Rooms are automatically deleted when they are empty, unless this option is enabled"; |
27 value = get_persistent(event.room); | 34 value = get_persistent(event.room); |
28 }); | 35 }); |
29 end, 100-5); | 36 end, 100-5); |
30 | 37 |
31 module:hook("muc-config-submitted/muc#roomconfig_persistentroom", function(event) | 38 module:hook("muc-config-submitted/muc#roomconfig_persistentroom", function(event) |
39 if restrict_persistent and not um_is_admin(event.actor, module.host) then | |
40 return; -- Not allowed | |
41 end | |
32 if set_persistent(event.room, event.value) then | 42 if set_persistent(event.room, 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 |