Skip to content

Commit

Permalink
feat: add can_edit field to SharedLink (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda authored Jun 10, 2022
1 parent 4dcb84a commit e0d4197
Show file tree
Hide file tree
Showing 15 changed files with 375 additions and 6 deletions.
24 changes: 24 additions & 0 deletions Box.V2.Test.Integration/BoxFilesManagerIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,30 @@ public async Task ViewVersions_ShouldReturnCorrectVersionNumber_WhenFileVersionI
Assert.AreEqual("2", response.Entries[0].VersionNumber);
}

[TestMethod]
public async Task AddSharedLink_ForValidNewFile_ShouldCreateNewSharedLink()
{
var file = await CreateSmallFile();

var sharedLinkRequest = new BoxSharedLinkRequest()
{
VanityName = GetShortUniqueName("SharedLink"),
Access = BoxSharedLinkAccessType.open,
Permissions = new BoxPermissionsRequest
{
Download = true,
Edit = true,
}
};

var response = await UserClient.FilesManager.CreateSharedLinkAsync(file.Id, sharedLinkRequest);

Assert.AreEqual(file.Id, response.Id);
Assert.AreEqual(BoxSharedLinkAccessType.open, response.SharedLink.Access);
Assert.IsTrue(response.SharedLink.Permissions.CanDownload);
Assert.IsTrue(response.SharedLink.Permissions.CanEdit);
}

private int GetNumberOfParts(long totalSize, long partSize)
{
if (partSize == 0)
Expand Down
16 changes: 16 additions & 0 deletions Box.V2.Test.Integration/BoxWebLinkManagerIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,21 @@ public async Task DeleteWebLinkAsync_ForExistingWebLink_ShouldDeleteWebLinkAndEx

await Assert.ThrowsExceptionAsync<BoxAPIException>(async () => { _ = await UserClient.WebLinksManager.GetWebLinkAsync(weblink.Id); });
}

[TestMethod]
public async Task AddSharedLink_ForNewWeblink_ShouldCreateNewSharedLink()
{
var webLink = await CreateWebLink(GetUniqueName("weblink"), FolderId);

var sharedLinkReq = new BoxSharedLinkRequest()
{
Access = BoxSharedLinkAccessType.open
};

var response = await UserClient.WebLinksManager.CreateSharedLinkAsync(webLink.Id, sharedLinkReq);

Assert.AreEqual(webLink.Id, response.Id);
Assert.AreEqual(BoxSharedLinkAccessType.open, response.SharedLink.Access);
}
}
}
5 changes: 5 additions & 0 deletions Box.V2.Test.Integration/Configuration/IntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ protected static string GetUniqueName(string resourceName, bool includeSpecialCh
return uniqueName;
}

protected static string GetShortUniqueName(string resourceName)
{
return GetUniqueName(resourceName, false).Substring(0, 20);
}

public static async Task ExecuteCommand(ICleanupCommand command)
{
IBoxClient client = GetClient(command);
Expand Down
9 changes: 9 additions & 0 deletions Box.V2.Test/Box.V2.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@
<None Update="Fixtures\BoxFileRequest\GetFileRequest200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxFiles\CreateFileSharedLink200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxFiles\ViewVersions200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxFiles\UploadNewVersionUsingSession200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxFolders\CreateFolderSharedLink200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxMetadata\ExecuteMetadataQuery200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -74,6 +80,9 @@
<None Update="Fixtures\BoxUsers\AddOrUpdateUserAvatar200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxWebLinks\CreateWebLinkSharedLink200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestData\smalltest.pdf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
4 changes: 2 additions & 2 deletions Box.V2.Test/BoxFilesManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,11 @@ public async Task CopyFile_ValidResponse_ValidFile()
public async Task CreateFileSharedLink_ValidResponse_ValidFile()
{
/*** Arrange ***/
var responseString = "{ \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/rh935iit6ewrmw0unyul\", \"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", \"vanity_url\": null, \"vanity_name\": \"my-custom-vanity-name\", \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" }";
Handler.Setup(h => h.ExecuteAsync<BoxFile>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxFile>>(new BoxResponse<BoxFile>()
{
Status = ResponseStatus.Success,
ContentString = responseString
ContentString = LoadFixtureFromJson("Fixtures/BoxFiles/CreateFileSharedLink200.json")
}));

var sharedLink = new BoxSharedLinkRequest()
Expand All @@ -440,6 +439,7 @@ public async Task CreateFileSharedLink_ValidResponse_ValidFile()
Assert.AreEqual("user", f.CreatedBy.Type);
Assert.AreEqual("17738362", f.CreatedBy.Id);
Assert.AreEqual("my-custom-vanity-name", f.SharedLink.VanityName);
Assert.AreEqual(true, f.SharedLink.Permissions.CanEdit);
}

