comparison mod_client_management/mod_client_management.lua @ 5311:d4a0d2b5343a

mod_client_management: Add support for revoking client access via XMPP
author Matthew Wild <mwild1@gmail.com>
date Thu, 06 Apr 2023 16:09:56 +0100
parents 5806e05346b8
children 22e6b9f09439
comparison
equal deleted inserted replaced
5310:5806e05346b8 5311:d4a0d2b5343a
367 367
368 origin.send(reply); 368 origin.send(reply);
369 return true; 369 return true;
370 end); 370 end);
371 371
372 local revocation_errors = require "util.errors".init(module.name, xmlns_manage_clients, {
373 ["item-not-found"] = { "cancel", "item-not-found", "Client not found" };
374 ["internal-server-error"] = { "wait", "internal-server-error", "Unable to revoke client access" };
375 ["password-reset-required"] = { "cancel", "service-unavailable", "Password reset required", "password-reset-required" };
376 });
377
378 module:hook("iq-set/self/xmpp:prosody.im/protocol/manage-clients:revoke", function (event)
379 local origin, stanza = event.origin, event.stanza;
380
381 if not module:may(":manage-clients", event) then
382 origin.send(st.error_reply(stanza, "auth", "forbidden"));
383 return true;
384 end
385
386 local client_id = stanza.tags[1].attr.id;
387
388 local ok, err = revocation_errors.coerce(revoke_client_access(origin.username, client_id));
389 if not ok then
390 origin.send(st.error_reply(stanza, err));
391 return true;
392 end
393
394 origin.send(st.reply(stanza));
395 return true;
396 end);
397
398
372 -- Command 399 -- Command
373 400
374 module:once(function () 401 module:once(function ()
375 local console_env = module:shared("/*/admin_shell/env"); 402 local console_env = module:shared("/*/admin_shell/env");
376 if not console_env.user then return; end -- admin_shell probably not loaded 403 if not console_env.user then return; end -- admin_shell probably not loaded