Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3533524
D12543.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D12543.diff
View Options
diff --git a/keyserver/src/fetchers/thread-permission-fetchers.js b/keyserver/src/fetchers/thread-permission-fetchers.js
--- a/keyserver/src/fetchers/thread-permission-fetchers.js
+++ b/keyserver/src/fetchers/thread-permission-fetchers.js
@@ -1,5 +1,8 @@
// @flow
+import _keyBy from 'lodash/fp/keyBy.js';
+import _mapValues from 'lodash/fp/mapValues.js';
+
import genesis from 'lib/facts/genesis.js';
import {
permissionLookup,
@@ -8,9 +11,16 @@
} from 'lib/permissions/thread-permissions.js';
import { relationshipBlockedInEitherDirection } from 'lib/shared/relationship-utils.js';
import {
- threadFrozenDueToBlock,
permissionsDisabledByBlock,
+ threadIsWithBlockedUserOnlyWithoutAdminRoleCheck,
+ threadMembersWithoutAddedAdmin,
+ roleIsAdminRole,
} from 'lib/shared/thread-utils.js';
+import type {
+ MemberInfoWithPermissions,
+ RelativeMemberInfo,
+ ThreadInfo,
+} from 'lib/types/minimally-encoded-thread-permissions-types.js';
import { userRelationshipStatus } from 'lib/types/relationship-types.js';
import type {
ThreadPermission,
@@ -18,6 +28,7 @@
ThreadRolePermissionsBlob,
} from 'lib/types/thread-permission-types.js';
import type { ThreadType } from 'lib/types/thread-types-enum.js';
+import { values } from 'lib/utils/objects.js';
import { fetchThreadInfos } from './thread-fetchers.js';
import { fetchKnownUserInfos } from './user-fetchers.js';
@@ -157,16 +168,71 @@
fetchKnownUserInfos(viewer),
]);
+ const communityThreadIDs = new Set<string>();
+ for (const threadInfo of values(threadInfos)) {
+ const communityRootThreadID = threadInfo.community;
+ if (!communityRootThreadID) {
+ continue;
+ }
+ communityThreadIDs.add(communityRootThreadID);
+ }
+
+ const { threadInfos: communityThreadInfos } = await fetchThreadInfos(viewer, {
+ threadIDs: communityThreadIDs,
+ });
+
+ const combinedThreadInfos = {
+ ...threadInfos,
+ ...communityThreadInfos,
+ };
+
+ const communityRootMembersToRole = _mapValues((threadInfo: ThreadInfo) => {
+ const keyedMembers = _keyBy('id')(threadInfo.members);
+ const keyedMembersToRole = _mapValues(
+ (member: MemberInfoWithPermissions | RelativeMemberInfo) => {
+ return member.role ? threadInfo.roles[member.role] : null;
+ },
+ )(keyedMembers);
+ return keyedMembersToRole;
+ })(combinedThreadInfos);
+
for (const threadID in threadInfos) {
- const blockedThread = threadFrozenDueToBlock(
- threadInfos[threadID],
+ const threadInfo = threadInfos[threadID];
+
+ if (
+ threadInfo.community &&
+ !(threadInfo.community in communityRootMembersToRole)
+ ) {
+ threadIDsWithDisabledPermissions.add(threadID);
+ continue;
+ }
+
+ // We fall back to threadID because the only case where threadInfo.community
+ // is not set is for a community root, in which case the thread's community
+ // root is the thread itself.
+ const communityMembersToRole =
+ communityRootMembersToRole[threadInfo.community ?? threadID];
+
+ const memberHasAdminRole = threadMembersWithoutAddedAdmin(threadInfo).some(
+ m => roleIsAdminRole(communityMembersToRole?.[m.id]),
+ );
+
+ if (memberHasAdminRole) {
+ continue;
+ }
+
+ const blockedThread = threadIsWithBlockedUserOnlyWithoutAdminRoleCheck(
+ threadInfo,
viewer.id,
userInfos,
+ false,
);
+
if (blockedThread) {
threadIDsWithDisabledPermissions.add(threadID);
}
}
+
return threadIDsWithDisabledPermissions;
}
diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js
--- a/lib/shared/thread-utils.js
+++ b/lib/shared/thread-utils.js
@@ -1013,7 +1013,7 @@
}
function threadIsWithBlockedUserOnlyWithoutAdminRoleCheck(
- threadInfo: ThreadInfo,
+ threadInfo: ThreadInfo | RawThreadInfo | LegacyRawThreadInfo,
viewerID: ?string,
userInfos: UserInfos,
checkOnlyViewerBlock: boolean,
@@ -1760,6 +1760,7 @@
threadUIName,
threadInfoFromRawThreadInfo,
threadTypeDescriptions,
+ threadIsWithBlockedUserOnlyWithoutAdminRoleCheck,
memberHasAdminPowers,
roleIsDefaultRole,
roleIsAdminRole,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 11:40 AM (11 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2704074
Default Alt Text
D12543.diff (4 KB)
Attached To
Mode
D12543: [keyserver] Use `threadIsWithBlockedUserOnlyWithoutAdminRoleCheck` instead of `threadFrozenDueToBlock` in `checkThreadsFrozen`
Attached
Detach File
Event Timeline
Log In to Comment