[TestMethod]
Expand Down
30 changes: 29 additions & 1 deletion Box.V2.Test/BoxFoldersManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public async Task CreateFolderSharedLink_ValidResponse_ValidFolder()
.Returns(() => Task.FromResult<IBoxResponse<BoxFolder>>(new BoxResponse<BoxFolder>()
{
Status = ResponseStatus.Success,
ContentString = "{ \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\", \"created_at\": \"2012-12-12T10:53:43-08:00\", \"modified_at\": \"2012-12-12T11:15:04-08:00\", \"description\": \"Some pictures I took\", \"size\": 629644, \"path_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" } ] }, \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/vspke7y05sb214wjokpk\", \"download_url\": \"https://www.box.com/shared/static/vspke7y05sb214wjokpk\", \"vanity_url\": null, \"vanity_name\": \"my-custom-vanity-name\", \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"folder_upload_email\": { \"access\": \"open\", \"email\": \"upload.Picture.k13sdz1@u.box.com\" }, \"parent\": { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, \"item_status\": \"active\", \"item_collection\": { \"total_count\": 1, \"entries\": [ { \"type\": \"file\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\" } ], \"offset\": 0, \"limit\": 100 } }"
ContentString = LoadFixtureFromJson("Fixtures/BoxFolders/CreateFolderSharedLink200.json")
}));

/*** Act ***/
Expand All @@ -605,6 +605,34 @@ public async Task CreateFolderSharedLink_ValidResponse_ValidFolder()
Assert.AreEqual("1", f.ETag);
Assert.AreEqual("Pictures", f.Name);
Assert.AreEqual("my-custom-vanity-name", f.SharedLink.VanityName);
Assert.AreEqual(false, f.SharedLink.Permissions.CanEdit);
}

