Skip to content

Commit

Permalink
feat: add vanity_name to SharedLink (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda committed Dec 9, 2021
1 parent 1f40714 commit 00a1e26
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Box.V2.Test/BoxFilesManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ 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, \"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\" }";
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>()
{
Expand All @@ -427,7 +427,8 @@ public async Task CreateFileSharedLink_ValidResponse_ValidFile()

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

/*** Act ***/
Expand All @@ -443,6 +444,7 @@ public async Task CreateFileSharedLink_ValidResponse_ValidFile()
Assert.AreEqual("sean@box.com", f.CreatedBy.Login);
Assert.AreEqual("user", f.CreatedBy.Type);
Assert.AreEqual("17738362", f.CreatedBy.Id);
Assert.AreEqual("my-custom-vanity-name", f.SharedLink.VanityName);
}

[TestMethod]
Expand Down
6 changes: 4 additions & 2 deletions Box.V2.Test/BoxFoldersManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,14 @@ 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, \"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 = "{ \"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 } }"
}));

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

BoxFolder f = await _foldersManager.CreateSharedLinkAsync("0", sharedLink);
Expand All @@ -615,6 +616,7 @@ public async Task CreateFolderSharedLink_ValidResponse_ValidFolder()
Assert.AreEqual("1", f.SequenceId);
Assert.AreEqual("1", f.ETag);
Assert.AreEqual("Pictures", f.Name);
Assert.AreEqual("my-custom-vanity-name", f.SharedLink.VanityName);
}

[TestMethod]
Expand Down
8 changes: 5 additions & 3 deletions Box.V2.Test/BoxWebLinksManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ 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\", \"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\" }";
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);
Expand All @@ -477,7 +477,8 @@ public async Task CreateWebLinkSharedLink_ValidResponse_ValidFile()

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

/*** Act ***/
Expand All @@ -486,12 +487,13 @@ public async Task CreateWebLinkSharedLink_ValidResponse_ValidFile()
/*** Assert ***/
Assert.AreEqual(new Uri("https://api.box.com/2.0/web_links/12345"), boxRequest.AbsoluteUri);
Assert.AreEqual(RequestMethod.Put, boxRequest.Method);
Assert.AreEqual("{\"shared_link\":{\"access\":\"collaborators\"}}", boxRequest.Payload);
Assert.AreEqual("{\"shared_link\":{\"access\":\"collaborators\",\"vanity_name\":\"my-custom-vanity-name\"}}", boxRequest.Payload);

Assert.AreEqual("5000948880", w.Id);
Assert.AreEqual("3", w.SequenceId);
Assert.AreEqual("3", w.ETag);
Assert.AreEqual("https://www.box.com/s/rh935iit6ewrmw0unyul", w.SharedLink.Url);
Assert.AreEqual("my-custom-vanity-name", w.SharedLink.VanityName);
}

[TestMethod]
Expand Down
8 changes: 8 additions & 0 deletions Box.V2/Models/BoxSharedLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class BoxSharedLink
public const string FieldPreviewCount = "preview_count";
public const string FieldAccess = "access";
public const string FieldPermissions = "permissions";
public const string FieldVanityName = "vanity_name";

/// <summary>
/// The Url of the shared link
Expand Down Expand Up @@ -73,5 +74,12 @@ public class BoxSharedLink
/// </summary>
[JsonProperty(PropertyName = FieldPermissions)]
public virtual BoxPermission Permissions { get; private set; }

/// <summary>
/// Defines a custom vanity name to use in the shared link URL, for example https://app.box.com/v/my-shared-link.
/// Custom URLs should not be used when sharing sensitive content as vanity URLs are a lot easier to guess than regular shared links.
/// </summary>
[JsonProperty(PropertyName = FieldVanityName)]
public virtual string VanityName { get; private set; }
}
}
8 changes: 8 additions & 0 deletions Box.V2/Models/Request/BoxSharedLinkRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public bool ShouldSerializeUnsharedAt()
/// </summary>
[JsonProperty(PropertyName = "password")]
public string Password { get; set; }

/// <summary>
/// Defines a custom vanity name to use in the shared link URL, for example https://app.box.com/v/my-shared-link.
/// Custom URLs should not be used when sharing sensitive content as vanity URLs are a lot easier to guess than regular shared links.
/// Vanity name must be at least 12 characters long
/// </summary>
[JsonProperty(PropertyName = "vanity_name")]
public string VanityName { get; set; }
}
}

0 comments on commit 00a1e26

Please sign in to comment.