Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add start_date_field and description to retention policies #888

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Box.V2.Exceptions;
using Box.V2.Models;
Expand Down Expand Up @@ -32,5 +33,54 @@ public async Task CreateRetentionPolicyAssignmentAsync_ForRetentionPolicyAssignm
var result = await AdminClient.RetentionPoliciesManager.DeleteRetentionPolicyAssignmentAsync(policyAssignment.Id);
Assert.IsTrue(result);
}

[TestMethod]
public async Task CreateRetentionPolicyAsync_WithDescription_ShouldSucceed()
{
var retentionPolicyRequest = new BoxRetentionPolicyRequest
{
PolicyName = GetUniqueName("policy"),
PolicyType = "finite",
RetentionLength = 1,
DispositionAction = DispositionAction.permanently_delete.ToString(),
RetentionType = BoxRetentionType.modifiable,
Description = "Policy to retain all reports for at least one month"
};
var policy = await AdminClient.RetentionPoliciesManager.CreateRetentionPolicyAsync(retentionPolicyRequest);

Assert.AreEqual(retentionPolicyRequest.PolicyName, policy.PolicyName);
Assert.AreEqual(retentionPolicyRequest.Description, policy.Description);

var policyRetire = new BoxRetentionPolicyRequest
{
Status = "retired"
};

var retireRes = await AdminClient.RetentionPoliciesManager.UpdateRetentionPolicyAsync(policy.Id, policyRetire);
Assert.AreEqual(retireRes.PolicyName, retentionPolicyRequest.PolicyName);
}

[TestMethod]
public async Task CreateRetentionPolicyAssignmentAsync_WithStartDateField_ShouldSuccess()
{
var retentionPolicy = await CreateRetentionPolicy();
var metadataFields = new Dictionary<string, object> { { "upload_date", "2024-02-14" } };
var metadataTemplate = await CreateMetadataTemplate(metadataFields);
var policyAssignmentReq = new BoxRetentionPolicyAssignmentRequest()
{
PolicyId = retentionPolicy.Id,
AssignTo = new BoxRequestEntity()
{
Id = metadataTemplate.Id,
Type = BoxType.metadata_template
},
StartDateField = "upload_date"
};
var policyAssignment = await AdminClient.RetentionPoliciesManager.CreateRetentionPolicyAssignmentAsync(policyAssignmentReq);
Assert.AreEqual(policyAssignmentReq.StartDateField, policyAssignment.StartDateField);

var result = await AdminClient.RetentionPoliciesManager.DeleteRetentionPolicyAssignmentAsync(policyAssignment.Id);
Assert.IsTrue(result);
}
}
}
9 changes: 8 additions & 1 deletion Box.V2.Test/BoxRetentionPoliciesManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success()
var policyAction = "permanently_delete";
var notifiedUserID = "12345";
var retentionType = BoxRetentionType.non_modifiable;
var description = "Policy to retain all reports for at least one month";
var responseString = "{"
+ "\"type\": \"retention_policy\","
+ "\"id\": \"123456789\","
Expand All @@ -47,6 +48,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success()
+ "\"modified_at\": null,"
+ "\"can_owner_extend_retention\": true,"
+ "\"are_owners_notified\": true,"
+ "\"description\": \"Policy to retain all reports for at least one month\","
+ "\"custom_notification_recipients\": ["
+ " {"
+ " \"type\": \"user\","
Expand Down Expand Up @@ -79,6 +81,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success()
requestParams.RetentionLength = retentionLength;
requestParams.DispositionAction = policyAction;
requestParams.RetentionType = retentionType;
requestParams.Description = description;
BoxRetentionPolicy results = await _retentionPoliciesManager.CreateRetentionPolicyAsync(requestParams);

/*** Assert ***/
Expand All @@ -92,6 +95,7 @@ public async Task CreateRetentionPolicy_OptionalParams_Success()
Assert.IsNotNull(results.CustomNotificationRecipients);
Assert.AreEqual(1, results.CustomNotificationRecipients.Count);
Assert.AreEqual(notifiedUserID, results.CustomNotificationRecipients[0].Id);
Assert.AreEqual(description, results.Description);
}

