This commit is contained in:
David Teller 2022-07-29 17:04:19 +02:00
parent 646b349be8
commit ce77b351d8
2 changed files with 26 additions and 5 deletions

View File

@ -27,7 +27,7 @@ import {
TextualMessageEventContent
} from "matrix-bot-sdk";
import { ALL_RULE_TYPES as ALL_BAN_LIST_RULE_TYPES, RULE_ROOM, RULE_SERVER, RULE_USER } from "./models/PolicyRule";
import { ALL_RULE_TYPES as ALL_BAN_LIST_RULE_TYPES, EntityType, RULE_ROOM, RULE_SERVER, RULE_USER } from "./models/PolicyRule";
import { applyServerAcls } from "./actions/ApplyAcl";
import { RoomUpdateError } from "./models/RoomUpdateError";
import { COMMAND_PREFIX, handleCommand } from "./commands/CommandHandler";
@ -1194,4 +1194,25 @@ export class Mjolnir {
await protection.handleReport(this, roomId, reporterId, event, reason);
}
}
/**
* Return the composite opinion for an entity.
*
* In the current implementation, we return the first opinion found in the list
* of policies. Future versions will support additional mechanisms for composing
* opinions.
*
* @param entity
* @param type
* @returns The opinion or null if no list defines an opinion on this entity.
*/
public opinionForEntity(entity: string, type: EntityType): number | null {
for (let policyList of this.policyLists) {
let opinion = policyList.opinionForEntity(entity, type);
if (opinion !== null) {
return opinion;
}
}
return null;
}
}

View File

@ -193,9 +193,9 @@ class PolicyList extends EventEmitter {
/**
* Return the opinion for a given entity.
* @returns The opinion specified by this list or `0` if no opinion was defined.
* @returns The opinion specified by this list or `null` if no opinion was defined.
*/
public opinionForEntity(entity: string, ruleKind?: EntityType): number {
public opinionForEntity(entity: string, ruleKind?: EntityType): number | null {
ruleKind = ruleKind || extractEntityType(entity);
// Find all rules for this entity.
@ -235,8 +235,8 @@ class PolicyList extends EventEmitter {
}
}
// By default, the opinion is 0.
return 0;
// By default, the opinion is null.
return null;
}
/**