-
Notifications
You must be signed in to change notification settings - Fork 13k
chore!: remove addUserToRole and removeUserFromRole
#36935
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
Conversation
|
Looks like this PR is ready to merge! 🎉 |
|
WalkthroughRemoved ddp-client method augmentations for add/remove role methods, added strict argument validation, and changed role lookup to ID-only resolution (no name fallback). Added a deprecation log call to setAdminStatus. User resolution, admin protections, broadcasts, and return values are unchanged. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor C as Client
participant S as addUserToRole
participant R as Roles
participant U as Users
participant A as Authorization
participant B as Broadcast/UI
C->>S: invoke(roleId, username, scope)
S->>S: validate roleId, username (types)
S->>R: findOneById(roleId)
R-->>S: role | null
alt role not found
S-->>C: error-invalid-role
else role found
S->>U: findOneByUsernameInsensitive(username)
U-->>S: user | null
alt user not found
S-->>C: error-invalid-user
else user found
S->>A: check canAddUserToRole(user, role, scope)
alt not allowed
S-->>C: error-not-allowed
else allowed
S->>R: addUserRolesAsync(user, role, scope)
R-->>S: result
S->>B: UI update + federation broadcast
S-->>C: result
end
end
end
sequenceDiagram
autonumber
actor C as Client
participant S as removeUserFromRole
participant R as Roles
participant U as Users
participant A as Authorization
participant B as Broadcast/UI
C->>S: invoke(roleId, username, scope)
S->>S: validate roleId, username (types)
S->>R: findOneById(roleId)
R-->>S: role | null
alt role not found
S-->>C: error-invalid-role
else role found
S->>U: findOneByUsernameInsensitive(username)
U-->>S: user | null
alt user not found
S-->>C: error-invalid-user
else user found
S->>A: check canRemoveUserFromRole(user, role, scope)
alt not allowed or last-admin guard
S-->>C: error-not-allowed
else allowed
S->>R: removeUserFromRoleAsync(user, role, scope)
R-->>S: result
S->>B: UI update + federation broadcast
S-->>C: result
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
Comment Pre-merge checks✅ Passed checks (3 passed)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.changeset/cold-moons-kiss.md(1 hunks)apps/meteor/app/authorization/server/methods/removeUserFromRole.ts(0 hunks)apps/meteor/app/bot-helpers/server/index.ts(0 hunks)apps/meteor/app/lib/server/methods/setAdminStatus.ts(0 hunks)apps/meteor/server/methods/removeUserFromRoom.ts(0 hunks)
💤 Files with no reviewable changes (4)
- apps/meteor/app/lib/server/methods/setAdminStatus.ts
- apps/meteor/app/bot-helpers/server/index.ts
- apps/meteor/app/authorization/server/methods/removeUserFromRole.ts
- apps/meteor/server/methods/removeUserFromRoom.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
🔇 Additional comments (1)
.changeset/cold-moons-kiss.md (1)
1-3: Changeset header looks correct.Package scope and release bump are well-formed for a major change.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release-8.0.0 #36935 +/- ##
=================================================
- Coverage 66.43% 66.38% -0.06%
=================================================
Files 3276 3312 +36
Lines 109596 111670 +2074
Branches 20860 20944 +84
=================================================
+ Hits 72814 74133 +1319
- Misses 34116 34860 +744
- Partials 2666 2677 +11
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
removeUserFromRole
05eefba to
b7d3c13
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/meteor/app/authorization/server/methods/removeUserFromRole.ts (1)
44-59: Missing permission gate when removing the admin role.Users with generic 'access-permissions' can strip 'admin' from others unless blocked by "last admin" rule. Require 'assign-admin-role' here, mirroring addUserToRole.
// prevent removing last user from admin role if (role._id === 'admin') { + // require elevated permission to modify the 'admin' role + if (!(await hasPermissionAsync(userId, 'assign-admin-role'))) { + throw new Meteor.Error('error-action-not-allowed', 'Removing admin is not allowed', { + method: 'authorization:removeUserFromRole', + action: 'Remove_admin', + }); + } + const adminCount = await Users.countDocuments({ roles: { $in: ['admin'], }, }); - const userIsAdmin = user.roles?.indexOf('admin') > -1; + const userIsAdmin = user.roles?.includes('admin') === true; if (adminCount === 1 && userIsAdmin) { throw new Meteor.Error('error-action-not-allowed', 'Leaving the app without admins is not allowed', { - method: 'removeUserFromRole', + method: 'authorization:removeUserFromRole', action: 'Remove_last_admin', }); } }
🧹 Nitpick comments (3)
apps/meteor/app/authorization/server/methods/addUserToRole.ts (1)
18-22: Simplify argument validation; avoid valueOf().Prefer direct string checks for clarity and to reject empty strings.
- if (!roleId || typeof roleId.valueOf() !== 'string' || !username || typeof username.valueOf() !== 'string') { + if (typeof roleId !== 'string' || roleId.length === 0 || typeof username !== 'string' || username.length === 0) {apps/meteor/app/authorization/server/methods/removeUserFromRole.ts (2)
10-16: Minor copy fix in error message.Grammar tweak for consistency with addUserToRole.
- throw new Meteor.Error('error-action-not-allowed', 'Access permissions is not allowed', { + throw new Meteor.Error('error-action-not-allowed', 'Accessing permissions is not allowed', {
54-57: Align 'method' field naming.Use the same 'authorization:removeUserFromRole' identifier as elsewhere.
- method: 'removeUserFromRole', + method: 'authorization:removeUserFromRole',
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/meteor/app/authorization/server/methods/addUserToRole.ts(1 hunks)apps/meteor/app/authorization/server/methods/removeUserFromRole.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: check
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
- GitHub Check: Builds matrix rust bindings against alpine
- GitHub Check: CodeQL-Build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/meteor/app/lib/server/methods/setAdminStatus.ts (1)
45-51: Pass roleId (not role name) to addUserToRole/removeUserFromRoleaddUserToRole/removeUserFromRole signatures are (userId: string, roleId: string, username: IUser['username'], scope?: string) (see apps/meteor/app/authorization/server/methods/{addUserToRole,removeUserFromRole}.ts). The code in apps/meteor/app/lib/server/methods/setAdminStatus.ts (lines ~45–51) still passes the literal 'admin' as the role — resolve the admin role's id and pass that roleId as the second argument; the username argument (user?.username) is correct.
🧹 Nitpick comments (1)
apps/meteor/app/lib/server/methods/setAdminStatus.ts (1)
21-25: Confirm deprecation target version (8.0.0) and placement of the log
- If this ships in release-8.0.0, “will be removed on version 8.0.0” can be misleading. Confirm whether removal is actually in 8.0.0 or the next major (e.g., 9.0.0) and adjust accordingly; otherwise remove the method now or gate it.
- Optional: consider logging after auth/permission checks to avoid unauthenticated probes inflating deprecation metrics.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/meteor/app/lib/server/methods/setAdminStatus.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/app/lib/server/methods/setAdminStatus.ts (1)
apps/meteor/app/lib/server/lib/deprecationWarningLogger.ts (1)
methodDeprecationLogger(90-137)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
- GitHub Check: CodeQL-Build
🔇 Additional comments (1)
apps/meteor/app/lib/server/methods/setAdminStatus.ts (1)
10-10: Deprecation logger import — LGTMImport path and named export look correct for the existing helper.
fd5e184 to
b7d3c13
Compare
removeUserFromRoleaddUserToRole and removeUserFromRole
ARCH-1801
Proposed changes (including videos or screenshots)
Issue(s)
Steps to test or reproduce
Further comments
Summary by CodeRabbit
Bug Fixes
Refactor
Chores