[TestMethod]
Expand All @@ -117,6 +121,7 @@ public async Task AssignPolicyToMetadataTemplate_OptionalParams_Success()
+ " \"login\": \"[email protected]\""
+ "},"
+ "\"assigned_at\": \"2015-07-20T14:28:09-07:00\","
+ "\"start_date_field\": \"upload_date\","
+ "\"filter_fields\": ["
+ " {"
+ " \"field\": \"foo\","
Expand Down Expand Up @@ -156,7 +161,8 @@ public async Task AssignPolicyToMetadataTemplate_OptionalParams_Success()
field = "baz",
value = 42
}
}
},
StartDateField = "upload_date"
};
BoxRetentionPolicyAssignment result = await _retentionPoliciesManager.CreateRetentionPolicyAssignmentAsync(assignmentParams);

Expand All @@ -167,6 +173,7 @@ public async Task AssignPolicyToMetadataTemplate_OptionalParams_Success()
Assert.AreEqual("bar", result.FilterFields[0].Value);
Assert.AreEqual("baz", result.FilterFields[1].Field);
Assert.AreEqual(42.ToString(), result.FilterFields[1].Value);
Assert.AreEqual("upload_date", result.StartDateField);
}

[TestMethod]
Expand Down
7 changes: 7 additions & 0 deletions Box.V2/Models/BoxRetentionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class BoxRetentionPolicy : BoxEntity
public const string FieldAreOwnersNotified = "are_owners_notified";
public const string FieldCustomNotificationRecipients = "custom_notification_recipients";
public const string FieldRetentionType = "retention_type";
public const string FieldDescription = "description";

/// <summary>
/// The name given to the retention policy
Expand Down Expand Up @@ -97,6 +98,12 @@ public class BoxRetentionPolicy : BoxEntity
[JsonProperty(PropertyName = FieldRetentionType)]
[JsonConverter(typeof(StringEnumConverter))]
public virtual BoxRetentionType RetentionType { get; set; }

/// <summary>
/// The additional text description of the retention policy.
/// </summary>
[JsonProperty(PropertyName = FieldDescription)]
public virtual string Description { get; set; }
}

public enum BoxRetentionType
Expand Down
7 changes: 7 additions & 0 deletions Box.V2/Models/BoxRetentionPolicyAssignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class BoxRetentionPolicyAssignment : BoxEntity
public const string FieldAssignedBy = "assigned_by";
public const string FieldAssignedAt = "assigned_at";
public const string FieldFilterFields = "filter_fields";
public const string FieldStartDateField = "start_date_field";

/// <summary>
/// A mini retention policy object representing the retention policy that has been assigned to this content.
Expand Down Expand Up @@ -44,5 +45,11 @@ public class BoxRetentionPolicyAssignment : BoxEntity
/// </summary>
[JsonProperty(PropertyName = FieldFilterFields)]
public virtual List<BoxMetadataFieldFilter> FilterFields { get; set; }

/// <summary>
/// The Metadata field which will be used to specify the start date for the retention policy.
/// </summary>
[JsonProperty(PropertyName = FieldStartDateField)]
public virtual string StartDateField { get; set; }
}
}
6 changes: 6 additions & 0 deletions Box.V2/Models/Request/BoxRetentionPolicyAssignmentRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@ public class BoxRetentionPolicyAssignmentRequest
/// </summary>
[JsonProperty(PropertyName = "filter_fields")]
public List<object> FilterFields { get; set; }

/// <summary>
/// The Metadata field which will be used to specify the start date for the retention policy
/// </summary>
[JsonProperty(PropertyName = "start_date_field")]
public string StartDateField { get; set; }
}
}
6 changes: 6 additions & 0 deletions Box.V2/Models/Request/BoxRetentionPolicyRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ public class BoxRetentionPolicyRequest
[JsonProperty(PropertyName = "retention_type")]
[JsonConverter(typeof(StringEnumConverter))]
public BoxRetentionType RetentionType { get; set; }

/// <summary>
/// The additional text description of the retention policy.
/// </summary>
[JsonProperty(PropertyName = "description")]
public string Description { get; set; }
}
}