Page MenuHomePhabricator

D11252.diff
No OneTemporary

D11252.diff

diff --git a/lib/permissions/minimally-encoded-thread-permissions-test-data.js b/lib/permissions/minimally-encoded-thread-permissions-test-data.js
--- a/lib/permissions/minimally-encoded-thread-permissions-test-data.js
+++ b/lib/permissions/minimally-encoded-thread-permissions-test-data.js
@@ -1,5 +1,6 @@
// @flow
+import { specialRoles } from './special-roles.js';
import type { RawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import { threadTypes } from '../types/thread-types-enum.js';
import type { LegacyRawThreadInfo } from '../types/thread-types.js';
@@ -352,6 +353,7 @@
'0a9',
],
isDefault: true,
+ specialRole: specialRoles.DEFAULT_ROLE,
},
},
currentUser: {
diff --git a/lib/permissions/special-roles.js b/lib/permissions/special-roles.js
--- a/lib/permissions/special-roles.js
+++ b/lib/permissions/special-roles.js
@@ -38,8 +38,12 @@
...role,
specialRole: specialRoles.ADMIN_ROLE,
};
+ } else {
+ return {
+ ...role,
+ specialRole: null,
+ };
}
- return role;
}
function patchRawThreadInfoWithSpecialRole(
diff --git a/lib/permissions/special-roles.test.js b/lib/permissions/special-roles.test.js
--- a/lib/permissions/special-roles.test.js
+++ b/lib/permissions/special-roles.test.js
@@ -17,6 +17,7 @@
name: 'roleName',
permissions: ['abc', 'def'],
isDefault: true,
+ specialRole: specialRoles.DEFAULT_ROLE,
};
const patchedRole = patchRoleInfoWithSpecialRole(role);
expect(patchedRole.specialRole).toBe(specialRoles.DEFAULT_ROLE);
@@ -29,21 +30,23 @@
name: 'Admins',
permissions: ['abc', 'def'],
isDefault: false,
+ specialRole: specialRoles.ADMIN_ROLE,
};
const patchedRole = patchRoleInfoWithSpecialRole(role);
expect(patchedRole.specialRole).toBe(specialRoles.ADMIN_ROLE);
});
- it('should correctly set undefined', () => {
+ it('should correctly set null', () => {
const role: RoleInfo = {
minimallyEncoded: true,
id: 'roleID',
name: 'BLAH',
permissions: ['abc', 'def'],
isDefault: false,
+ specialRole: null,
};
const patchedRole = patchRoleInfoWithSpecialRole(role);
- expect(patchedRole.specialRole).toBe(undefined);
+ expect(patchedRole.specialRole).toBe(null);
});
});
@@ -82,6 +85,7 @@
name: 'Members',
permissions: ['000', '010', '005', '015', '0a7'],
isDefault: true,
+ specialRole: specialRoles.DEFAULT_ROLE,
minimallyEncoded: true,
},
'256|83796': {
@@ -128,6 +132,7 @@
'156',
],
isDefault: false,
+ specialRole: specialRoles.ADMIN_ROLE,
minimallyEncoded: true,
},
},
@@ -193,6 +198,7 @@
'0a9',
],
isDefault: false,
+ specialRole: null,
minimallyEncoded: true,
},
},
@@ -222,6 +228,6 @@
);
expect(
patchedRawThreadInfos['256|83814'].roles['256|83815'].specialRole,
- ).toBe(undefined);
+ ).toBe(null);
});
});
diff --git a/lib/reducers/calendar-filters-reducer.test.js b/lib/reducers/calendar-filters-reducer.test.js
--- a/lib/reducers/calendar-filters-reducer.test.js
+++ b/lib/reducers/calendar-filters-reducer.test.js
@@ -5,6 +5,7 @@
removeKeyserverThreadIDsFromFilterList,
} from './calendar-filters-reducer.js';
import { keyserverAuthActionTypes } from '../actions/user-actions.js';
+import { specialRoles } from '../permissions/special-roles.js';
import type { RawMessageInfo } from '../types/message-types.js';
import type { ThreadStore } from '../types/thread-types';
@@ -49,6 +50,7 @@
name: 'Members',
permissions: ['000', '010', '005', '015', '0a7'],
isDefault: true,
+ specialRole: specialRoles.DEFAULT_ROLE,
minimallyEncoded: true,
},
'256|83796': {
@@ -56,6 +58,7 @@
name: 'Admins',
permissions: ['000', '010', '005', '015', '0a7'],
isDefault: false,
+ specialRole: specialRoles.ADMIN_ROLE,
minimallyEncoded: true,
},
},
@@ -106,6 +109,7 @@
name: 'Members',
permissions: ['000', '010', '005', '015', '0a7'],
isDefault: true,
+ specialRole: specialRoles.DEFAULT_ROLE,
minimallyEncoded: true,
},
},
diff --git a/lib/shared/thread-utils.test.js b/lib/shared/thread-utils.test.js
--- a/lib/shared/thread-utils.test.js
+++ b/lib/shared/thread-utils.test.js
@@ -5,6 +5,7 @@
threadInfoFromRawThreadInfo,
} from './thread-utils.js';
import { threadInfoValidator } from '../permissions/minimally-encoded-thread-permissions-validators.js';
+import { specialRoles } from '../permissions/special-roles.js';
import type { RawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import { threadTypes } from '../types/thread-types-enum.js';
import type { UserInfos } from '../types/user-types.js';
@@ -108,6 +109,7 @@
name: 'Members',
permissions: ['000', '010', '005', '015', '0a7'],
isDefault: true,
+ specialRole: specialRoles.DEFAULT_ROLE,
minimallyEncoded: true,
},
'83796': {
@@ -154,6 +156,7 @@
'156',
],
isDefault: false,
+ specialRole: specialRoles.ADMIN_ROLE,
minimallyEncoded: true,
},
},
diff --git a/lib/types/minimally-encoded-thread-permissions-types.js b/lib/types/minimally-encoded-thread-permissions-types.js
--- a/lib/types/minimally-encoded-thread-permissions-types.js
+++ b/lib/types/minimally-encoded-thread-permissions-types.js
@@ -18,13 +18,15 @@
threadRolePermissionsBlobToBitmaskArray,
} from '../permissions/minimally-encoded-thread-permissions.js';
import type { SpecialRole } from '../permissions/special-roles.js';
+import { specialRoles } from '../permissions/special-roles.js';
+import { roleIsAdminRole, roleIsDefaultRole } from '../shared/thread-utils.js';
import type { ThreadEntity } from '../utils/entity-text.js';
export type RoleInfo = $ReadOnly<{
...ClientLegacyRoleInfo,
+minimallyEncoded: true,
+permissions: $ReadOnlyArray<string>,
- +specialRole?: ?SpecialRole,
+ +specialRole: ?SpecialRole,
}>;
const minimallyEncodeRoleInfo = (roleInfo: ClientLegacyRoleInfo): RoleInfo => {
@@ -32,10 +34,17 @@
!('minimallyEncoded' in roleInfo),
'roleInfo is already minimally encoded.',
);
+ let specialRole: ?SpecialRole;
+ if (roleIsDefaultRole(roleInfo)) {
+ specialRole = specialRoles.DEFAULT_ROLE;
+ } else if (roleIsAdminRole(roleInfo)) {
+ specialRole = specialRoles.ADMIN_ROLE;
+ }
return {
...roleInfo,
minimallyEncoded: true,
permissions: threadRolePermissionsBlobToBitmaskArray(roleInfo.permissions),
+ specialRole,
};
};

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 25, 7:47 AM (7 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2701957
Default Alt Text
D11252.diff (6 KB)

Event Timeline