Mercurial > prosody-hg
comparison plugins/muc/persistent.lib.lua @ 12674:72f431b4dc2c
Merge role-auth->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 22 Aug 2022 13:53:35 +0100 |
| parents | 9061f9621330 |
| children | 73a45ba6e3f1 |
comparison
equal
deleted
inserted
replaced
| 12639:6d9ee0a3eb4b | 12674:72f431b4dc2c |
|---|---|
| 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 | 9 |
| 10 local restrict_persistent = not module:get_option_boolean("muc_room_allow_persistent", true); | 10 local restrict_persistent = not module:get_option_boolean("muc_room_allow_persistent", true); |
| 11 local um_is_admin = require "core.usermanager".is_admin; | 11 module:default_permission( |
| 12 restrict_persistent and "prosody:admin" or "prosody:user", | |
| 13 ":create-persistent-room" | |
| 14 ); | |
| 12 | 15 |
| 13 local function get_persistent(room) | 16 local function get_persistent(room) |
| 14 return room._data.persistent; | 17 return room._data.persistent; |
| 15 end | 18 end |
| 16 | 19 |
| 20 room._data.persistent = persistent; | 23 room._data.persistent = persistent; |
| 21 return true; | 24 return true; |
| 22 end | 25 end |
| 23 | 26 |
| 24 module:hook("muc-config-form", function(event) | 27 module:hook("muc-config-form", function(event) |
| 25 if restrict_persistent and not um_is_admin(event.actor, module.host) then | 28 if not module:may(":create-persistent-room", event.actor) then |
| 26 -- Don't show option if hidden rooms are restricted and user is not admin of this host | 29 -- Hide config option if this user is not allowed to create persistent rooms |
| 27 return; | 30 return; |
| 28 end | 31 end |
| 29 table.insert(event.form, { | 32 table.insert(event.form, { |
| 30 name = "muc#roomconfig_persistentroom"; | 33 name = "muc#roomconfig_persistentroom"; |
| 31 type = "boolean"; | 34 type = "boolean"; |
| 34 value = get_persistent(event.room); | 37 value = get_persistent(event.room); |
| 35 }); | 38 }); |
| 36 end, 100-5); | 39 end, 100-5); |
| 37 | 40 |
| 38 module:hook("muc-config-submitted/muc#roomconfig_persistentroom", function(event) | 41 module:hook("muc-config-submitted/muc#roomconfig_persistentroom", function(event) |
| 39 if restrict_persistent and not um_is_admin(event.actor, module.host) then | 42 if not module:may(":create-persistent-room", event.actor) then |
| 40 return; -- Not allowed | 43 return; -- Not allowed |
| 41 end | 44 end |
| 42 if set_persistent(event.room, event.value) then | 45 if set_persistent(event.room, event.value) then |
| 43 event.status_codes["104"] = true; | 46 event.status_codes["104"] = true; |
| 44 end | 47 end |
