Update the deactivate command to use the audit log and purging deactivate.

This commit is contained in:
gnuxie committed 2025-04-13 20:06:35 +01:00
1 parent d8a6ba756b
commit 99bbbf5b01
2 files changed
+55 -7

No files matched your search

+9
View File
@@ -83,6 +83,7 @@ import {
} from "./commands/interface-manager/MatrixPromptForConfirmation";
import { SynapseHttpAntispam } from "./webapis/SynapseHTTPAntispam/SynapseHttpAntispam";
import { DraupnirStores } from "./backingstore/DraupnirStores";
import { HomeserverUserPurgingDeactivate } from "./protections/HomeserverUserPolicyApplication/HomeserverUserPurgingDeactivate";
const log = new Logger("Draupnir");
// webAPIS should not be included on the Draupnir class.
@@ -116,6 +117,14 @@ export class Draupnir implements Client, MatrixAdaptorContext {
public readonly reactionHandler: MatrixReactionHandler;
public readonly purgingDeactivate =
this.synapseAdminClient && this.stores.restrictionAuditLog
? new HomeserverUserPurgingDeactivate(
this.synapseAdminClient,
this.stores.restrictionAuditLog
)
: undefined;
private readonly timelineEventListener = this.handleTimelineEvent.bind(this);
public readonly capabilityMessageRenderer: RendererMessageCollector;
+46 -7
View File
@@ -1,4 +1,4 @@
// Copyright 2022 Gnuxie <Gnuxie@protonmail.com>
// Copyright 2022 - 2025 Gnuxie <Gnuxie@protonmail.com>
// Copyright 2019 The Matrix.org Foundation C.I.C.
//
// SPDX-License-Identifier: AFL-3.0 AND Apache-2.0
@@ -8,8 +8,9 @@
// https://github.com/matrix-org/mjolnir
// </text>
import { Ok, Result, isError } from "@gnuxie/typescript-result";
import { Result, ResultError, isError } from "@gnuxie/typescript-result";
import {
BasicInvocationInformation,
MatrixUserIDPresentationType,
describeCommand,
tuple,
@@ -17,6 +18,7 @@ import {
import { ActionError } from "matrix-protection-suite";
import { Draupnir } from "../../Draupnir";
import { DraupnirInterfaceAdaptor } from "../DraupnirCommandPrerequisites";
import { deactivateUser } from "../../protections/HomeserverUserPolicyApplication/deactivateUser";
export const SynapseAdminDeactivateCommand = describeCommand({
summary: "Deactivate a user on the homeserver.",
@@ -25,24 +27,61 @@ export const SynapseAdminDeactivateCommand = describeCommand({
description: "The user to deactivate",
acceptor: MatrixUserIDPresentationType,
}),
keywords: {
keywordDescriptions: {
"purge-messages": {
isFlag: true,
description:
"Restrict access to the account until Draupnir removes all of their messages, and then finally deactivate.",
},
},
},
async executor(
draupnir: Draupnir,
_info,
_keywords,
info: BasicInvocationInformation,
keywords,
_rest,
targetUser
): Promise<Result<void>> {
const isAdmin = await draupnir.synapseAdminClient?.isSynapseAdmin();
if (isAdmin === undefined || isError(isAdmin) || !isAdmin.ok) {
if (
isAdmin === undefined ||
isError(isAdmin) ||
!isAdmin.ok ||
!draupnir.purgingDeactivate
) {
return ActionError.Result(
"I am not a Synapse administrator, or the endpoint to deactivate a user is blocked"
);
}
if (draupnir.stores.restrictionAuditLog === undefined) {
return ResultError.Result(
"The user restriction audit log is not configured"
);
}
if (draupnir.synapseAdminClient === undefined) {
throw new TypeError("Shouldn't be happening at this point");
}
await draupnir.synapseAdminClient.deactivateUser(targetUser.toString());
return Ok(undefined);
const isPurgingDeactivate = keywords.getKeywordValue<boolean>(
"purge-messages",
false
);
const deactivateResult = await (() =>
isPurgingDeactivate
? draupnir.purgingDeactivate.beginPurgeUser(targetUser.toString(), {
sender: info.commandSender,
rule: null,
})
: deactivateUser(
targetUser.toString(),
draupnir.synapseAdminClient,
draupnir.stores.restrictionAuditLog,
{
sender: info.commandSender,
rule: null,
}
))();
return deactivateResult;
},
});