Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3158206
D10313.id34537.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10313.id34537.diff
View Options
diff --git a/lib/utils/thread-ops-utils.js b/lib/utils/thread-ops-utils.js
--- a/lib/utils/thread-ops-utils.js
+++ b/lib/utils/thread-ops-utils.js
@@ -2,20 +2,26 @@
import invariant from 'invariant';
-import { minimallyEncodedMemberInfoValidator } from '../permissions/minimally-encoded-thread-permissions-validators.js';
+import {
+ minimallyEncodedMemberInfoValidator,
+ minimallyEncodedRoleInfoValidator,
+} from '../permissions/minimally-encoded-thread-permissions-validators.js';
import type {
MinimallyEncodedMemberInfo,
MinimallyEncodedRawThreadInfo,
+ MinimallyEncodedRoleInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import {
decodeMinimallyEncodedRawThreadInfo,
minimallyEncodeMemberInfo,
+ minimallyEncodeRoleInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import { assertThreadType } from '../types/thread-types-enum.js';
import {
type ClientDBThreadInfo,
legacyMemberInfoValidator,
type LegacyRawThreadInfo,
+ legacyRoleInfoValidator,
type RawThreadInfo,
} from '../types/thread-types.js';
@@ -52,6 +58,27 @@
: minimallyEncodeMemberInfo(rawMember),
);
+ // 2. Validate and potentially minimally encode `rawRoles`.
+ const rawRoles = JSON.parse(clientDBThreadInfo.roles);
+ Object.keys(rawRoles).forEach(idx =>
+ invariant(
+ minimallyEncodedRoleInfoValidator.is(rawRoles[idx]) ||
+ legacyRoleInfoValidator.is(rawRoles[idx]),
+ 'rawRole must be correctly formed [MinimallyEncoded/Legacy]RoleInfo',
+ ),
+ );
+ const minimallyEncodedRoles: { +[id: string]: MinimallyEncodedRoleInfo } =
+ Object.keys(rawRoles).reduce(
+ (acc: { [string]: MinimallyEncodedRoleInfo }, roleID: string) => {
+ const roleInfo = rawRoles[roleID];
+ acc[roleID] = roleInfo.minimallyEncoded
+ ? roleInfo
+ : minimallyEncodeRoleInfo(roleInfo);
+ return acc;
+ },
+ {},
+ );
+
let rawThreadInfo: MinimallyEncodedRawThreadInfo = {
minimallyEncoded: true,
id: clientDBThreadInfo.id,
@@ -64,7 +91,7 @@
containingThreadID: clientDBThreadInfo.containingThreadID,
community: clientDBThreadInfo.community,
members: minimallyEncodedMembers,
- roles: JSON.parse(clientDBThreadInfo.roles),
+ roles: minimallyEncodedRoles,
currentUser: JSON.parse(clientDBThreadInfo.currentUser),
repliesCount: clientDBThreadInfo.repliesCount,
pinnedCount: clientDBThreadInfo.pinnedCount,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 6, 9:33 PM (22 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2432613
Default Alt Text
D10313.id34537.diff (2 KB)
Attached To
Mode
D10313: [lib] Update `convertClientDBThreadInfoToRawThreadInfo` to validate `RoleInfo`s
Attached
Detach File
Event Timeline
Log In to Comment