Page MenuHomePhabricator

[lib] Include `specialRole` field in `RoleInfo` for future clients
ClosedPublic

Authored by atul on Feb 8 2024, 9:49 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Dec 28, 9:02 PM
Unknown Object (File)
Sat, Dec 28, 2:06 PM
Unknown Object (File)
Sat, Dec 28, 2:06 PM
Unknown Object (File)
Sat, Dec 28, 2:06 PM
Unknown Object (File)
Sat, Dec 28, 2:06 PM
Unknown Object (File)
Sat, Dec 28, 2:06 PM
Unknown Object (File)
Sat, Dec 28, 2:06 PM
Unknown Object (File)
Sat, Dec 28, 2:06 PM
Subscribers

Details

Summary

We include the specialRole field in RoleInfo based on shouldIncludeSpecialRoleFieldInRoles which is determined by a code version check.

Test Plan

Hard coded shouldIncludeSpecialRoleFieldInRoles to true/false and observed that the specialRole field was included/excluded:

shouldIncludeSpecialRoleFieldInRoles = true:

image.png (658×1 px, 193 KB)

shouldIncludeSpecialRoleFieldInRoles = false:

image.png (648×1 px, 198 KB)

Diff Detail

Repository
rCOMM Comm
Branch
master
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

Harbormaster returned this revision to the author for changes because remote builds failed.Feb 8 2024, 9:53 AM
Harbormaster failed remote builds in B26658: Diff 36865!
lib/shared/thread-utils.js
889–898

Actually, this approach is too hacky. Encoding the role permissions twice, while not expensive, is still wasteful. We should minimally encode ONCE and just include specialRole field from rolesWithFilteredThreadPermissions

atul published this revision for review.Feb 8 2024, 11:50 AM

few nit stuff inline, feel free to adopt or ignore

lib/shared/thread-utils.js
884–891 ↗(On Diff #36882)

This should be simpler

893–903 ↗(On Diff #36882)

Nit: I personally would prefer if we defined

Object.entries(rawThreadInfoWithoutSpecialRoles.roles).map(
      ([key, role]) => [
        key,
        {
          ...role,
          specialRole: rolesWithFilteredThreadPermissions[key]?.specialRole,
        },
      ],
    ),

as a separate variable then passed that into Object.fromEntries()

but up to you

This revision is now accepted and ready to land.Feb 8 2024, 1:11 PM

rebase to fix CI before addressing @ginsu's feedback

consistency

lib/shared/thread-utils.js
884–891 ↗(On Diff #36882)

I'd prefer to group the early returns even though we have multiple calls to minimallyEncodeRawThreadInfo. I think the repetition is okay in this case.

893–903 ↗(On Diff #36882)

I think I'd prefer to go from one object representation of roles to another object representation of roles without an intermediate array representation.

Using Object.entries with entries within the call seems like a common pattern in codebase.