Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3750602
D9687.id32690.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D9687.id32690.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D9687: [lib] Introduce `threadRolePermissionsBlobToBitmaskArray`
Attached
Detach File
Event Timeline
Log In to Comment