Comparison

plugins/muc/persistent.lib.lua @ 12729:73a45ba6e3f1

muc: Re-allow non-admins to configure persistence (thanks Meaz) Non-admins don't have a role on MUC services by default. Not even prosody:user. This meant they had no :create-persistent-room permission, even if muc_room_allow_persistent was true (the default). Now we only check the role permissions if persistent room creation is restricted, otherwise we skip any permission checks, just like previous versions.
author Matthew Wild <mwild1@gmail.com>
date Wed, 28 Sep 2022 17:47:00 +0100
parent 12642:9061f9621330
child 12732:f731eda8a873
comparison
equal deleted inserted replaced
12728:931a2d049a91 12729:73a45ba6e3f1
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( 11 module:default_permission("prosody:admin", ":create-persistent-room"); -- Admins can always create, by default
12 restrict_persistent and "prosody:admin" or "prosody:user",
13 ":create-persistent-room"
14 );
15 12
16 local function get_persistent(room) 13 local function get_persistent(room)
17 return room._data.persistent; 14 return room._data.persistent;
18 end 15 end
19 16
23 room._data.persistent = persistent; 20 room._data.persistent = persistent;
24 return true; 21 return true;
25 end 22 end
26 23
27 module:hook("muc-config-form", function(event) 24 module:hook("muc-config-form", function(event)
28 if not module:may(":create-persistent-room", event.actor) then 25 if restrict_persistent and not module:may(":create-persistent-room", event.actor) then
29 -- Hide config option if this user is not allowed to create persistent rooms 26 -- Hide config option if this user is not allowed to create persistent rooms
30 return; 27 return;
31 end 28 end
32 table.insert(event.form, { 29 table.insert(event.form, {
33 name = "muc#roomconfig_persistentroom"; 30 name = "muc#roomconfig_persistentroom";
37 value = get_persistent(event.room); 34 value = get_persistent(event.room);
38 }); 35 });
39 end, 100-5); 36 end, 100-5);
40 37
41 module:hook("muc-config-submitted/muc#roomconfig_persistentroom", function(event) 38 module:hook("muc-config-submitted/muc#roomconfig_persistentroom", function(event)
42 if not module:may(":create-persistent-room", event.actor) then 39 if restrict_persistent and not module:may(":create-persistent-room", event.actor) then
43 return; -- Not allowed 40 return; -- Not allowed
44 end 41 end
45 if set_persistent(event.room, event.value) then 42 if set_persistent(event.room, event.value) then
46 event.status_codes["104"] = true; 43 event.status_codes["104"] = true;
47 end 44 end