Skip to content

Commit

Permalink
UNFINISHED: start moving permission check command to MPS.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnuxie committed Apr 6, 2024
1 parent a6b2179 commit 9b48a48
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/commands/PermissionCheckCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,32 @@ limitations under the License.
* are NOT distributed, contributed, committed, or licensed under the Apache License.
*/

import { Mjolnir } from "../Mjolnir";
import { ActionError, ActionResult } from "matrix-protection-suite";
import { defineInterfaceCommand, findTableCommand } from "./interface-manager/InterfaceCommand";
import { ParsedKeywords, parameters } from "./interface-manager/ParameterParsing";
import { DraupnirContext } from "./CommandHandler";
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";

// !mjolnir verify
export async function execPermissionCheckCommand(roomId: string, event: any, mjolnir: Mjolnir) {
return mjolnir.protectedRoomsTracker.verifyPermissions();
}
defineInterfaceCommand({
designator: ["verify"],
table: "mjolnir",
parameters: parameters([]),
command: async function (this: DraupnirContext, _keywords: ParsedKeywords): Promise<ActionResult<unknown>> {
const enabledProtection = this.draupnir.protectedRoomsSet.protections.allProtections;
const eventPermissions = new Set<string>();
const permissions = new Set<string>();
for (const proteciton of enabledProtection) {
proteciton.requiredEventPermissions.forEach(permission => eventPermissions.add(permission));
proteciton.requiredPermissions.forEach(permission => permissions.add(permission));
}
// FIXME do we need something like setMembership but for room state?
return ActionError.Result(`Unimplemented`);
},
summary: "Verify the permissions that draupnir has."
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "verify"),
renderer: tickCrossRenderer
})

0 comments on commit 9b48a48

Please sign in to comment.