diff --git a/src/intTest/java/com/box/sdk/BoxCollaborationIT.java b/src/intTest/java/com/box/sdk/BoxCollaborationIT.java index 76d5ce36d..a0eb957dc 100644 --- a/src/intTest/java/com/box/sdk/BoxCollaborationIT.java +++ b/src/intTest/java/com/box/sdk/BoxCollaborationIT.java @@ -2,7 +2,6 @@ import static com.box.sdk.BoxApiProvider.jwtApiForServiceAccount; import static com.box.sdk.BoxCollaborationAllowlist.AllowlistDirection.INBOUND; -import static com.box.sdk.CleanupTools.deleteFile; import static com.box.sdk.CleanupTools.deleteFolder; import static com.box.sdk.UniqueTestFolder.getUniqueFolder; import static com.box.sdk.UniqueTestFolder.removeUniqueFolder; @@ -12,7 +11,10 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import com.eclipsesource.json.JsonObject; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -47,6 +49,7 @@ public void updateInfoSucceeds() { BoxCollaboration.Info collabInfo = folder.collaborate(collaboratorLogin, originalRole); assertThat(collabInfo.getRole(), is(equalTo(originalRole))); + assertNotNull(collabInfo.getIsAccessOnly()); BoxCollaboration collab = collabInfo.getResource(); collabInfo.setRole(newRole); @@ -149,7 +152,7 @@ public void singleFileCollabSucceeds() { assertEquals(2, numCollabs); } finally { - deleteFile(uploadedFile); + CleanupTools.deleteFile(uploadedFile); if (allowList != null) { allowList.delete(); } @@ -167,4 +170,29 @@ public void acceptPendingCollaboration() { } } + @Test + public void singleFileCollabWithAccessOnlySucceeds() { + HashMap collabsMap = new HashMap<>(); + BoxAPIConnection api = jwtApiForServiceAccount(); + String fileName = "[singleFileCollabSucceeds] Test File.txt"; + BoxFile uploadedFile = null; + try { + uploadedFile = uploadFileToUniqueFolderWithSomeContent(api, fileName); + JsonObject user = new JsonObject() + .add("login", TestConfig.getCollaborator()) + .add("type", "user"); + JsonObject file = new JsonObject() + .add("id", uploadedFile.getID()) + .add("type", "file"); + + BoxCollaboration.Role originalRole = BoxCollaboration.Role.VIEWER; + BoxCollaboration.Info collabInfo = BoxCollaboration.create(api, user, file, originalRole, + false, false, null, true); + + assertThat(collabInfo.getRole(), is(equalTo(originalRole))); + assertTrue(collabInfo.getIsAccessOnly()); + } finally { + CleanupTools.deleteFile(uploadedFile); + } + } } diff --git a/src/main/java/com/box/sdk/BoxCollaboration.java b/src/main/java/com/box/sdk/BoxCollaboration.java index 926e85b23..1b269aa60 100644 --- a/src/main/java/com/box/sdk/BoxCollaboration.java +++ b/src/main/java/com/box/sdk/BoxCollaboration.java @@ -25,7 +25,7 @@ public class BoxCollaboration extends BoxResource { */ public static final String[] ALL_FIELDS = {"type", "id", "item", "accessible_by", "role", "expires_at", "can_view_path", "status", "acknowledged_at", "created_by", - "created_at", "modified_at"}; + "created_at", "modified_at", "is_access_only"}; /** * Collaborations URL Template. @@ -67,7 +67,7 @@ public BoxCollaboration(BoxAPIConnection api, String id) { */ protected static BoxCollaboration.Info create(BoxAPIConnection api, JsonObject accessibleBy, JsonObject item, BoxCollaboration.Role role, Boolean notify, Boolean canViewPath) { - return create(api, accessibleBy, item, role, notify, canViewPath, null); + return create(api, accessibleBy, item, role, notify, canViewPath, null, null); } /** @@ -91,6 +91,32 @@ protected static BoxCollaboration.Info create( Boolean canViewPath, Date expiresAt ) { + return create(api, accessibleBy, item, role, notify, canViewPath, expiresAt, null); + } + + /** + * Create a new collaboration object. + * + * @param api the API connection used to make the request. + * @param accessibleBy the JSON object describing who should be collaborated. + * @param item the JSON object describing which item to collaborate. + * @param role the role to give the collaborators. + * @param notify the user/group should receive email notification of the collaboration or not. + * @param canViewPath the view path collaboration feature is enabled or not. + * @param expiresAt the date the collaboration expires + * @param isAccessOnly the collaboration is an access only collaboration or not. + * @return info about the new collaboration. + */ + protected static BoxCollaboration.Info create( + BoxAPIConnection api, + JsonObject accessibleBy, + JsonObject item, + BoxCollaboration.Role role, + Boolean notify, + Boolean canViewPath, + Date expiresAt, + Boolean isAccessOnly + ) { String queryString = ""; if (notify != null) { @@ -113,6 +139,9 @@ protected static BoxCollaboration.Info create( if (expiresAt != null) { requestJSON.add("expires_at", BoxDateFormat.format(expiresAt)); } + if (isAccessOnly != null) { + requestJSON.add("is_access_only", isAccessOnly); + } BoxJSONRequest request = new BoxJSONRequest(api, url, "POST"); @@ -364,6 +393,7 @@ public class Info extends BoxResource.Info { private BoxItem.Info item; private String inviteEmail; private boolean canViewPath; + private boolean isAccessOnly; /** * Constructs an empty Info object. @@ -453,6 +483,18 @@ public void setCanViewPath(boolean canViewState) { this.addPendingChange("can_view_path", canViewState); } + /** + * Gets a boolean indicator weather "is access only" feature is enabled or not. This field is read only. + * It is used to indicate whether a collaboration is an Access Only Collaboration (AOC). + * When set to true, it separates access from interest by hiding collaborated items from the All Files page + * and the ALF stream. + * This means that users who have been granted access through AOCs will not see these items in their + * regular file view. + */ + public boolean getIsAccessOnly() { + return this.isAccessOnly; + } + /** * The email address used to invite an un-registered collaborator, if they are not a registered user. * @@ -583,6 +625,9 @@ protected void parseJSONMember(JsonObject.Member member) { case "can_view_path": this.canViewPath = value.asBoolean(); break; + case "is_access_only": + this.isAccessOnly = value.asBoolean(); + break; case "invite_email": this.inviteEmail = value.asString(); break; diff --git a/src/test/Fixtures/BoxCollaboration/CreateCollaboration201.json b/src/test/Fixtures/BoxCollaboration/CreateCollaboration201.json index 68cd5c0fc..e2bb56771 100644 --- a/src/test/Fixtures/BoxCollaboration/CreateCollaboration201.json +++ b/src/test/Fixtures/BoxCollaboration/CreateCollaboration201.json @@ -25,5 +25,6 @@ "sequence_id": "2", "etag": "2", "name": "Ball Valve Diagram" - } + }, + "is_access_only": false } diff --git a/src/test/Fixtures/BoxCollaboration/CreateFileCollaboration201.json b/src/test/Fixtures/BoxCollaboration/CreateFileCollaboration201.json index 22948ee83..5e149347b 100644 --- a/src/test/Fixtures/BoxCollaboration/CreateFileCollaboration201.json +++ b/src/test/Fixtures/BoxCollaboration/CreateFileCollaboration201.json @@ -31,5 +31,6 @@ "etag": "5", "sha1": "aa810e72823f3c3dad2d1d4488966f6f1e0a8a9d", "name": "1_1-4_bsp_ball_valve.pdf" - } + }, + "is_access_only": false } diff --git a/src/test/Fixtures/BoxCollaboration/GetCollaborationInfo200.json b/src/test/Fixtures/BoxCollaboration/GetCollaborationInfo200.json index f1840da64..19e7ad9a8 100644 --- a/src/test/Fixtures/BoxCollaboration/GetCollaborationInfo200.json +++ b/src/test/Fixtures/BoxCollaboration/GetCollaborationInfo200.json @@ -25,5 +25,6 @@ "sequence_id": "2", "etag": "2", "name": "Ball Valve Diagram" - } + }, + "is_access_only": false } diff --git a/src/test/Fixtures/BoxCollaboration/GetCollaborationOnFolder200.json b/src/test/Fixtures/BoxCollaboration/GetCollaborationOnFolder200.json index cd6ab3bbe..e0345e737 100644 --- a/src/test/Fixtures/BoxCollaboration/GetCollaborationOnFolder200.json +++ b/src/test/Fixtures/BoxCollaboration/GetCollaborationOnFolder200.json @@ -28,7 +28,8 @@ "sequence_id": "2", "etag": "2", "name": "Ball Valve Diagram" - } + }, + "is_access_only": false }, { "type": "collaboration", @@ -57,7 +58,8 @@ "sequence_id": "2", "etag": "2", "name": "Ball Valve Diagram" - } + }, + "is_access_only": false } ] } diff --git a/src/test/Fixtures/BoxCollaboration/GetPendingCollaborationInfo200.json b/src/test/Fixtures/BoxCollaboration/GetPendingCollaborationInfo200.json index 07fa2b7c0..8651be3a2 100644 --- a/src/test/Fixtures/BoxCollaboration/GetPendingCollaborationInfo200.json +++ b/src/test/Fixtures/BoxCollaboration/GetPendingCollaborationInfo200.json @@ -22,7 +22,8 @@ }, "role": "editor", "acknowledged_at": null, - "item": null + "item": null, + "is_access_only": false } ], "limit": 100, diff --git a/src/test/Fixtures/BoxCollaboration/UpdateCollaboration200.json b/src/test/Fixtures/BoxCollaboration/UpdateCollaboration200.json index 579c48286..2cb48ee8c 100644 --- a/src/test/Fixtures/BoxCollaboration/UpdateCollaboration200.json +++ b/src/test/Fixtures/BoxCollaboration/UpdateCollaboration200.json @@ -25,5 +25,6 @@ "sequence_id": "2", "etag": "2", "name": "Ball Valve Diagram" - } + }, + "is_access_only": false } diff --git a/src/test/java/com/box/sdk/BoxCollaborationTest.java b/src/test/java/com/box/sdk/BoxCollaborationTest.java index 214c2ab83..e6231b4e1 100644 --- a/src/test/java/com/box/sdk/BoxCollaborationTest.java +++ b/src/test/java/com/box/sdk/BoxCollaborationTest.java @@ -4,8 +4,7 @@ import static com.box.sdk.http.ContentType.APPLICATION_JSON; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static java.lang.String.format; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.*; import com.eclipsesource.json.JsonObject; import com.github.tomakehurst.wiremock.client.WireMock; @@ -187,11 +186,13 @@ public void testCreateAndEditCollaborationSucceeds() { .add("item", folder) .add("role", BoxCollaboration.Role.EDITOR.toJSONString()) .add("can_view_path", false) - .add("expires_at", BoxDateFormat.format(expiresAt)); + .add("expires_at", BoxDateFormat.format(expiresAt)) + .add("is_access_only", false); JsonObject updateBody = new JsonObject() .add("role", BoxCollaboration.Role.VIEWER.toJSONString()) - .add("expires_at", BoxDateFormat.format(expiresAt)); + .add("expires_at", BoxDateFormat.format(expiresAt)) + .add("is_access_only", true); wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(createCollaborationURL)) .withRequestBody(WireMock.equalToJson(createBody.toString())) @@ -211,7 +212,7 @@ public void testCreateAndEditCollaborationSucceeds() { .withBody(editResult))); BoxCollaboration.Info collabInfo = BoxCollaboration.create(this.api, user, folder, BoxCollaboration.Role.EDITOR, - false, false, expiresAt); + false, false, expiresAt, false); assertEquals(BoxCollaboration.Status.ACCEPTED, collabInfo.getStatus()); assertEquals(BoxCollaboration.Role.EDITOR, collabInfo.getRole()); @@ -219,6 +220,8 @@ public void testCreateAndEditCollaborationSucceeds() { assertEquals(collabID, collabInfo.getID()); assertEquals(itemName, collabInfo.getItem().getName()); assertEquals(expiresAt, collabInfo.getExpiresAt()); + assertFalse(collabInfo.getIsAccessOnly()); + BoxCollaboration collaboration = new BoxCollaboration(this.api, collabID); collabInfo.setRole(BoxCollaboration.Role.VIEWER); @@ -254,6 +257,7 @@ public void testGetCollaborationInfoSucceeds() { assertEquals(createdByEmail, collabInfo.getCreatedBy().getLogin()); assertEquals(collabItemID, collabInfo.getItem().getID()); assertEquals(collabItemName, collabInfo.getItem().getName()); + assertFalse(collabInfo.getIsAccessOnly()); } @Test