Page MenuHomePhabricator

D9689.diff
No OneTemporary

D9689.diff

diff --git a/lib/permissions/minimally-encoded-thread-permissions.js b/lib/permissions/minimally-encoded-thread-permissions.js
--- a/lib/permissions/minimally-encoded-thread-permissions.js
+++ b/lib/permissions/minimally-encoded-thread-permissions.js
@@ -169,10 +169,21 @@
): $ReadOnlyArray<string> =>
Object.keys(threadRolePermissionsBlob).map(rolePermissionToBitmaskHex);
+const decodeThreadRolePermissionsBitmaskArray = (
+ threadRolePermissionsBitmaskArray: $ReadOnlyArray<string>,
+): ThreadRolePermissionsBlob =>
+ Object.fromEntries(
+ threadRolePermissionsBitmaskArray.map(bitmask => [
+ decodeRolePermissionBitmask(bitmask),
+ true,
+ ]),
+ );
+
export {
permissionsToBitmaskHex,
hasPermission,
rolePermissionToBitmaskHex,
decodeRolePermissionBitmask,
threadRolePermissionsBlobToBitmaskArray,
+ decodeThreadRolePermissionsBitmaskArray,
};
diff --git a/lib/permissions/minimally-encoded-thread-permissions.test.js b/lib/permissions/minimally-encoded-thread-permissions.test.js
--- a/lib/permissions/minimally-encoded-thread-permissions.test.js
+++ b/lib/permissions/minimally-encoded-thread-permissions.test.js
@@ -2,6 +2,7 @@
import {
decodeRolePermissionBitmask,
+ decodeThreadRolePermissionsBitmaskArray,
hasPermission,
permissionsToBitmaskHex,
rolePermissionToBitmaskHex,
@@ -128,82 +129,95 @@
});
});
-describe('threadRolePermissionsBlobToBitmaskArray', () => {
- const permissions: ThreadRolePermissionsBlob = {
- add_members: true,
- child_open_join_thread: true,
- create_sidebars: true,
- create_subthreads: true,
- descendant_open_know_of: true,
- descendant_open_visible: true,
- descendant_opentoplevel_join_thread: true,
- edit_entries: true,
- edit_message: true,
- edit_permissions: true,
- edit_thread: true,
- edit_thread_avatar: true,
- edit_thread_color: true,
- edit_thread_description: true,
- know_of: true,
- leave_thread: true,
- react_to_message: true,
- remove_members: true,
- visible: true,
- voiced: true,
- open_know_of: true,
- open_visible: true,
- opentoplevel_join_thread: true,
- toplevel_know_of: true,
- toplevel_visible: true,
- opentoplevel_know_of: true,
- opentoplevel_visible: true,
- child_know_of: true,
- child_visible: true,
- child_opentoplevel_join_thread: true,
- child_toplevel_know_of: true,
- child_toplevel_visible: true,
- child_opentoplevel_know_of: true,
- child_opentoplevel_visible: true,
- };
+const threadRolePermissionsBlob: ThreadRolePermissionsBlob = {
+ add_members: true,
+ child_open_join_thread: true,
+ create_sidebars: true,
+ create_subthreads: true,
+ descendant_open_know_of: true,
+ descendant_open_visible: true,
+ descendant_opentoplevel_join_thread: true,
+ edit_entries: true,
+ edit_message: true,
+ edit_permissions: true,
+ edit_thread: true,
+ edit_thread_avatar: true,
+ edit_thread_color: true,
+ edit_thread_description: true,
+ know_of: true,
+ leave_thread: true,
+ react_to_message: true,
+ remove_members: true,
+ visible: true,
+ voiced: true,
+ open_know_of: true,
+ open_visible: true,
+ opentoplevel_join_thread: true,
+ toplevel_know_of: true,
+ toplevel_visible: true,
+ opentoplevel_know_of: true,
+ opentoplevel_visible: true,
+ child_know_of: true,
+ child_visible: true,
+ child_opentoplevel_join_thread: true,
+ child_toplevel_know_of: true,
+ child_toplevel_visible: true,
+ child_opentoplevel_know_of: true,
+ child_opentoplevel_visible: true,
+};
+
+const threadRolePermissionsBitmaskArray = [
+ '0c0',
+ '0a9',
+ '090',
+ '080',
+ '005',
+ '015',
+ '0a7',
+ '030',
+ '110',
+ '0b0',
+ '040',
+ '120',
+ '060',
+ '050',
+ '000',
+ '0f0',
+ '100',
+ '0d0',
+ '010',
+ '020',
+ '001',
+ '011',
+ '0a3',
+ '002',
+ '012',
+ '003',
+ '013',
+ '008',
+ '018',
+ '0ab',
+ '00a',
+ '01a',
+ '00b',
+ '01b',
+];
+describe('threadRolePermissionsBlobToBitmaskArray', () => {
it('should encode threadRolePermissionsBlob as bitmask array', () => {
- const threadRolePermissionsBitmaskArray =
- threadRolePermissionsBlobToBitmaskArray(permissions);
- expect(threadRolePermissionsBitmaskArray).toEqual([
- '0c0',
- '0a9',
- '090',
- '080',
- '005',
- '015',
- '0a7',
- '030',
- '110',
- '0b0',
- '040',
- '120',
- '060',
- '050',
- '000',
- '0f0',
- '100',
- '0d0',
- '010',
- '020',
- '001',
- '011',
- '0a3',
- '002',
- '012',
- '003',
- '013',
- '008',
- '018',
- '0ab',
- '00a',
- '01a',
- '00b',
- '01b',
- ]);
+ const arr = threadRolePermissionsBlobToBitmaskArray(
+ threadRolePermissionsBlob,
+ );
+ expect(arr).toEqual(threadRolePermissionsBitmaskArray);
+ });
+});
+
+describe('decodeThreadRolePermissionsBitmaskArray', () => {
+ it('should decode threadRolePermissionsBitmaskArray', () => {
+ expect(
+ decodeThreadRolePermissionsBitmaskArray(
+ threadRolePermissionsBitmaskArray,
+ ),
+ ).toEqual(threadRolePermissionsBlob);
});
});

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 20, 5:04 PM (19 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2540013
Default Alt Text
D9689.diff (5 KB)

Event Timeline