From cf5ce5464124379714be6cbb57dfd8b94b5c4817 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Thu, 8 Sep 2022 12:15:15 +0200 Subject: [PATCH 01/14] feat: Additions and Updates to and for Modifiable Retention --- Box.V2/Managers/BoxRetentionPoliciesManager.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Box.V2/Managers/BoxRetentionPoliciesManager.cs b/Box.V2/Managers/BoxRetentionPoliciesManager.cs index e78a42287..39d67101c 100644 --- a/Box.V2/Managers/BoxRetentionPoliciesManager.cs +++ b/Box.V2/Managers/BoxRetentionPoliciesManager.cs @@ -172,6 +172,21 @@ public async Task GetRetentionPolicyAssignmentAsyn return response.ResponseObject; } + /// + /// Used to delete a retention policy assignment. + /// + /// ID of the retention policy assignment. + /// True if the retention policy assignment was successfully deleted. + public async Task DeleteRetentionPolicyAssignmentAsync(string retentionPolicyAssignmentId) + { + BoxRequest request = new BoxRequest(_config.RetentionPolicyAssignmentsUri, retentionPolicyAssignmentId) + .Method(RequestMethod.Delete); + + IBoxResponse response = await ToResponseAsync(request).ConfigureAwait(false); + + return response.Status == ResponseStatus.Success; + } + /// /// Retrieves all file version retentions for the given enterprise. /// From 108abd750afdfabe84606d4facb849b224989f45 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Thu, 8 Sep 2022 12:27:25 +0200 Subject: [PATCH 02/14] Update interface --- Box.V2/Managers/IBoxRetentionPoliciesManager.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Box.V2/Managers/IBoxRetentionPoliciesManager.cs b/Box.V2/Managers/IBoxRetentionPoliciesManager.cs index eaa5c68cf..df48539f4 100644 --- a/Box.V2/Managers/IBoxRetentionPoliciesManager.cs +++ b/Box.V2/Managers/IBoxRetentionPoliciesManager.cs @@ -78,6 +78,13 @@ public interface IBoxRetentionPoliciesManager /// The specified retention policy assignment will be returned upon success. Task GetRetentionPolicyAssignmentAsync(string retentionPolicyAssignmentId, IEnumerable fields = null); + /// + /// Used to delete a retention policy assignment. + /// + /// ID of the retention policy assignment. + /// True if the retention policy assignment was successfully deleted. + Task DeleteRetentionPolicyAssignmentAsync(string retentionPolicyAssignmentId); + /// /// Retrieves all file version retentions for the given enterprise. /// From 49b4dc925d9d0b0ed11c3c8b23fca9943c197095 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Thu, 8 Sep 2022 13:33:10 +0200 Subject: [PATCH 03/14] Update test --- .../BoxRetentionPoliciesManagerTest.cs | 25 +++++++++++++++++-- Box.V2/Models/BoxRetentionPolicy.cs | 7 ++++++ .../Request/BoxRetentionPolicyRequest.cs | 7 ++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs index 2ab0ed5b3..1de9c90dc 100644 --- a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs +++ b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs @@ -28,6 +28,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success() var policyType = "finite"; var policyAction = "permanently_delete"; var notifiedUserID = "12345"; + var retentionType = "modifiable"; var responseString = "{" + "\"type\": \"retention_policy\"," + "\"id\": \"123456789\"," @@ -51,7 +52,8 @@ public async Task CreateRetentionPolicy_OptionalParams_Success() + " \"type\": \"user\"," + " \"id\": \"" + notifiedUserID + "\"" + " }" - + "]" + + "]," + + "\"retention_type\": \""+ retentionType +"\"" + "}"; Handler.Setup(h => h.ExecuteAsync(It.IsAny())) .Returns(Task.FromResult>(new BoxResponse() @@ -64,7 +66,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success() var requestParams = new BoxRetentionPolicyRequest { AreOwnersNotified = true, - CanOwnerExtendRetention = true + CanOwnerExtendRetention = true, }; var notifiedUser = new BoxRequestEntity { @@ -76,6 +78,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success() requestParams.PolicyType = policyType; requestParams.RetentionLength = retentionLength; requestParams.DispositionAction = policyAction; + requestParams.RetentionType = retentionType; BoxRetentionPolicy results = await _retentionPoliciesManager.CreateRetentionPolicyAsync(requestParams); /*** Assert ***/ @@ -83,6 +86,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success() Assert.AreEqual(policyName, results.PolicyName); Assert.AreEqual(policyType, results.PolicyType); Assert.AreEqual(retentionLength.ToString(), results.RetentionLength); + Assert.AreEqual(retentionType, results.RetentionType); Assert.AreEqual(true, results.CanOwnerExtendRetention); Assert.AreEqual(true, results.AreOwnersNotified); Assert.IsNotNull(results.CustomNotificationRecipients); @@ -165,6 +169,23 @@ public async Task AssignPolicyToMetadataTemplate_OptionalParams_Success() Assert.AreEqual(42.ToString(), result.FilterFields[1].Value); } + [TestMethod] + public async Task DeleteRetentionPolicyAssignment_ValidRequest_Success() + { + /*** Arrange ***/ + var responseString = ""; + Handler.Setup(h => h.ExecuteAsync(It.IsAny())) + .Returns(Task.FromResult>(new BoxResponse() + { + Status = ResponseStatus.Success, + ContentString = responseString + })); + bool result = await _retentionPoliciesManager.DeleteRetentionPolicyAssignmentAsync("12345"); + + /*** Assert ***/ + Assert.IsTrue(result); + } + [TestMethod] public async Task GetFileVersionRetentions_OptionalParams_Success() { diff --git a/Box.V2/Models/BoxRetentionPolicy.cs b/Box.V2/Models/BoxRetentionPolicy.cs index ef34be0cc..0af65d39e 100644 --- a/Box.V2/Models/BoxRetentionPolicy.cs +++ b/Box.V2/Models/BoxRetentionPolicy.cs @@ -20,6 +20,7 @@ public class BoxRetentionPolicy : BoxEntity public const string FieldCanOwnerExtendRetention = "can_owner_extend_retention"; public const string FieldAreOwnersNotified = "are_owners_notified"; public const string FieldCustomNotificationRecipients = "custom_notification_recipients"; + public const string FieldRetentionType = "retention_type"; /// /// The name given to the retention policy @@ -87,5 +88,11 @@ public class BoxRetentionPolicy : BoxEntity /// [JsonProperty(PropertyName = FieldCustomNotificationRecipients)] public virtual List CustomNotificationRecipients { get; set; } + + /// + /// The type of retention policy. Value is one of modifiable or non-modifiable. + /// + [JsonProperty(PropertyName = FieldRetentionType)] + public virtual string RetentionType { get; set; } } } diff --git a/Box.V2/Models/Request/BoxRetentionPolicyRequest.cs b/Box.V2/Models/Request/BoxRetentionPolicyRequest.cs index a8d48cdde..bc2dd58f7 100644 --- a/Box.V2/Models/Request/BoxRetentionPolicyRequest.cs +++ b/Box.V2/Models/Request/BoxRetentionPolicyRequest.cs @@ -55,5 +55,12 @@ public class BoxRetentionPolicyRequest /// [JsonProperty(PropertyName = "custom_notification_recipients")] public List CustomNotificationRecipients { get; set; } + + /// + /// Used to determine the type of retention policy, value can be modifiable or non-modifiable + /// When updating a retention policy, you can use non-modifiable type only. You can convert a modifiable policy to non-modifiable, but not the other way around. + /// + [JsonProperty(PropertyName = "retention_type")] + public string RetentionType { get; set; } } } From a213348f485828928d47f65ca9689091c03f065e Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Thu, 8 Sep 2022 17:27:22 +0200 Subject: [PATCH 04/14] Update integration test --- ...oxRetentionPolicyManagerIntegrationTest.cs | 57 +++++++++++++++++++ .../BoxRetentionPoliciesManagerTest.cs | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs diff --git a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs new file mode 100644 index 000000000..124418729 --- /dev/null +++ b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs @@ -0,0 +1,57 @@ +using System; +using System.Threading.Tasks; +using Box.V2.Exceptions; +using Box.V2.Models; +using Box.V2.Models.Request; +using Box.V2.Test.Integration.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Box.V2.Test.Integration +{ + [TestClass] + public class BoxRetentionPolicyManagerIntegrationTest : TestInFolder + { + [TestMethod] + public async Task CreateRetentionPolicyAsync_ForRetentionPolicyRequest_ShouldCreateNewRetentionPolicy() + { + var retentionPolicyName = GetUniqueName("RetentionPolicy"); + var policyType = "finite"; + var retentionType = "modifiable"; + var retentionPolicyReq = new BoxRetentionPolicyRequest() + { + PolicyName = retentionPolicyName, + RetentionLength = 1, + RetentionType = retentionType, + PolicyType = policyType + }; + var policy = await UserClient.RetentionPoliciesManager.CreateRetentionPolicyAsync(retentionPolicyReq); + Assert.AreEqual(retentionPolicyName, policy.PolicyName); + Assert.AreEqual(1, policy.RetentionLength); + Assert.AreEqual(retentionType, policy.RetentionType); + Assert.AreEqual(policyType, policy.PolicyType); + Assert.AreEqual("active", policy.Status); + + await UserClient.RetentionPoliciesManager.UpdateRetentionPolicyAsync(policy.Id, new BoxRetentionPolicyRequest() { Status = "retired" }); + } + + [TestMethod] + public async Task CreatePolicyAssignment_ForRetentionPolicyAssignmentRequest_ShouldSuccess() + { + var adminFolder = await CreateFolderAsAdmin("0"); + var uploadedFile = await CreateSmallFileAsAdmin(adminFolder.Id); + var retentionPolicy = await CreateRetentionPolicy(adminFolder.Id); + + var policyAssignmentReq = new BoxRetentionPolicyAssignmentRequest() + { + PolicyId = retentionPolicy.Id, + AssignTo = new BoxRequestEntity() { Id = adminFolder.Id } + }; + var policyAssignment = await UserClient.RetentionPoliciesManager.CreateRetentionPolicyAssignmentAsync(policyAssignmentReq); + Assert.AreEqual(retentionPolicy.Id, policyAssignment.RetentionPolicy.Id); + Assert.AreEqual(adminFolder.Id, policyAssignment.AssignedTo.Id); + + var result = await UserClient.RetentionPoliciesManager.DeleteRetentionPolicyAssignmentAsync(policyAssignment.Id); + Assert.IsTrue(result); + } + } +} diff --git a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs index 1de9c90dc..ea554ec0b 100644 --- a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs +++ b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs @@ -53,7 +53,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success() + " \"id\": \"" + notifiedUserID + "\"" + " }" + "]," - + "\"retention_type\": \""+ retentionType +"\"" + + "\"retention_type\": \"" + retentionType + "\"" + "}"; Handler.Setup(h => h.ExecuteAsync(It.IsAny())) .Returns(Task.FromResult>(new BoxResponse() From 7b60645872ab55fd162a573f7cac082038bdbb14 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Thu, 8 Sep 2022 17:32:35 +0200 Subject: [PATCH 05/14] Update integration test --- .../BoxRetentionPolicyManagerIntegrationTest.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs index 124418729..ca1424189 100644 --- a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs +++ b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs @@ -22,7 +22,8 @@ public async Task CreateRetentionPolicyAsync_ForRetentionPolicyRequest_ShouldCre PolicyName = retentionPolicyName, RetentionLength = 1, RetentionType = retentionType, - PolicyType = policyType + PolicyType = policyType, + DispositionAction = "permanently_delete", }; var policy = await UserClient.RetentionPoliciesManager.CreateRetentionPolicyAsync(retentionPolicyReq); Assert.AreEqual(retentionPolicyName, policy.PolicyName); @@ -35,7 +36,7 @@ public async Task CreateRetentionPolicyAsync_ForRetentionPolicyRequest_ShouldCre } [TestMethod] - public async Task CreatePolicyAssignment_ForRetentionPolicyAssignmentRequest_ShouldSuccess() + public async Task CreateRetentionPolicyAssignmentAsync_ForRetentionPolicyAssignmentRequest_ShouldSuccess() { var adminFolder = await CreateFolderAsAdmin("0"); var uploadedFile = await CreateSmallFileAsAdmin(adminFolder.Id); From be6304475e5d0ac054e937f569422953ee98b01c Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Mon, 12 Sep 2022 01:51:59 +0200 Subject: [PATCH 06/14] Update testing. --- ...oxRetentionPolicyManagerIntegrationTest.cs | 25 ------------- .../CreateRetentionPolicyCommand.cs | 36 ++++++++++++++++--- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs index ca1424189..a1d44d3a4 100644 --- a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs +++ b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs @@ -11,35 +11,10 @@ namespace Box.V2.Test.Integration [TestClass] public class BoxRetentionPolicyManagerIntegrationTest : TestInFolder { - [TestMethod] - public async Task CreateRetentionPolicyAsync_ForRetentionPolicyRequest_ShouldCreateNewRetentionPolicy() - { - var retentionPolicyName = GetUniqueName("RetentionPolicy"); - var policyType = "finite"; - var retentionType = "modifiable"; - var retentionPolicyReq = new BoxRetentionPolicyRequest() - { - PolicyName = retentionPolicyName, - RetentionLength = 1, - RetentionType = retentionType, - PolicyType = policyType, - DispositionAction = "permanently_delete", - }; - var policy = await UserClient.RetentionPoliciesManager.CreateRetentionPolicyAsync(retentionPolicyReq); - Assert.AreEqual(retentionPolicyName, policy.PolicyName); - Assert.AreEqual(1, policy.RetentionLength); - Assert.AreEqual(retentionType, policy.RetentionType); - Assert.AreEqual(policyType, policy.PolicyType); - Assert.AreEqual("active", policy.Status); - - await UserClient.RetentionPoliciesManager.UpdateRetentionPolicyAsync(policy.Id, new BoxRetentionPolicyRequest() { Status = "retired" }); - } - [TestMethod] public async Task CreateRetentionPolicyAssignmentAsync_ForRetentionPolicyAssignmentRequest_ShouldSuccess() { var adminFolder = await CreateFolderAsAdmin("0"); - var uploadedFile = await CreateSmallFileAsAdmin(adminFolder.Id); var retentionPolicy = await CreateRetentionPolicy(adminFolder.Id); var policyAssignmentReq = new BoxRetentionPolicyAssignmentRequest() diff --git a/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs b/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs index 08303c8db..4b8709027 100644 --- a/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs +++ b/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; using Box.V2.Models; using Box.V2.Models.Request; @@ -27,9 +28,27 @@ public async Task Execute(IBoxClient client) RetentionLength = 1, DispositionAction = DispositionAction.permanently_delete.ToString(), }; + try + { + var response = await client.RetentionPoliciesManager.CreateRetentionPolicyAsync(retentionPolicyRequest); + Policy = response; + } + catch + { + // TODO: 12-09-2022, @mcong + // There is an error on backend side, which will return 409 status code "conflict" + // but retention policy still created. + // Delete this try-catch after the issue is fixed. + var policies = await client.RetentionPoliciesManager.GetRetentionPoliciesAsync(_policyName); + if (policies.Entries.Count == 1) + { + // Retention policy already created. + var policy = policies.Entries[0]; + var response = await client.RetentionPoliciesManager.GetRetentionPolicyAsync(policy.Id); + Policy = response; + } - var response = await client.RetentionPoliciesManager.CreateRetentionPolicyAsync(retentionPolicyRequest); - Policy = response; + } PolicyId = Policy.Id; var assignmentRequest = new BoxRetentionPolicyAssignmentRequest() @@ -53,8 +72,17 @@ public async Task Dispose(IBoxClient client) { Status = "retired" }; - - await client.RetentionPoliciesManager.UpdateRetentionPolicyAsync(PolicyId, retentionPolicyRequest); + try + { + await client.RetentionPoliciesManager.UpdateRetentionPolicyAsync(PolicyId, retentionPolicyRequest); + } + catch + { + // TODO: 12-09-2022, @mcong + // There is an error on backend side, which will return 500 status code "Internal Server Error" + // but retention policy still updated. + // Delete this try-catch after the issue is fixed. + } } } } From 8555aa9dc3471d3819a325ff6ea74315a8708877 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Mon, 12 Sep 2022 02:24:56 +0200 Subject: [PATCH 07/14] Update test --- .../BoxRetentionPolicyManagerIntegrationTest.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs index a1d44d3a4..0d55b2ba3 100644 --- a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs +++ b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs @@ -15,18 +15,21 @@ public class BoxRetentionPolicyManagerIntegrationTest : TestInFolder public async Task CreateRetentionPolicyAssignmentAsync_ForRetentionPolicyAssignmentRequest_ShouldSuccess() { var adminFolder = await CreateFolderAsAdmin("0"); + var adminFolder2 = await CreateFolderAsAdmin("0"); var retentionPolicy = await CreateRetentionPolicy(adminFolder.Id); - var policyAssignmentReq = new BoxRetentionPolicyAssignmentRequest() { PolicyId = retentionPolicy.Id, - AssignTo = new BoxRequestEntity() { Id = adminFolder.Id } + AssignTo = new BoxRequestEntity() { + Id = adminFolder2.Id, + Type = BoxType.folder + } }; - var policyAssignment = await UserClient.RetentionPoliciesManager.CreateRetentionPolicyAssignmentAsync(policyAssignmentReq); + var policyAssignment = await AdminClient.RetentionPoliciesManager.CreateRetentionPolicyAssignmentAsync(policyAssignmentReq); Assert.AreEqual(retentionPolicy.Id, policyAssignment.RetentionPolicy.Id); - Assert.AreEqual(adminFolder.Id, policyAssignment.AssignedTo.Id); + Assert.AreEqual(adminFolder2.Id, policyAssignment.AssignedTo.Id); - var result = await UserClient.RetentionPoliciesManager.DeleteRetentionPolicyAssignmentAsync(policyAssignment.Id); + var result = await AdminClient.RetentionPoliciesManager.DeleteRetentionPolicyAssignmentAsync(policyAssignment.Id); Assert.IsTrue(result); } } From cdbe382d7bb515b33450161c9276ad5638c9039b Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Mon, 12 Sep 2022 02:29:34 +0200 Subject: [PATCH 08/14] Fix linting error --- .../BoxRetentionPolicyManagerIntegrationTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs index 0d55b2ba3..c5e163504 100644 --- a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs +++ b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs @@ -20,7 +20,8 @@ public async Task CreateRetentionPolicyAssignmentAsync_ForRetentionPolicyAssignm var policyAssignmentReq = new BoxRetentionPolicyAssignmentRequest() { PolicyId = retentionPolicy.Id, - AssignTo = new BoxRequestEntity() { + AssignTo = new BoxRequestEntity() + { Id = adminFolder2.Id, Type = BoxType.folder } From f37d639bb66f2a7c3363bf4e96488658da2c48ed Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Mon, 12 Sep 2022 11:33:32 +0200 Subject: [PATCH 09/14] Update test. --- ...oxRetentionPolicyManagerIntegrationTest.cs | 7 +++---- .../CreateRetentionPolicyCommand.cs | 19 +++++++++++-------- .../Configuration/IntegrationTestBase.cs | 2 +- .../BoxRetentionPoliciesManagerTest.cs | 2 +- Box.V2/Config/Constants.cs | 19 +++++++++++++++++++ 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs index c5e163504..f41ba86b0 100644 --- a/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs +++ b/Box.V2.Test.Integration/BoxRetentionPolicyManagerIntegrationTest.cs @@ -15,20 +15,19 @@ public class BoxRetentionPolicyManagerIntegrationTest : TestInFolder public async Task CreateRetentionPolicyAssignmentAsync_ForRetentionPolicyAssignmentRequest_ShouldSuccess() { var adminFolder = await CreateFolderAsAdmin("0"); - var adminFolder2 = await CreateFolderAsAdmin("0"); - var retentionPolicy = await CreateRetentionPolicy(adminFolder.Id); + var retentionPolicy = await CreateRetentionPolicy(); var policyAssignmentReq = new BoxRetentionPolicyAssignmentRequest() { PolicyId = retentionPolicy.Id, AssignTo = new BoxRequestEntity() { - Id = adminFolder2.Id, + Id = adminFolder.Id, Type = BoxType.folder } }; var policyAssignment = await AdminClient.RetentionPoliciesManager.CreateRetentionPolicyAssignmentAsync(policyAssignmentReq); Assert.AreEqual(retentionPolicy.Id, policyAssignment.RetentionPolicy.Id); - Assert.AreEqual(adminFolder2.Id, policyAssignment.AssignedTo.Id); + Assert.AreEqual(adminFolder.Id, policyAssignment.AssignedTo.Id); var result = await AdminClient.RetentionPoliciesManager.DeleteRetentionPolicyAssignmentAsync(policyAssignment.Id); Assert.IsTrue(result); diff --git a/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs b/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs index 4b8709027..7315ee09d 100644 --- a/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs +++ b/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs @@ -51,17 +51,20 @@ public async Task Execute(IBoxClient client) } PolicyId = Policy.Id; - var assignmentRequest = new BoxRetentionPolicyAssignmentRequest() + if (_folderId != null) { - PolicyId = PolicyId, - AssignTo = new BoxRequestEntity() + var assignmentRequest = new BoxRetentionPolicyAssignmentRequest() { - Type = BoxType.folder, - Id = _folderId - } - }; + PolicyId = PolicyId, + AssignTo = new BoxRequestEntity() + { + Type = BoxType.folder, + Id = _folderId + } + }; - await client.RetentionPoliciesManager.CreateRetentionPolicyAssignmentAsync(assignmentRequest); + await client.RetentionPoliciesManager.CreateRetentionPolicyAssignmentAsync(assignmentRequest); + } return PolicyId; } diff --git a/Box.V2.Test.Integration/Configuration/IntegrationTestBase.cs b/Box.V2.Test.Integration/Configuration/IntegrationTestBase.cs index 1c7847ff8..5e02fdae7 100644 --- a/Box.V2.Test.Integration/Configuration/IntegrationTestBase.cs +++ b/Box.V2.Test.Integration/Configuration/IntegrationTestBase.cs @@ -263,7 +263,7 @@ public static MemoryStream CreateBigFileInMemoryStream() return CreateFileInMemoryStream(50000000); } - public static async Task CreateRetentionPolicy(string folderId = "0", CommandScope commandScope = CommandScope.Test) + public static async Task CreateRetentionPolicy(string folderId = null, CommandScope commandScope = CommandScope.Test) { var createRetentionPolicyCommand = new CreateRetentionPolicyCommand(folderId, GetUniqueName("policy"), commandScope); await ExecuteCommand(createRetentionPolicyCommand); diff --git a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs index ea554ec0b..f1b2490a2 100644 --- a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs +++ b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs @@ -28,7 +28,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success() var policyType = "finite"; var policyAction = "permanently_delete"; var notifiedUserID = "12345"; - var retentionType = "modifiable"; + var retentionType = BoxRetentionType.modifiable; var responseString = "{" + "\"type\": \"retention_policy\"," + "\"id\": \"123456789\"," diff --git a/Box.V2/Config/Constants.cs b/Box.V2/Config/Constants.cs index 20942e140..8b599e4db 100644 --- a/Box.V2/Config/Constants.cs +++ b/Box.V2/Config/Constants.cs @@ -947,5 +947,24 @@ public static class ConflictResolution /// public const string Overwrite = "overwrite"; } + + /*** The retention type of retention policy ***/ + public static class RetentionType + { + /// + /// You can modify the retention policy. For example, you can add or remove folders, + /// shorten or lengthen the policy duration, or delete the assignment. + /// Use this type if your retention policy is not related to any regulatory purposes. + /// + public const string Modifiable = "modifiable"; + + /// + /// You can modify the retention policy only in a limited way: add a folder, lengthen the duration, retire the policy, + /// change the disposition action or notification settings. + /// You cannot perform other actions, such as deleting the assignment or shortening the policy duration. + /// Use this type to ensure compliance with regulatory retention policies. + /// + public const string NonModifiable = "non-modifiable"; + } } } From 5616485993c65257b74c6bab67451ee672199b79 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Mon, 12 Sep 2022 11:37:56 +0200 Subject: [PATCH 10/14] Update error handling. --- .../DisposableCommands/CreateRetentionPolicyCommand.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs b/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs index 7315ee09d..3aa5893db 100644 --- a/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs +++ b/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs @@ -33,7 +33,7 @@ public async Task Execute(IBoxClient client) var response = await client.RetentionPoliciesManager.CreateRetentionPolicyAsync(retentionPolicyRequest); Policy = response; } - catch + catch (Exception ex) { // TODO: 12-09-2022, @mcong // There is an error on backend side, which will return 409 status code "conflict" @@ -46,6 +46,9 @@ public async Task Execute(IBoxClient client) var policy = policies.Entries[0]; var response = await client.RetentionPoliciesManager.GetRetentionPolicyAsync(policy.Id); Policy = response; + } else + { + throw ex; } } From b2444733a7e5744c215c4edaf5412aa30a3d9bd2 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Mon, 12 Sep 2022 11:43:17 +0200 Subject: [PATCH 11/14] Fix lint error --- .../DisposableCommands/CreateRetentionPolicyCommand.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs b/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs index 3aa5893db..85dd911d2 100644 --- a/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs +++ b/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs @@ -46,7 +46,8 @@ public async Task Execute(IBoxClient client) var policy = policies.Entries[0]; var response = await client.RetentionPoliciesManager.GetRetentionPolicyAsync(policy.Id); Policy = response; - } else + } + else { throw ex; } From 1d64ce53c37e96c552fd8afdc7e1ec6c4e4916ea Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Mon, 12 Sep 2022 11:49:00 +0200 Subject: [PATCH 12/14] Update tests. --- Box.V2.Test/BoxRetentionPoliciesManagerTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs index f1b2490a2..bce5e0d30 100644 --- a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs +++ b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs @@ -4,6 +4,7 @@ using Box.V2.Managers; using Box.V2.Models; using Box.V2.Models.Request; +using Box.V2.Config; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -28,7 +29,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success() var policyType = "finite"; var policyAction = "permanently_delete"; var notifiedUserID = "12345"; - var retentionType = BoxRetentionType.modifiable; + var retentionType = Constants.RetentionType.Modifiable; var responseString = "{" + "\"type\": \"retention_policy\"," + "\"id\": \"123456789\"," From afdecd83658b4a1baf89df865e9d15948befd906 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Mon, 12 Sep 2022 11:58:27 +0200 Subject: [PATCH 13/14] Fix lint error --- Box.V2.Test/BoxRetentionPoliciesManagerTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs index bce5e0d30..313ff926d 100644 --- a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs +++ b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Box.V2.Config; using Box.V2.Managers; using Box.V2.Models; using Box.V2.Models.Request; -using Box.V2.Config; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; From b8fa8507403e87fa5ce9d0b0c2a545d0b44969bc Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Mon, 12 Sep 2022 15:34:06 +0200 Subject: [PATCH 14/14] Update retention_type to enum --- .../CreateRetentionPolicyCommand.cs | 1 + .../BoxRetentionPoliciesManagerTest.cs | 5 ++--- Box.V2/Config/Constants.cs | 19 ------------------- Box.V2/Models/BoxRetentionPolicy.cs | 12 +++++++++++- .../Request/BoxRetentionPolicyRequest.cs | 4 +++- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs b/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs index 85dd911d2..526d1c868 100644 --- a/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs +++ b/Box.V2.Test.Integration/Configuration/Commands/DisposableCommands/CreateRetentionPolicyCommand.cs @@ -27,6 +27,7 @@ public async Task Execute(IBoxClient client) PolicyType = "finite", RetentionLength = 1, DispositionAction = DispositionAction.permanently_delete.ToString(), + RetentionType = BoxRetentionType.modifiable }; try { diff --git a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs index 313ff926d..33eb40d6d 100644 --- a/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs +++ b/Box.V2.Test/BoxRetentionPoliciesManagerTest.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Box.V2.Config; using Box.V2.Managers; using Box.V2.Models; using Box.V2.Models.Request; @@ -29,7 +28,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success() var policyType = "finite"; var policyAction = "permanently_delete"; var notifiedUserID = "12345"; - var retentionType = Constants.RetentionType.Modifiable; + var retentionType = BoxRetentionType.non_modifiable; var responseString = "{" + "\"type\": \"retention_policy\"," + "\"id\": \"123456789\"," @@ -54,7 +53,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success() + " \"id\": \"" + notifiedUserID + "\"" + " }" + "]," - + "\"retention_type\": \"" + retentionType + "\"" + + "\"retention_type\": \"non-modifiable\"" + "}"; Handler.Setup(h => h.ExecuteAsync(It.IsAny())) .Returns(Task.FromResult>(new BoxResponse() diff --git a/Box.V2/Config/Constants.cs b/Box.V2/Config/Constants.cs index 8b599e4db..20942e140 100644 --- a/Box.V2/Config/Constants.cs +++ b/Box.V2/Config/Constants.cs @@ -947,24 +947,5 @@ public static class ConflictResolution /// public const string Overwrite = "overwrite"; } - - /*** The retention type of retention policy ***/ - public static class RetentionType - { - /// - /// You can modify the retention policy. For example, you can add or remove folders, - /// shorten or lengthen the policy duration, or delete the assignment. - /// Use this type if your retention policy is not related to any regulatory purposes. - /// - public const string Modifiable = "modifiable"; - - /// - /// You can modify the retention policy only in a limited way: add a folder, lengthen the duration, retire the policy, - /// change the disposition action or notification settings. - /// You cannot perform other actions, such as deleting the assignment or shortening the policy duration. - /// Use this type to ensure compliance with regulatory retention policies. - /// - public const string NonModifiable = "non-modifiable"; - } } } diff --git a/Box.V2/Models/BoxRetentionPolicy.cs b/Box.V2/Models/BoxRetentionPolicy.cs index 0af65d39e..85351604f 100644 --- a/Box.V2/Models/BoxRetentionPolicy.cs +++ b/Box.V2/Models/BoxRetentionPolicy.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Runtime.Serialization; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Box.V2.Models { @@ -93,6 +95,14 @@ public class BoxRetentionPolicy : BoxEntity /// The type of retention policy. Value is one of modifiable or non-modifiable. /// [JsonProperty(PropertyName = FieldRetentionType)] - public virtual string RetentionType { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public virtual BoxRetentionType RetentionType { get; set; } + } + + public enum BoxRetentionType + { + modifiable, + [EnumMember(Value = "non-modifiable")] + non_modifiable } } diff --git a/Box.V2/Models/Request/BoxRetentionPolicyRequest.cs b/Box.V2/Models/Request/BoxRetentionPolicyRequest.cs index bc2dd58f7..4cf2baf77 100644 --- a/Box.V2/Models/Request/BoxRetentionPolicyRequest.cs +++ b/Box.V2/Models/Request/BoxRetentionPolicyRequest.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Box.V2.Models.Request { @@ -61,6 +62,7 @@ public class BoxRetentionPolicyRequest /// When updating a retention policy, you can use non-modifiable type only. You can convert a modifiable policy to non-modifiable, but not the other way around. /// [JsonProperty(PropertyName = "retention_type")] - public string RetentionType { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public BoxRetentionType RetentionType { get; set; } } }