99// </text>
1010
1111import {
12+ MemberPolicyMatches ,
1213 Ok ,
1314 PolicyRoomWatchProfile ,
1415 PolicyRule ,
@@ -31,6 +32,7 @@ import {
3132import { Result } from "@gnuxie/typescript-result" ;
3233import { Draupnir } from "../Draupnir" ;
3334import { DraupnirInterfaceAdaptor } from "./DraupnirCommandPrerequisites" ;
35+ import { renderMentionPill } from "./interface-manager/MatrixHelpRenderer" ;
3436
3537function 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+
5465export 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({
138141DraupnirInterfaceAdaptor . 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