comparison plugins/muc/persistent.lib.lua @ 12732:f731eda8a873

Backed out changeset 73a45ba6e3f1 in favour of 427dd01f0864 New behaviour (muc_room_allow_persistent = true, the default): - Parent host users are not restricted by default (prosody:user) - Users without roles (by default that is non-admins, non-parent-host users, and users on other servers) can no longer configure persistence by default. muc_room_allow_persistent = false will restrict persistence to prosody:admin. Parent-host users should not be restricted by default, and this can be configured via the new roles/permissions options.
author Matthew Wild <mwild1@gmail.com>
date Thu, 29 Sep 2022 12:43:09 +0100
parents 73a45ba6e3f1
children 082c7d856e61
comparison
equal deleted inserted replaced
12731:a314f5bff9f0 12732:f731eda8a873
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 module:default_permission("prosody:admin", ":create-persistent-room"); -- Admins can always create, by default 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 module:may(":create-persistent-room", event.actor) then 28 if not module:may(":create-persistent-room", event.actor) then
26 -- Hide config option if this user is not allowed to create persistent rooms 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";
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 module:may(":create-persistent-room", event.actor) 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