Page MenuHomePhabricator

D9924.diff
No OneTemporary

D9924.diff

diff --git a/lib/permissions/thread-permissions.js b/lib/permissions/thread-permissions.js
--- a/lib/permissions/thread-permissions.js
+++ b/lib/permissions/thread-permissions.js
@@ -8,13 +8,14 @@
threadPermissionFilterPrefixes,
threadPermissionPropagationPrefixes,
threadPermissions,
-} from '../types/thread-permission-types.js';
-import type {
- ThreadPermission,
- ThreadPermissionInfo,
- ThreadPermissionsBlob,
- ThreadPermissionsInfo,
- ThreadRolePermissionsBlob,
+ configurableCommunityPermissions,
+ userSurfacedPermissions,
+ type UserSurfacedPermission,
+ type ThreadPermission,
+ type ThreadPermissionInfo,
+ type ThreadPermissionsBlob,
+ type ThreadPermissionsInfo,
+ type ThreadRolePermissionsBlob,
} from '../types/thread-permission-types.js';
import { type ThreadType, threadTypes } from '../types/thread-types-enum.js';
@@ -153,6 +154,15 @@
}
}
+function getThreadPermissionBlobFromUserSurfacedPermission(
+ userSurfacedPermission: UserSurfacedPermission,
+): ThreadRolePermissionsBlob {
+ const permissions = Array.from(
+ configurableCommunityPermissions[userSurfacedPermission],
+ );
+ return Object.fromEntries(permissions.map(permission => [permission, true]));
+}
+
export type RolePermissionBlobs = {
+Members: ThreadRolePermissionsBlob,
+Admins?: ThreadRolePermissionsBlob,
@@ -165,50 +175,51 @@
const TOP_LEVEL_DESCENDANT = DESCENDANT + TOP_LEVEL;
const OPEN_TOP_LEVEL_DESCENDANT = DESCENDANT + OPEN_TOP_LEVEL;
+const editCalendar = getThreadPermissionBlobFromUserSurfacedPermission(
+ userSurfacedPermissions.EDIT_CALENDAR,
+);
+const createAndEditChannels = getThreadPermissionBlobFromUserSurfacedPermission(
+ userSurfacedPermissions.CREATE_AND_EDIT_CHANNELS,
+);
+const addMembers = getThreadPermissionBlobFromUserSurfacedPermission(
+ userSurfacedPermissions.ADD_MEMBERS,
+);
+const reactToMessages = getThreadPermissionBlobFromUserSurfacedPermission(
+ userSurfacedPermissions.REACT_TO_MESSAGES,
+);
+const editMessages = getThreadPermissionBlobFromUserSurfacedPermission(
+ userSurfacedPermissions.EDIT_MESSAGES,
+);
+
const voicedPermissions = {
- [threadPermissions.VOICED]: true,
- [threadPermissions.EDIT_ENTRIES]: true,
- [threadPermissions.EDIT_THREAD_NAME]: true,
- [threadPermissions.EDIT_THREAD_COLOR]: true,
- [threadPermissions.EDIT_THREAD_DESCRIPTION]: true,
- [threadPermissions.EDIT_THREAD_AVATAR]: true,
- [threadPermissions.CREATE_SUBCHANNELS]: true,
+ ...editCalendar,
+ ...createAndEditChannels,
[threadPermissions.ADD_MEMBERS]: true,
+ [threadPermissions.VOICED]: true,
};
function getRolePermissionBlobsForCommunityRoot(
threadType: ThreadType,
): RolePermissionBlobs {
- const openDescendantKnowOf = OPEN_DESCENDANT + threadPermissions.KNOW_OF;
- const openDescendantVisible = OPEN_DESCENDANT + threadPermissions.VISIBLE;
- const openTopLevelDescendantJoinThread =
- OPEN_TOP_LEVEL_DESCENDANT + threadPermissions.JOIN_THREAD;
- const openChildJoinThread = OPEN_CHILD + threadPermissions.JOIN_THREAD;
- const openChildAddMembers = OPEN_CHILD + threadPermissions.ADD_MEMBERS;
+ const genesisUniversalPermissions = getUniversalCommunityRootPermissionsBlob(
+ threadTypes.GENESIS,
+ );
+ const memberUniversalPermissions =
+ getUniversalCommunityRootPermissionsBlob(threadType);
- const genesisMemberPermissions = {
- [threadPermissions.KNOW_OF]: true,
- [threadPermissions.VISIBLE]: true,
- [openDescendantKnowOf]: true,
- [openDescendantVisible]: true,
- [openTopLevelDescendantJoinThread]: true,
- };
const baseMemberPermissions = {
- ...genesisMemberPermissions,
- [threadPermissions.REACT_TO_MESSAGE]: true,
- [threadPermissions.EDIT_MESSAGE]: true,
- [threadPermissions.LEAVE_THREAD]: true,
- [threadPermissions.CREATE_SIDEBARS]: true,
- [threadPermissions.ADD_MEMBERS]: true,
- [openChildJoinThread]: true,
- [openChildAddMembers]: true,
+ ...reactToMessages,
+ ...editMessages,
+ ...addMembers,
+ ...memberUniversalPermissions,
+ ...genesisUniversalPermissions,
};
let memberPermissions;
if (threadType === threadTypes.COMMUNITY_ANNOUNCEMENT_ROOT) {
memberPermissions = baseMemberPermissions;
} else if (threadType === threadTypes.GENESIS) {
- memberPermissions = genesisMemberPermissions;
+ memberPermissions = genesisUniversalPermissions;
} else {
memberPermissions = {
...baseMemberPermissions,
@@ -383,10 +394,10 @@
threadType === threadTypes.COMMUNITY_SECRET_SUBTHREAD
) {
const memberPermissions = {
+ ...voicedPermissions,
+ ...subthreadBasePermissions,
[threadPermissions.REMOVE_MEMBERS]: true,
[threadPermissions.EDIT_PERMISSIONS]: true,
- ...subthreadBasePermissions,
- ...voicedPermissions,
};
return {
Members: memberPermissions,

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 6:42 AM (5 m, 37 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2690494
Default Alt Text
D9924.diff (4 KB)

Event Timeline