refactor(api): centralize caller ability creation in AbilityFactory#29
Merged
Conversation
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes the
createAbilityForCaller/isUserOnboardedprivate-helper duplication fromEventsServiceandGalleriesServiceby moving the logic intoAbilityFactoryas a newcreateForCaller(callerId)method. Every domain service that authorizes with CASL now calls one shared implementation — motivated by the upcoming photos domain, which would otherwise have added a third copy.What's included
AbilityFactory.createForCaller(callerId)— fetches the caller's onboarding state and builds the ability in one place.AbilityFactorynow injectsPrismaService(PrismaModuleis global, so no module wiring changes)createForUser(user)kept unchanged for callers that already know the onboarding state (and for tests)EventsService/GalleriesService— dropped both private helpers; all 9 call sites now useabilityFactory.createForCallerEventsService.findAllForUser— the earlyreturn []for non-onboarded callers now checksability.can(READ, Event)against the subject type, which is false exactly when the caller has no rules (not onboarded). Same behavior, no extra query shape changecreateForCaller(onboarded, not onboarded, missing user)Behavior
No API or behavior changes — pure refactor. Each authorized call still performs the same single user lookup; it just lives in one place now.
Test plan
npm test— 218 passed (3 new)npm run test:e2e— 75 passedformat:check,eslint,openapi:check(spec unchanged),npm run build