diff 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
line wrap: on
line diff
--- a/mod_client_management/mod_client_management.lua	Thu Apr 06 15:24:49 2023 +0100
+++ b/mod_client_management/mod_client_management.lua	Thu Apr 06 16:09:56 2023 +0100
@@ -369,6 +369,33 @@
 	return true;
 end);
 
+local revocation_errors = require "util.errors".init(module.name, xmlns_manage_clients, {
+	["item-not-found"] = { "cancel", "item-not-found", "Client not found" };
+	["internal-server-error"] = { "wait", "internal-server-error", "Unable to revoke client access" };
+	["password-reset-required"] = { "cancel", "service-unavailable", "Password reset required", "password-reset-required" };
+});
+
+module:hook("iq-set/self/xmpp:prosody.im/protocol/manage-clients:revoke", function (event)
+	local origin, stanza = event.origin, event.stanza;
+
+	if not module:may(":manage-clients", event) then
+		origin.send(st.error_reply(stanza, "auth", "forbidden"));
+		return true;
+	end
+
+	local client_id = stanza.tags[1].attr.id;
+
+	local ok, err = revocation_errors.coerce(revoke_client_access(origin.username, client_id));
+	if not ok then
+		origin.send(st.error_reply(stanza, err));
+		return true;
+	end
+
+	origin.send(st.reply(stanza));
+	return true;
+end);
+
+
 -- Command
 
 module:once(function ()