Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Towards opinions in PolicyLists. #336

Merged
merged 8 commits into from
Jul 26, 2022
Merged

Towards opinions in PolicyLists. #336

merged 8 commits into from
Jul 26, 2022

Conversation

Yoric
Copy link
Contributor

@Yoric Yoric commented Jul 20, 2022

This changeset is part of an ongoing effort to implement "opinions"
within policy lists, as per MSC3847.

For the time being:

  • we rename BanList into PolicyList;
  • we cleanup a little dead code;
  • we replace a few strings with enum;
  • ListRule becomes an abstract class with two concrete subclasses ListRuleBan and ListRuleOpinion.

This changeset is part of an ongoing effort to implement "opinions"
within policy lists, as per MSC3847.

For the time being:
- we rename BanList into PolicyList;
- we cleanup a little dead code;
- we replace a few `string`s with `enum`;
- `ListRule` becomes an abstract class with two concrete subclasses `ListRuleBan` and `ListRuleOpinion`.
@Yoric Yoric requested review from jesopo and Gnuxie July 20, 2022 09:19
src/models/ListRule.ts Outdated Show resolved Hide resolved
src/models/ListRule.ts Outdated Show resolved Hide resolved
src/models/PolicyList.ts Outdated Show resolved Hide resolved
src/models/ListRule.ts Outdated Show resolved Hide resolved
Comment on lines -36 to -41
* The recommendation for this rule, or `null` if there is no recommendation or the recommendation is invalid.
* Recommendations are normalised to their stable types.
* A glob for `entity`.
*/
public get recommendation(): string|null {
if (RECOMMENDATION_BAN_TYPES.includes(this.action)) return RECOMMENDATION_BAN;
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for changing this getter? You need to be really careful to check where this behaviour is being relied upon https://github.com/matrix-org/mjolnir/pull/336/files#diff-ebc449200d5204df932d4794476267f12b9759b8dfcbf34b7dc92361870b5f3cR155 is the only example (I think) and needs changing to ensure the kind is upgraded to stable.

Copy link
Contributor Author

@Yoric Yoric Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, for ListRuleBan, the public readonly property will return exactly the same thing as the getter, with simpler code and slightly stronger typing.

For ListRuleOpinion, the public readonly property will return something different, but there is no helping it. I'll need to go through the entire codebase with a fine comb to find out exactly where the fact that all rules are m.ban is currently harcoded. I expect that this is going to take me some time, hence the current PR that only does part of the job.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to go through the entire codebase with a fine comb to find out exactly where the fact that all rules are m.ban is currently harcoded. I expect that this is going to take me some time, hence the current PR that only does part of the job.

Well yes but you can't do part of the job without introducing a bug so it doesn't seem acceptable, though searching this myself there is only one instance (the one linked) where there would be a bug.

Copy link
Contributor Author

@Yoric Yoric Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bugs happen, but I believe that I've structured my refactoring to ensure that the behavior remains unchanged for the time being. There may be slight theoretical differences in ill-formed rules if someone happens to create an ill-formed ListRuleOpinion, but that shouldn't have any consequence.

Do we agree so far?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we're talking about the same thing, but so long as we only make rules with List.parse i don't think this will be a problem anymore.

src/models/ListRule.ts Show resolved Hide resolved
src/models/ListRule.ts Outdated Show resolved Hide resolved
src/models/ListRule.ts Outdated Show resolved Hide resolved
@Yoric Yoric requested a review from Gnuxie July 21, 2022 08:03
src/models/ListRule.ts Outdated Show resolved Hide resolved
package.json Outdated
@@ -14,6 +14,7 @@
"start:dev": "yarn build && node --async-stack-traces lib/index.js",
"test": "ts-mocha --project ./tsconfig.json test/commands/**/*.ts",
"test:integration": "NODE_ENV=harness ts-mocha --async-stack-traces --require test/integration/fixtures.ts --timeout 300000 --project ./tsconfig.json \"test/integration/**/*Test.ts\"",
"test:YORIC": "NODE_ENV=harness ts-mocha --async-stack-traces --require test/integration/fixtures.ts --timeout 300000 --project ./tsconfig.json \"test/integration/banListTest.ts\"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to remove this 😸

Copy link
Contributor

@Gnuxie Gnuxie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two more pretty critical things i've become aware of

src/models/ListRule.ts Outdated Show resolved Hide resolved
src/models/ListRule.ts Show resolved Hide resolved
@Yoric Yoric merged commit 829e1bd into main Jul 26, 2022
const banList = new BanList(banListId, banListId, mjolnir);
await createPolicyRule(mjolnir, banListId, RULE_SERVER, 'exmaple.org', '', {recommendation: 'something that is not m.ban'});
const banList = new PolicyList(banListId, banListId, mjolnir);
await createPolicyRule(mjolnir, banListId, RULE_SERVER, 'exmaple.org', '', { recommendation: 'something that is not m.ban' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain how these formatting changes were spotted? (Did you use another linter or editor extension?) Dealing with a merge conflict in this file and worried about missing some.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants