Page MenuHomePhabricator

[lib] Add optional specialRole field to RoleInfo
ClosedPublic

Authored by atul on Nov 30 2023, 1:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 20, 5:12 PM
Unknown Object (File)
Wed, Nov 20, 4:21 AM
Unknown Object (File)
Tue, Nov 19, 7:09 PM
Unknown Object (File)
Thu, Nov 14, 1:45 PM
Unknown Object (File)
Thu, Nov 14, 1:36 PM
Unknown Object (File)
Sat, Nov 9, 5:21 PM
Unknown Object (File)
Fri, Nov 8, 10:02 PM
Unknown Object (File)
Fri, Nov 8, 7:18 PM
Subscribers

Details

Summary

We want to introduce a specialRole field to the RoleInfo/LegacyRoleInfo type so we can include it when fetching threads/roles, and going forward perform checks on role.specialRole instead of relying on role.isDefault since this won't extend to checking for other special roles (like Admins).

This diff introduces this field as specialRole?: ?number to prevent flow errors. Towards the end of this stack, I plan to change this type to specialRole: ?number so we always include specialRole, whether it is a number or null.

Part of ENG-5994

Test Plan

Ran flow

Diff Detail

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

Event Timeline

rohan held this revision as a draft.
rohan published this revision for review.Nov 30 2023, 1:32 PM

Use more specific type for specialRole field

tomek added inline comments.
lib/types/thread-types.js
95 ↗(On Diff #34107)

Just to make sure: are the type and validator of minimally-encoded versions also updated?

This revision is now accepted and ready to land.Dec 1 2023, 7:52 AM
lib/types/thread-types.js
95 ↗(On Diff #34107)

Yes they should be. MinimallyEncodedRoleInfo uses LegacyRoleInfo

export type MinimallyEncodedRoleInfo = $ReadOnly<{
  ...LegacyRoleInfo,
  +minimallyEncoded: true,
  +permissions: $ReadOnlyArray<string>,
}>;

(cc @atul in case I missed something)

lib/types/thread-types.js
95 ↗(On Diff #34107)

Yup, looks right! Since MinimallyEncodedRoleInfo is "derived" from LegacyRoleInfo, any changes to LegacyRoleInfo should be reflected in MinimallyEncodedRoleInfo.

atul edited reviewers, added: rohan; removed: atul.
atul retitled this revision from [lib] Add optional speciaRole field to RoleInfo to [lib] Add optional specialRole field to RoleInfo.Feb 5 2024, 12:48 PM
This revision was landed with ongoing or failed builds.Feb 6 2024, 10:17 AM
This revision was automatically updated to reflect the committed changes.

I modified this diff before landing to only modify RoleInfo (formerly MinimallyEncodedRoleInfo) since I figured we could ignore LegacyRoleInfo going forward...

However, as I previously realized and then forgot, we DO need the specialRole field LegacyRoleInfo because on the keyserver we're still constructing Legacy "everything" and then POSSIBLY minimally encoding for new clients. So we'll need specialRole in the LegacyRoleInfo that's being initially constructed so it's available when being converted to RoleInfo.

That said, we will never want a LegacyRoleInfo with specialRole on ANY client because that would lead to issues with validation. So what we'll want to do is:

  1. Introduce ServerLegacyRoleInfo to be used by keyserver to handle fetching from database, etc
  2. Based on codeVersion check either

Old clients: strip out specialRole field to go from ServerLegacyRoleInfo -> ClientLegacyRoleInfo
New clients: minimallyEncode* ServerLegacyRoleInfo -> RoleInfo WHILE RETAINING specialRole field.