Skip to content

Commit 6a28622

Browse files
authored
fix: correctly parse permission models from json file (#306)
https://coveord.atlassian.net/browse/CDX-1447
1 parent a266d67 commit 6a28622

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[
2+
{
3+
"author": "Sample Group",
4+
"documenttype": "Video",
5+
"duration": 180.72,
6+
"filename": "myvideo.avi",
7+
"language": ["English"],
8+
"permanentid": "my94293video03938permanent93892id",
9+
"sourcetype": "Push",
10+
"title": "My Video",
11+
"compressionType": "LZMA",
12+
"documentId": "http://www.example.com/myvideo.avi",
13+
"fileExtension": ".avi",
14+
"permissions": [
15+
{
16+
"name": "MyPermissionLevel1",
17+
"permissionSets": [
18+
{
19+
"allowAnonymous": false,
20+
"allowedPermissions": [
21+
{
22+
"identity": "SampleGroup",
23+
"identityType": "GrOup"
24+
}
25+
],
26+
"deniedPermissions": [
27+
{
28+
"identity": "[email protected]",
29+
"identityType": "User",
30+
"securityProvider": "My Security Identity Provider"
31+
}
32+
]
33+
}
34+
]
35+
},
36+
{
37+
"name": "MyPermissionLevel2",
38+
"permissionSets": [
39+
{
40+
"allowAnonymous": false,
41+
"allowedPermissions": [
42+
{
43+
"identity": "SampleGroup2",
44+
"identityType": "Group"
45+
}
46+
],
47+
"deniedPermissions": [
48+
{
49+
"identity": "[email protected]",
50+
"identityType": "User"
51+
}
52+
]
53+
}
54+
]
55+
}
56+
]
57+
}
58+
]

src/validation/parseFile.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ describe('parseFile', () => {
9696
await expect(parse(file)).rejects.toThrow(error);
9797
});
9898

99+
it('should support complex permission models', async () => {
100+
const file = join(
101+
pathToStub,
102+
'jsondocuments',
103+
'complexPermissionModel.json'
104+
);
105+
await expect(
106+
parseAndGetDocumentBuilderFromJSONDocument(file)
107+
).resolves.not.toThrow();
108+
});
109+
99110
it('should not throw if allowedPermissions or deniedPermissions are omitted', async () => {
100111
const file = join(pathToStub, 'jsondocuments', 'limitedPermissionSet.json');
101112
await expect(

src/validation/parsePermissions.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,8 @@ class PermissionParser {
4242
new CaseInsensitiveDocument<PrimitivesValues>(permission);
4343

4444
new KnownKeys('permissionsets', caseInsensitivePermission)
45-
.whenExists<PermissionLevel>((permissionLevel) =>
46-
this.processPermissionLevel(permissionLevel)
47-
)
48-
.whenDoesNotExist<PermissionSet>((permissionSet) =>
49-
this.processPermissionSet(permissionSet)
50-
);
45+
.whenExists(() => this.processPermissionLevel(permission))
46+
.whenDoesNotExist(() => this.processPermissionSet(permission));
5147
}
5248
);
5349

0 commit comments

Comments
 (0)