Software / code / prosody
Comparison
plugins/muc/hidden.lib.lua @ 12802:4a8740e01813
Merge 0.12->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 12 Dec 2022 07:10:54 +0100 |
| parent | 12642:9061f9621330 |
| child | 13170:082c7d856e61 |
comparison
equal
deleted
inserted
replaced
| 12801:ebd6b4d8bf04 | 12802:4a8740e01813 |
|---|---|
| 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_public = not module:get_option_boolean("muc_room_allow_public", true); | 10 local restrict_public = not module:get_option_boolean("muc_room_allow_public", true); |
| 11 local um_is_admin = require "core.usermanager".is_admin; | 11 module:default_permission(restrict_public and "prosody:admin" or "prosody:user", ":create-public-room"); |
| 12 | 12 |
| 13 local function get_hidden(room) | 13 local function get_hidden(room) |
| 14 return room._data.hidden; | 14 return room._data.hidden; |
| 15 end | 15 end |
| 16 | 16 |
| 20 room._data.hidden = hidden; | 20 room._data.hidden = hidden; |
| 21 return true; | 21 return true; |
| 22 end | 22 end |
| 23 | 23 |
| 24 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 | 25 if not module:may(":create-public-room", event.actor) then |
| 26 -- Don't show option if public rooms are restricted and user is not admin of this host | 26 -- Hide config option if this user is not allowed to create public rooms |
| 27 return; | 27 return; |
| 28 end | 28 end |
| 29 table.insert(event.form, { | 29 table.insert(event.form, { |
| 30 name = "muc#roomconfig_publicroom"; | 30 name = "muc#roomconfig_publicroom"; |
| 31 type = "boolean"; | 31 type = "boolean"; |
| 34 value = not get_hidden(event.room); | 34 value = not get_hidden(event.room); |
| 35 }); | 35 }); |
| 36 end, 100-9); | 36 end, 100-9); |
| 37 | 37 |
| 38 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 | 39 if not module:may(":create-public-room", event.actor) then |
| 40 return; -- Not allowed | 40 return; -- Not allowed |
| 41 end | 41 end |
| 42 if set_hidden(event.room, not event.value) then | 42 if set_hidden(event.room, not event.value) then |
| 43 event.status_codes["104"] = true; | 43 event.status_codes["104"] = true; |
| 44 end | 44 end |