Bläddra i källkod

Adds new option to allowners module (#10207)

* feat: Adds option to disable owner revoke in allowners module.

* squash: Fixes few lua check warnings.
master
Дамян Минков 3 år sedan
förälder
incheckning
ab18fa731b
Inget konto är kopplat till bidragsgivarens mejladress
1 ändrade filer med 41 tillägg och 5 borttagningar
  1. 41
    5
      resources/prosody-plugins/mod_muc_allowners.lua

+ 41
- 5
resources/prosody-plugins/mod_muc_allowners.lua Visa fil

2
 local jid = require "util.jid";
2
 local jid = require "util.jid";
3
 local jid_bare = require "util.jid".bare;
3
 local jid_bare = require "util.jid".bare;
4
 local jid_host = require "util.jid".host;
4
 local jid_host = require "util.jid".host;
5
+local st = require "util.stanza";
5
 local um_is_admin = require "core.usermanager".is_admin;
6
 local um_is_admin = require "core.usermanager".is_admin;
6
 local util = module:require "util";
7
 local util = module:require "util";
7
 local is_healthcheck_room = util.is_healthcheck_room;
8
 local is_healthcheck_room = util.is_healthcheck_room;
8
 local extract_subdomain = util.extract_subdomain;
9
 local extract_subdomain = util.extract_subdomain;
10
+local get_room_from_jid = util.get_room_from_jid;
9
 local presence_check_status = util.presence_check_status;
11
 local presence_check_status = util.presence_check_status;
10
 local MUC_NS = 'http://jabber.org/protocol/muc';
12
 local MUC_NS = 'http://jabber.org/protocol/muc';
11
 
13
 
12
 local moderated_subdomains;
14
 local moderated_subdomains;
13
 local moderated_rooms;
15
 local moderated_rooms;
16
+local disable_revoke_owners;
14
 
17
 
15
 local function load_config()
18
 local function load_config()
16
     moderated_subdomains = module:get_option_set("allowners_moderated_subdomains", {})
19
     moderated_subdomains = module:get_option_set("allowners_moderated_subdomains", {})
17
     moderated_rooms = module:get_option_set("allowners_moderated_rooms", {})
20
     moderated_rooms = module:get_option_set("allowners_moderated_rooms", {})
21
+    disable_revoke_owners = module:get_option_boolean("allowners_disable_revoke_owners", false);
18
 end
22
 end
19
 load_config();
23
 load_config();
20
 
24
 
21
-local function is_admin(jid)
22
-    return um_is_admin(jid, module.host);
25
+local function is_admin(_jid)
26
+    return um_is_admin(_jid, module.host);
23
 end
27
 end
24
 
28
 
25
 -- List of the bare_jids of all occupants that are currently joining (went through pre-join) and will be promoted
29
 -- List of the bare_jids of all occupants that are currently joining (went through pre-join) and will be promoted
71
         end
75
         end
72
 
76
 
73
         if not (room_name == session.jitsi_meet_room or session.jitsi_meet_room == '*') then
77
         if not (room_name == session.jitsi_meet_room or session.jitsi_meet_room == '*') then
74
-            module:log('debug', 'skip allowners for auth user and non matching room name: %s, jwt room name: %s', room_name, session.jitsi_meet_room);
78
+            module:log('debug', 'skip allowners for auth user and non matching room name: %s, jwt room name: %s',
79
+                room_name, session.jitsi_meet_room);
75
             return;
80
             return;
76
         end
81
         end
77
 
82
 
78
         if not (subdomain == session.jitsi_meet_context_group) then
83
         if not (subdomain == session.jitsi_meet_context_group) then
79
-            module:log('debug', 'skip allowners for auth user and non matching room subdomain: %s, jwt subdomain: %s', subdomain, session.jitsi_meet_context_group);
84
+            module:log('debug', 'skip allowners for auth user and non matching room subdomain: %s, jwt subdomain: %s',
85
+                subdomain, session.jitsi_meet_context_group);
80
             return;
86
             return;
81
         end
87
         end
82
     end
88
     end
103
 -- We want to filter those presences where we send first `participant` and just after it `moderator`
109
 -- We want to filter those presences where we send first `participant` and just after it `moderator`
104
 function filter_stanza(stanza)
110
 function filter_stanza(stanza)
105
     -- when joining_moderator_participants is empty there is nothing to filter
111
     -- when joining_moderator_participants is empty there is nothing to filter
106
-    if next(joining_moderator_participants) == nil or not stanza.attr or not stanza.attr.to or stanza.name ~= "presence" then
112
+    if next(joining_moderator_participants) == nil
113
+            or not stanza.attr
114
+            or not stanza.attr.to
115
+            or stanza.name ~= "presence" then
107
         return stanza;
116
         return stanza;
108
     end
117
     end
109
 
118
 
146
 
155
 
147
 -- enable filtering presences
156
 -- enable filtering presences
148
 filters.add_filter_hook(filter_session);
157
 filters.add_filter_hook(filter_session);
158
+
159
+-- filters any attempt to revoke owner rights on non moderated rooms
160
+function filter_admin_set_query(event)
161
+    local origin, stanza = event.origin, event.stanza;
162
+    local room_jid = jid_bare(stanza.attr.to);
163
+    local room = get_room_from_jid(room_jid);
164
+
165
+    local item = stanza.tags[1].tags[1];
166
+    local _aff = item.attr.affiliation;
167
+
168
+    -- if it is a moderated room we skip it
169
+    if is_moderated(room.jid) then
170
+        return nil;
171
+    end
172
+
173
+    -- any revoking is disabled
174
+    if _aff ~= 'owner' then
175
+        origin.send(st.error_reply(stanza, "auth", "forbidden"));
176
+        return true;
177
+    end
178
+end
179
+
180
+if not disable_revoke_owners then
181
+    -- default prosody priority for handling these is -2
182
+    module:hook("iq-set/bare/http://jabber.org/protocol/muc#admin:query", filter_admin_set_query, 5);
183
+    module:hook("iq-set/host/http://jabber.org/protocol/muc#admin:query", filter_admin_set_query, 5);
184
+end

Laddar…
Avbryt
Spara