Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3356653
D7363.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
D7363.diff
View Options
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
@@ -2,6 +2,8 @@
import invariant from 'invariant';
import _find from 'lodash/fp/find.js';
+import _mapValues from 'lodash/fp/mapValues.js';
+import _omitBy from 'lodash/fp/omitBy.js';
import * as React from 'react';
import { generatePendingThreadColor } from './color-utils.js';
@@ -710,6 +712,15 @@
const filterDetailedThreadEditPermissions =
options?.filterDetailedThreadEditPermissions;
+ const filterThreadPermissions = _omitBy(
+ (v, k) =>
+ filterDetailedThreadEditPermissions &&
+ [
+ threadPermissions.EDIT_THREAD_COLOR,
+ threadPermissions.EDIT_THREAD_DESCRIPTION,
+ ].includes(k),
+ );
+
const members = [];
let currentUser;
for (const serverMember of serverThreadInfo.members) {
@@ -728,10 +739,9 @@
) {
continue;
}
- const memberPermissions = filterThreadEditDetailedPermissions(
- serverMember.permissions,
- filterDetailedThreadEditPermissions,
- );
+
+ const memberPermissions = filterThreadPermissions(serverMember.permissions);
+
members.push({
id: serverMember.id,
role: serverMember.role,
@@ -752,9 +762,8 @@
if (currentUser) {
currentUserPermissions = currentUser.permissions;
} else {
- currentUserPermissions = filterThreadEditDetailedPermissions(
+ currentUserPermissions = filterThreadPermissions(
getAllThreadPermissions(null, serverThreadInfo.id),
- filterDetailedThreadEditPermissions,
);
currentUser = {
role: null,
@@ -779,6 +788,11 @@
type = shimThreadTypes[type];
}
+ const rolesWithFilteredThreadPermissions = _mapValues(role => ({
+ ...role,
+ permissions: filterThreadPermissions(role.permissions),
+ }))(serverThreadInfo.roles);
+
let rawThreadInfo: any = {
id: serverThreadInfo.id,
type,
@@ -788,7 +802,7 @@
creationTime: serverThreadInfo.creationTime,
parentThreadID: serverThreadInfo.parentThreadID,
members,
- roles: serverThreadInfo.roles,
+ roles: rolesWithFilteredThreadPermissions,
currentUser,
repliesCount: serverThreadInfo.repliesCount,
};
@@ -815,18 +829,6 @@
return rawThreadInfo;
}
-function filterThreadEditDetailedPermissions(
- permissions: ThreadPermissionsInfo,
- shouldFilter: ?boolean,
-): ThreadPermissionsInfo {
- if (!shouldFilter) {
- return permissions;
- }
- const { edit_thread_color, edit_thread_description, ...newPermissions } =
- permissions;
- return newPermissions;
-}
-
function threadUIName(threadInfo: ThreadInfo): string | ThreadEntity {
if (threadInfo.name) {
return firstLine(threadInfo.name);
@@ -1571,7 +1573,6 @@
threadFrozenDueToBlock,
threadFrozenDueToViewerBlock,
rawThreadInfoFromServerThreadInfo,
- filterThreadEditDetailedPermissions,
threadUIName,
threadInfoFromRawThreadInfo,
threadTypeDescriptions,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 7:48 PM (21 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577170
Default Alt Text
D7363.diff (2 KB)
Attached To
Mode
D7363: [lib] Replace `filterThreadEditDetailedPermissions` with `filterThreadPermissions`
Attached
Detach File
Event Timeline
Log In to Comment