Skip to content

Commit

Permalink
fix: Fix deserializing permissions for BoxFile and BoxFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsocha2 committed Jul 1, 2024
1 parent f17f817 commit 9457b6b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 52 deletions.
1 change: 1 addition & 0 deletions src/intTest/java/com/box/sdk/BoxFileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public void getInfoWithAllFields() {
assertThat(uploadedFileInfo.getItemStatus(), is(equalTo("active")));
assertThat(uploadedFileInfo.getVersion(), not(nullValue()));
assertThat(uploadedFileInfo.getVersion().getVersionID(), not(nullValue()));
assertThat(uploadedFileInfo.getPermissions(), hasItem(BoxFile.Permission.CAN_INVITE_COLLABORATOR));
} finally {
deleteFile(uploadedFile);
}
Expand Down
30 changes: 4 additions & 26 deletions src/main/java/com/box/sdk/BoxFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -1964,32 +1964,10 @@ private EnumSet<Permission> parsePermissions(JsonObject jsonObject) {
if (value.isNull() || !value.asBoolean()) {
continue;
}

switch (member.getName()) {
case "can_download":
permissions.add(Permission.CAN_DOWNLOAD);
break;
case "can_upload":
permissions.add(Permission.CAN_UPLOAD);
break;
case "can_rename":
permissions.add(Permission.CAN_RENAME);
break;
case "can_delete":
permissions.add(Permission.CAN_DELETE);
break;
case "can_share":
permissions.add(Permission.CAN_SHARE);
break;
case "can_set_share_access":
permissions.add(Permission.CAN_SET_SHARE_ACCESS);
break;
case "can_preview":
permissions.add(Permission.CAN_PREVIEW);
break;
case "can_comment":
permissions.add(Permission.CAN_COMMENT);
break;
try {
permissions.add(Permission.fromJSONValue(member.getName()));
} catch (IllegalArgumentException ignored) {
// If the permission is not recognized, we ignore it.
}
}

Expand Down
28 changes: 4 additions & 24 deletions src/main/java/com/box/sdk/BoxFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1745,30 +1745,10 @@ private EnumSet<Permission> parsePermissions(JsonObject jsonObject) {
continue;
}

switch (member.getName()) {
case "can_download":
permissions.add(Permission.CAN_DOWNLOAD);
break;
case "can_upload":
permissions.add(Permission.CAN_UPLOAD);
break;
case "can_rename":
permissions.add(Permission.CAN_RENAME);
break;
case "can_delete":
permissions.add(Permission.CAN_DELETE);
break;
case "can_share":
permissions.add(Permission.CAN_SHARE);
break;
case "can_invite_collaborator":
permissions.add(Permission.CAN_INVITE_COLLABORATOR);
break;
case "can_set_share_access":
permissions.add(Permission.CAN_SET_SHARE_ACCESS);
break;
default:
break;
try {
permissions.add(BoxFolder.Permission.fromJSONValue(member.getName()));
} catch (IllegalArgumentException ignored) {
// If the permission is not recognized, we ignore it.
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/test/Fixtures/BoxFile/GetFileInfo200.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,19 @@
"name": "Top Secret"
},
"disposition_at": "2012-12-12T18:53:43Z",
"is_accessible_via_shared_link": true
"is_accessible_via_shared_link": true,
"permissions": {
"can_annotate": true,
"can_comment": true,
"can_delete": true,
"can_download": true,
"can_invite_collaborator": true,
"can_preview": true,
"can_rename": true,
"can_set_share_access": true,
"can_share": true,
"can_upload": true,
"can_view_annotations_all": true,
"can_view_annotations_self": true
}
}
11 changes: 10 additions & 1 deletion src/test/Fixtures/BoxFolder/GetFolderInfo200.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,14 @@
"definition": "Content that should not be shared outside the company.",
"name": "Top Secret"
},
"is_accessible_via_shared_link": true
"is_accessible_via_shared_link": true,
"permissions": {
"can_delete": true,
"can_download": true,
"can_invite_collaborator": true,
"can_rename": true,
"can_set_share_access": true,
"can_share": true,
"can_upload": true
}
}
2 changes: 2 additions & 0 deletions src/test/java/com/box/sdk/BoxFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -179,6 +180,7 @@ public void testGetFileInfoSucceeds() throws ParseException {
assertTrue(info.getHasCollaborations());
assertEquals(info.getDispositionAt(), BoxDateFormat.parse("2012-12-12T18:53:43Z"));
assertTrue(info.getIsAccessibleViaSharedLink());
assertEquals(info.getPermissions(), EnumSet.allOf(BoxFile.Permission.class));
}

@Test(expected = BoxDeserializationException.class)
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/box/sdk/BoxFolderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -488,6 +489,7 @@ public void testGetAllRootFolderItemsSucceeds() {
assertEquals(ownedByUserLogin, rootFolderInfo.getOwnedBy().getLogin());
assertEquals(modifiedByLogin, rootFolderInfo.getModifiedBy().getLogin());
assertEquals(modifiedByName, rootFolderInfo.getModifiedBy().getName());
assertEquals(rootFolderInfo.getPermissions(), EnumSet.allOf(BoxFolder.Permission.class));
}

@Test
Expand Down

0 comments on commit 9457b6b

Please sign in to comment.