Skip to content

Commit d3b55a8

Browse files
authored
Add !rules matching members command. (#726)
This shows all the rules that are matching members in the protected rooms set, but probably cannot be actioned either due to permission limitations or ACL leakage.
1 parent 94f41d7 commit d3b55a8

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

src/commands/DraupnirCommands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
import {
3939
DraupnirListRulesCommand,
4040
DraupnirRulesMatchingCommand,
41+
DraupnirRulesMatchingMembersCommand,
4142
} from "./Rules";
4243
import { DraupnirDisplaynameCommand } from "./SetDisplayNameCommand";
4344
import { DraupnirSetPowerLevelCommand } from "./SetPowerLevelCommand";
@@ -104,6 +105,11 @@ const DraupnirCommands = new StandardCommandTable("draupnir")
104105
.internCommand(DraupnirRoomsRemoveCommand, ["rooms", "remove"])
105106
.internCommand(DraupnirListRulesCommand, ["rules"])
106107
.internCommand(DraupnirRulesMatchingCommand, ["rules", "matching"])
108+
.internCommand(DraupnirRulesMatchingMembersCommand, [
109+
"rules",
110+
"matching",
111+
"members",
112+
])
107113
.internCommand(DraupnirSafeModeCommand, ["safe", "mode"])
108114
.internCommand(DraupnirDisplaynameCommand, ["displayname"])
109115
.internCommand(DraupnirSetPowerLevelCommand, ["powerlevel"])

src/commands/Rules.tsx

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// </text>
1010

1111
import {
12+
MemberPolicyMatches,
1213
Ok,
1314
PolicyRoomWatchProfile,
1415
PolicyRule,
@@ -31,6 +32,7 @@ import {
3132
import { Result } from "@gnuxie/typescript-result";
3233
import { Draupnir } from "../Draupnir";
3334
import { DraupnirInterfaceAdaptor } from "./DraupnirCommandPrerequisites";
35+
import { renderMentionPill } from "./interface-manager/MatrixHelpRenderer";
3436

3537
function renderListMatches(
3638
result: Result<ListMatches[]>
@@ -51,15 +53,16 @@ function renderListMatches(
5153
);
5254
}
5355

56+
function renderRuleSummary(rule: PolicyRule) {
57+
return (
58+
<li>
59+
{rule.kind} (<code>{rule.recommendation}</code>):{" "}
60+
<code>{rule.entity}</code> ({rule.reason})
61+
</li>
62+
);
63+
}
64+
5465
export function renderListRules(list: ListMatches) {
55-
const renderRuleSummary = (rule: PolicyRule) => {
56-
return (
57-
<li>
58-
{rule.kind} (<code>{rule.recommendation}</code>):{" "}
59-
<code>{rule.entity}</code> ({rule.reason})
60-
</li>
61-
);
62-
};
6366
return (
6467
<fragment>
6568
<a href={list.room.toPermalink()}>{list.roomID}</a> propagation:{" "}
@@ -138,3 +141,39 @@ export const DraupnirRulesMatchingCommand = describeCommand({
138141
DraupnirInterfaceAdaptor.describeRenderer(DraupnirRulesMatchingCommand, {
139142
JSXRenderer: renderListMatches,
140143
});
144+
145+
export const DraupnirRulesMatchingMembersCommand = describeCommand({
146+
summary:
147+
"Lists the rule that are matching matching members of protected rooms",
148+
parameters: tuple(),
149+
async executor(draupnir: Draupnir): Promise<Result<MemberPolicyMatches[]>> {
150+
const revision =
151+
draupnir.protectedRoomsSet.setPoliciesMatchingMembership.currentRevision;
152+
return Ok(revision.allMembersWithRules());
153+
},
154+
});
155+
156+
DraupnirInterfaceAdaptor.describeRenderer(DraupnirRulesMatchingMembersCommand, {
157+
JSXRenderer(result) {
158+
if (isError(result)) {
159+
return Ok(undefined);
160+
}
161+
return Ok(
162+
<root>
163+
<h4>Rules matching members of protected rooms:</h4>
164+
<ul>
165+
{result.ok.map((memberPolicies) => (
166+
<li>
167+
{renderMentionPill(memberPolicies.userID, memberPolicies.userID)}:
168+
<ul>
169+
{memberPolicies.policies.map((policy) =>
170+
renderRuleSummary(policy)
171+
)}
172+
</ul>
173+
</li>
174+
))}
175+
</ul>
176+
</root>
177+
);
178+
},
179+
});

0 commit comments

Comments
 (0)