refactor: casl factory - publisheddata - #2812
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider updating
PublishedDataAbility.buildAbility’s signature to acceptJWTUser | undefined(or make the parameter optional) to reflect the current usage fromCaslAbilityFactory.publishedDataAccessand avoid misleading type expectations for unauthenticated calls. - It might be helpful to give
accessGroupsinPublishedDataAbilityan explicitAccessGroupsType | undefinedtype instead of leaving it implicit, to make the expected shape and potentialundefinedhandling clearer at call sites usingadmin/delete.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider updating `PublishedDataAbility.buildAbility`’s signature to accept `JWTUser | undefined` (or make the parameter optional) to reflect the current usage from `CaslAbilityFactory.publishedDataAccess` and avoid misleading type expectations for unauthenticated calls.
- It might be helpful to give `accessGroups` in `PublishedDataAbility` an explicit `AccessGroupsType | undefined` type instead of leaving it implicit, to make the expected shape and potential `undefined` handling clearer at call sites using `admin`/`delete`.
## Individual Comments
### Comment 1
<location path="src/casl/abilities/published-data.ability.ts" line_range="21-25" />
<code_context>
+ this.accessGroups =
+ this.configService.get<AccessGroupsType>("accessGroups");
+ }
+ private accessGroups;
+
+ buildAbility(user: JWTUser): MongoAbility<PossibleAbilities, Conditions> {
</code_context>
<issue_to_address>
**suggestion:** Consider typing `accessGroups` explicitly and making it readonly.
`accessGroups` is currently implicitly `any` and mutable. To align with the rest of the config-based access logic and reduce accidental mutation, consider declaring it as `private readonly accessGroups?: AccessGroupsType;`, which also clarifies its use with optional chaining later.
```suggestion
constructor(private configService: ConfigService) {
this.accessGroups =
this.configService.get<AccessGroupsType>("accessGroups");
}
private readonly accessGroups?: AccessGroupsType;
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Code Review Report: Branch
|
|
This PR might be effected by #2886 or vice versa. |
|
Just a reminder we should update the newly added authorization docs for publisheddata to reflect the casl refactor: #2886 (comment) in this / another PR |
Description
Subsection of PR #2748 for published-data.
This unifies the publishedDataEndpointAccess and publishedDataInstanceAccess functions in CaslAbilityFactory, and adjusts the affected controller to accommodate the change. The publisheddata-specific code is extracted into a separate module.
Changes:
Tests included
Documentation
Summary by Sourcery
Unify published data CASL ability handling by delegating to a dedicated PublishedDataAbility and update the published-data v4 controller to use the new access entry point.
Enhancements:
Build: