refactor(authorization): accept a minimal user shape (UserWithRoles) in permission checks - #41351
Conversation
|
Looks like this PR is ready to merge! 🎉 |
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
📜 Recent review details⏰ Context from checks skipped due to timeout. (2)
🧰 Additional context used📓 Path-based instructions (1)**/*.{ts,tsx,js}📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
🧠 Learnings (3)📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-05-06T12:21:44.083ZApplied to files:
🔇 Additional comments (13)
WalkthroughAuthorization permission APIs now accept a minimal ChangesAuthorization user-shape migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
561c458 to
f285a4b
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #41351 +/- ##
===========================================
- Coverage 69.12% 69.07% -0.05%
===========================================
Files 3762 3762
Lines 147936 147936
Branches 26428 26453 +25
===========================================
- Hits 102261 102190 -71
- Misses 41185 41258 +73
+ Partials 4490 4488 -2
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
f285a4b to
9d2d920
Compare
…ecks
Add `UserWithRoles = Pick<IUser, '_id' | 'roles'>` to IAuthorization and relax
the permission-check signatures from `string | IUser` to `string | UserWithRoles`.
`getRoles` only reads `_id` and `roles`, so a full `IUser` was never required.
This lets call sites holding a partial user projection pass the object directly —
skipping the check's internal Users.findOneById — as long as that projection
carries `roles` at runtime. Migrated only sites verified to carry roles at
RUNTIME (not just by type, since finders return `IUser` regardless of projection):
- Meteor.userAsync() sites (full doc): pushConfig, removeChannelLinks,
room publications, loadHistory.
- canAccessRoom: use the already-refetched full user.
- eraseRoom (+ eraseTeam generic constraints): all callers pass REST `this.user`
(getDefaultUserFields includes roles) or a full user.
- browseChannels: method caller uses userAsync; its REST caller now projects
`roles` alongside `__rooms`.
Left on the user-id form: livechat roomAccessValidator (caller has only `_id`),
and canDeleteMessage (one caller chain — deleteFileMessage → Upload.canDeleteFile
— loads the user with a `{ username }` projection, so it lacks roles at runtime).
9d2d920 to
615a68e
Compare
What
Follow-up to accepting
IUserin permission checks. Adds a minimal named type and migrates the sites that hold a partial user projection (which the previousstring | IUsersignature rejected).Core change
getRolesonly ever readsuser._idanduser.roles, so requiring a fullIUserwas overkill. New type inIAuthorization:Authorization.hasPermission/hasAllPermission/hasAtLeastOnePermissionand thehasPermissionAsynchelpers now takestring | UserWithRoles. FullIUserstays compatible, so nothing that already passes a user breaks.Migrated sites
Meteor.userAsync()(full doc at runtime, only the static type was narrow):pushConfig,removeChannelLinks, room publications,loadHistory.canAccessRoom: pass the user it already re-fetches to a full document.roles, then pass the object:canDeleteMessage,eraseRoom(+ theeraseTeamSharedgeneric constraints it flows into),browseChannels.browseChannelsREST caller (api/v1/misc.ts) now projectsrolesnext to__rooms.Each partial site that now passes an object trades 2 DB lookups for 1 (its own fetch + the check's internal
findOneById→ just its own fetch, widened to includeroles).Left on the string path
livechat/roomAccessValidator.compatibilityreceivesPick<IUser, '_id'>from its caller — no roles available, and fetching them would add the lookup this change avoids.Verification
Every touched file typechecks clean (serena diagnostics), no
ascasts.IUser.rolesbeing required means TS still blocks any rolesless object — the safety gate is intact.Task: ARCH-2248
Summary by CodeRabbit