refactor: Update authorization service to accept IUser type
This pull request refactors the way user objects are handled in permission and room access checks throughout the codebase. The main goal is to migrate from passing user IDs or partial user objects to consistently using full IUser objects, improving type safety and reducing ambiguity. The changes also update relevant method signatures and internal logic to support this transition, while maintaining backward compatibility for now.
The most important changes are:
Authorization and Permission Checks:
- Updated the
Authorizationservice and related interfaces to accept either a fullIUserobject or a user ID, with a preference for usingIUser. This affects methods likehasPermission,hasAllPermission, andhasAtLeastOnePermission, as well as internal helpers such asgetRolesandall. [1] [2] [3] [4]
Room Access and Validation:
- Refactored
canAccessRoomand related room access validators to accept and work with fullIUserobjects. Added logic to convert a partial user (with only_id) to a full user when necessary, ensuring all validators receive the expected user shape. [1] [2] [3] [4] - Updated
canSendMessageAsyncandvalidateRoomMessagePermissionsAsyncto accept either a user object or the legacy{ uid, username, type }shape, with a plan to remove the old option in the future. [1] [2]
Send Message Flow:
- Modified the
executeSendMessagemethod and its call sites to accept a full user object rather than just a user ID, updating all downstream permission and room access checks accordingly. [1] [2] [3] [4] [5] [6] [7]
API and Notification Adjustments:
- Updated API endpoints and notification modules to pass user objects instead of user IDs to authorization checks and room access methods.
Type Definitions:
- Updated the
RoomAccessValidatortype andIAuthorizationinterface to reflect the new user parameter types and deprecated the old signatures that only accepted user IDs.
These changes lay the groundwork for a more robust and type-safe permission and access control system by standardizing on full user objects throughout the codebase.
Proposed changes (including videos or screenshots)
Issue(s)
Steps to test or reproduce
Further comments
Task: ARCH-1983