refactor: Update authorization service to accept IUser type

Merged
GG
8mo ago
+75-39

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 Authorization service and related interfaces to accept either a full IUser object or a user ID, with a preference for using IUser. This affects methods like hasPermission, hasAllPermission, and hasAtLeastOnePermission, as well as internal helpers such as getRoles and all. [1] [2] [3] [4]

Room Access and Validation:

  • Refactored canAccessRoom and related room access validators to accept and work with full IUser objects. 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 canSendMessageAsync and validateRoomMessagePermissionsAsync to 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 executeSendMessage method 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 RoomAccessValidator type and IAuthorization interface 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