[TestMethod]
public async Task CreateFolderSharedLink_ShouldThrowArgumentException_WhenEditIsTrue()
{
/*** Arrange ***/
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxFolder>(It.IsAny<IBoxRequest>()))
.Returns(() => Task.FromResult<IBoxResponse<BoxFolder>>(new BoxResponse<BoxFolder>()
{
Status = ResponseStatus.Success,
ContentString = LoadFixtureFromJson("Fixtures/BoxFolders/CreateFolderSharedLink200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r);

var sharedLink = new BoxSharedLinkRequest()
{
Access = BoxSharedLinkAccessType.collaborators,
VanityName = "my-custom-vanity-name",
Permissions = new BoxPermissionsRequest
{
Edit = true
}
};

/*** Act && Assert ***/
await Assert.ThrowsExceptionAsync<ArgumentException>(async () => { _ = await _foldersManager.CreateSharedLinkAsync("12345", sharedLink); });
}

[TestMethod]
Expand Down
32 changes: 29 additions & 3 deletions Box.V2.Test/BoxWebLinksManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,22 +457,21 @@ public async Task Copy_ValidResponse()
public async Task CreateWebLinkSharedLink_ValidResponse_ValidFile()
{
/*** Arrange ***/
var responseString = "{ \"type\": \"web_link\", \"id\": \"5000948880\", \"sequence_id\": \"3\", \"etag\": \"3\", \"sha1\": \"134b65991ed521fcfe4724b7d814ab8ded5185dc\", \"name\": \"tigers.jpeg\", \"description\": \"a picture of tigers\", \"size\": 629644, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" } ] }, \"created_at\": \"2012-12-12T10:55:30-08:00\", \"modified_at\": \"2012-12-12T11:04:26-08:00\", \"created_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"17738362\", \"name\": \"sean rose\", \"login\": \"sean@box.com\" }, \"shared_link\": { \"url\": \"https://www.box.com/s/rh935iit6ewrmw0unyul\", \"vanity_name\": \"my-custom-vanity-name\", \"download_url\": \"https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg\", \"vanity_url\": null, \"is_password_enabled\": false, \"unshared_at\": null, \"download_count\": 0, \"preview_count\": 0, \"access\": \"open\", \"permissions\": { \"can_download\": true, \"can_preview\": true } }, \"parent\": { \"type\": \"folder\", \"id\": \"11446498\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Pictures\" }, \"item_status\": \"active\" }";
IBoxRequest boxRequest = null;
var webLinksUri = new Uri(Constants.WebLinksEndpointString);
Config.SetupGet(x => x.WebLinksEndpointUri).Returns(webLinksUri);
Handler.Setup(h => h.ExecuteAsync<BoxWebLink>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxWebLink>>(new BoxResponse<BoxWebLink>()
{
Status = ResponseStatus.Success,
ContentString = responseString
ContentString = LoadFixtureFromJson("Fixtures/BoxWebLinks/CreateWebLinkSharedLink200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r);

var sharedLink = new BoxSharedLinkRequest()
{
Access = BoxSharedLinkAccessType.collaborators,
VanityName = "my-custom-vanity-name"
VanityName = "my-custom-vanity-name",
};

/*** Act ***/
Expand All @@ -490,6 +489,33 @@ public async Task CreateWebLinkSharedLink_ValidResponse_ValidFile()
Assert.AreEqual("my-custom-vanity-name", w.SharedLink.VanityName);
}

[TestMethod]
public async Task CreateWebLinkSharedLink_ShouldThrowArgumentException_WhenEditIsTrue()
{
/*** Arrange ***/
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxWebLink>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxWebLink>>(new BoxResponse<BoxWebLink>()
{
Status = ResponseStatus.Success,
ContentString = LoadFixtureFromJson("Fixtures/BoxWebLinks/CreateWebLinkSharedLink200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r);

var sharedLink = new BoxSharedLinkRequest()
{
Access = BoxSharedLinkAccessType.collaborators,
VanityName = "my-custom-vanity-name",
Permissions = new BoxPermissionsRequest
{
Edit = true
}
};

/*** Act && Assert ***/
await Assert.ThrowsExceptionAsync<ArgumentException>(async () => { _ = await _webLinkManager.CreateSharedLinkAsync("12345", sharedLink); });
}

[TestMethod]
public async Task DeleteWebLinkSharedLink_ValidResponse_ValidFile()
{
Expand Down
73 changes: 73 additions & 0 deletions Box.V2.Test/Fixtures/BoxFiles/CreateFileSharedLink200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"type": "file",
"id": "5000948880",
"sequence_id": "3",
"etag": "3",
"sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc",
"name": "tigers.jpeg",
"description": "a picture of tigers",
"size": 629644,
"path_collection": {
"total_count": 2,
"entries": [
{
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files"
},
{
"type": "folder",
"id": "11446498",
"sequence_id": "1",
"etag": "1",
"name": "Pictures"
}
]
},
"created_at": "2012-12-12T10:55:30-08:00",
"modified_at": "2012-12-12T11:04:26-08:00",
"created_by": {
"type": "user",
"id": "17738362",
"name": "sean rose",
"login": "sean@box.com"
},
"modified_by": {
"type": "user",
"id": "17738362",
"name": "sean rose",
"login": "sean@box.com"
},
"owned_by": {
"type": "user",
"id": "17738362",
"name": "sean rose",
"login": "sean@box.com"
},
"shared_link": {
"url": "https://www.box.com/s/rh935iit6ewrmw0unyul",
"download_url": "https://www.box.com/shared/static/rh935iit6ewrmw0unyul.jpeg",
"vanity_url": null,
"vanity_name": "my-custom-vanity-name",
"is_password_enabled": false,
"unshared_at": null,
"download_count": 0,
"preview_count": 0,
"access": "open",
"permissions": {
"can_download": true,
"can_preview": true,
"can_edit": true
}
},
"parent": {
"type": "folder",
"id": "11446498",
"sequence_id": "1",
"etag": "1",
"name": "Pictures"
},
"item_status": "active"
}
84 changes: 84 additions & 0 deletions Box.V2.Test/Fixtures/BoxFolders/CreateFolderSharedLink200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"type": "folder",
"id": "11446498",
"sequence_id": "1",
"etag": "1",
"name": "Pictures",
"created_at": "2012-12-12T10:53:43-08:00",
"modified_at": "2012-12-12T11:15:04-08:00",
"description": "Some pictures I took",
"size": 629644,
"path_collection": {
"total_count": 1,
"entries": [
{
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files"
}
]
},
"created_by": {
"type": "user",
"id": "17738362",
"name": "sean rose",
"login": "sean@box.com"
},
"modified_by": {
"type": "user",
"id": "17738362",
"name": "sean rose",
"login": "sean@box.com"
},
"owned_by": {
"type": "user",
"id": "17738362",
"name": "sean rose",
"login": "sean@box.com"
},
"shared_link": {
"url": "https://www.box.com/s/vspke7y05sb214wjokpk",
"download_url": "https://www.box.com/shared/static/vspke7y05sb214wjokpk",
"vanity_url": null,
"vanity_name": "my-custom-vanity-name",
"is_password_enabled": false,
"unshared_at": null,
"download_count": 0,
"preview_count": 0,
"access": "open",
"permissions": {
"can_download": true,
"can_preview": true,
"can_edit" : false
}
},
"folder_upload_email": {
"access": "open",
"email": "upload.Picture.k13sdz1@u.box.com"
},
"parent": {
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files"
},
"item_status": "active",
"item_collection": {
"total_count": 1,
"entries": [
{
"type": "file",
"id": "5000948880",
"sequence_id": "3",
"etag": "3",
"sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc",
"name": "tigers.jpeg"
}
],
"offset": 0,
"limit": 100
}
}
Loading

0 comments on commit e0d4197

Please sign in to comment.