Page MenuHomePhabricator

D9687.id32690.diff
No OneTemporary

D9687.id32690.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
@@ -6,6 +6,7 @@
import type {
ThreadPermission,
ThreadPermissionsInfo,
+ ThreadRolePermissionsBlob,
} from '../types/thread-permission-types.js';
import { entries, invertObjectToMap } from '../utils/objects.js';
@@ -163,9 +164,15 @@
return `${propagationPrefixString}${filterPrefixString}${basePermissionString}`;
};
+const threadRolePermissionsBlobToBitmaskArray = (
+ threadRolePermissionsBlob: ThreadRolePermissionsBlob,
+): $ReadOnlyArray<string> =>
+ Object.keys(threadRolePermissionsBlob).map(rolePermissionToBitmaskHex);
+
export {
permissionsToBitmaskHex,
hasPermission,
rolePermissionToBitmaskHex,
decodeRolePermissionBitmask,
+ threadRolePermissionsBlobToBitmaskArray,
};
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
@@ -5,7 +5,9 @@
hasPermission,
permissionsToBitmaskHex,
rolePermissionToBitmaskHex,
+ threadRolePermissionsBlobToBitmaskArray,
} from './minimally-encoded-thread-permissions.js';
+import type { ThreadRolePermissionsBlob } from '../types/thread-permission-types.js';
describe('minimallyEncodedThreadPermissions', () => {
const permissions = {
@@ -125,3 +127,83 @@
expect(decodeRolePermissionBitmask('008')).toBe('child_know_of');
});
});
+
+describe('threadRolePermissionsBlobToRolePermissionBitmaskArray', () => {
+ 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,
+ };
+
+ 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',
+ ]);
+ });
+});

File Metadata

Mime Type
text/plain
Expires
Fri, Jan 10, 10:40 PM (18 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2856245
Default Alt Text
D9687.id32690.diff (3 KB)

Event Timeline