Skip to content

Commit c5f146c

Browse files
antususarjankowski
andauthored
feat: Added method to remove retention policy assignment (#873)
Co-authored-by: Artur Jankowski <[email protected]>
1 parent 1ec5b01 commit c5f146c

File tree

5 files changed

+142
-2
lines changed

5 files changed

+142
-2
lines changed

BoxSDK.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
05F770D426F337FA00BDECA2 /* FileLogDestinationSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05F770D326F337FA00BDECA2 /* FileLogDestinationSpec.swift */; };
107107
05F770DB26F3879500BDECA2 /* ThreadSafeQueueSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05F770DA26F3879500BDECA2 /* ThreadSafeQueueSpecs.swift */; };
108108
05FA797527D793B100669B6D /* CCGAuthSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05FA797427D793B100669B6D /* CCGAuthSession.swift */; };
109+
0BD51EDC28CF257E000DE69E /* RetentionPoliciesModuleIntegrationSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD51EDB28CF257E000DE69E /* RetentionPoliciesModuleIntegrationSpecs.swift */; };
109110
0C00835C229C06FE0067C1AF /* GetFolderInfo.json in Resources */ = {isa = PBXBuildFile; fileRef = 0C00835B229C06FE0067C1AF /* GetFolderInfo.json */; };
110111
0C00836E229C41CA0067C1AF /* FolderCollaborations.json in Resources */ = {isa = PBXBuildFile; fileRef = 0C00836D229C41CA0067C1AF /* FolderCollaborations.json */; };
111112
0C008372229C45480067C1AF /* UpdateFolder.json in Resources */ = {isa = PBXBuildFile; fileRef = 0C008371229C45480067C1AF /* UpdateFolder.json */; };
@@ -715,6 +716,7 @@
715716
05F770D326F337FA00BDECA2 /* FileLogDestinationSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileLogDestinationSpec.swift; sourceTree = "<group>"; };
716717
05F770DA26F3879500BDECA2 /* ThreadSafeQueueSpecs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadSafeQueueSpecs.swift; sourceTree = "<group>"; };
717718
05FA797427D793B100669B6D /* CCGAuthSession.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CCGAuthSession.swift; sourceTree = "<group>"; };
719+
0BD51EDB28CF257E000DE69E /* RetentionPoliciesModuleIntegrationSpecs.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RetentionPoliciesModuleIntegrationSpecs.swift; sourceTree = "<group>"; };
718720
0C00835B229C06FE0067C1AF /* GetFolderInfo.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = GetFolderInfo.json; sourceTree = "<group>"; };
719721
0C00835F229C08F40067C1AF /* FolderUploadEmail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderUploadEmail.swift; sourceTree = "<group>"; };
720722
0C008369229C39F00067C1AF /* CopyFolder.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = CopyFolder.json; sourceTree = "<group>"; };
@@ -1273,12 +1275,13 @@
12731275
05EC89D527577AF900FEBAC6 /* IntegrationTests */ = {
12741276
isa = PBXGroup;
12751277
children = (
1276-
054D536B283CFAB800CC2CBC /* Async */,
12771278
05070D2C2757DBD7000AFE20 /* BaseIntegrationSpecs.swift */,
12781279
0501990B282423970085003B /* BoxClientIntegrationSpecs.swift */,
12791280
05EA725A27621FA7001ECFF3 /* FileModuleIntegrationSpecs.swift */,
12801281
0579F6FF27577FD200473A3C /* FolderModuleIntegrationSpecs.swift */,
1282+
0BD51EDB28CF257E000DE69E /* RetentionPoliciesModuleIntegrationSpecs.swift */,
12811283
052A03F9287C1FC20063513C /* UsersModuleIntegrationSpecs.swift */,
1284+
054D536B283CFAB800CC2CBC /* Async */,
12821285
053637BB276C952D00C18D26 /* Extensions */,
12831286
05EA725C2762649B001ECFF3 /* Resources */,
12841287
0547B737276C99AA002D9E7A /* Utils */,
@@ -2826,6 +2829,7 @@
28262829
isa = PBXSourcesBuildPhase;
28272830
buildActionMask = 2147483647;
28282831
files = (
2832+
0BD51EDC28CF257E000DE69E /* RetentionPoliciesModuleIntegrationSpecs.swift in Sources */,
28292833
0547B73E276C99AA002D9E7A /* CryptographyUtil.swift in Sources */,
28302834
053637BD276C96E400C18D26 /* IntegrationTestResources.swift in Sources */,
28312835
057C8CE4276799760092A6EC /* Date+Extensions.swift in Sources */,

IntegrationTests/BaseIntegrationSpecs.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,8 @@ class BaseIntegrationSpecs: QuickSpec {
268268
}
269269
}
270270
}
271+
272+
func randomizeName(name: String) -> String {
273+
return "\(name)_\(UUID().uuidString)"
274+
}
271275
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//
2+
// RetentionPoliciesModuleIntegrationSpecs.swift
3+
// BoxSDKIntegrationTests-iOS
4+
//
5+
// Created by Kamil Berdychowski on 09/09/2022.
6+
// Copyright © 2022 box. All rights reserved.
7+
//
8+
9+
@testable import BoxSDK
10+
import Nimble
11+
import Quick
12+
13+
class RetentionPoliciesModuleIntegrationSpecs: BaseIntegrationSpecs {
14+
var folder: Folder!
15+
var retentionPolicy: RetentionPolicy!
16+
17+
override func spec() {
18+
beforeSuite {
19+
self.initializeClient()
20+
self.createRetention(name: self.randomizeName(name: "iOS One Day")) { [weak self] retention in self?.retentionPolicy = retention }
21+
self.createFolder(name: NameGenerator.getUniqueFolderName(for: "RetentionPoliciesModule")) { [weak self] createdFolder in self?.folder = createdFolder }
22+
}
23+
24+
afterSuite {
25+
self.retireRetention(self.retentionPolicy)
26+
self.deleteFolder(self.folder, recursive: true)
27+
}
28+
29+
describe("Retention Policy Assignment") {
30+
31+
context("live cycle") {
32+
33+
it("assign then get and unassign retention policy") {
34+
var retentionPolicyAssignment: RetentionPolicyAssignment?
35+
36+
// Assign
37+
waitUntil(timeout: .seconds(Constants.Timeout.default)) { done in
38+
self.client.retentionPolicy.assign(
39+
policyId: self.retentionPolicy.id,
40+
assignedContentId: self.folder.id,
41+
assignContentType: RetentionPolicyAssignmentItemType.folder
42+
) { result in
43+
switch result {
44+
case let .success(assignment):
45+
retentionPolicyAssignment = assignment
46+
expect(retentionPolicyAssignment?.retentionPolicy?.id).to(equal(self.retentionPolicy.id))
47+
expect(retentionPolicyAssignment?.assignedTo?.type).to(equal(RetentionPolicyAssignmentItemType.folder))
48+
expect(retentionPolicyAssignment?.assignedTo?.id).to(equal(self.folder.id))
49+
case let .failure(error):
50+
fail("Expected assign call to succeed, but instead got \(error)")
51+
}
52+
53+
done()
54+
}
55+
}
56+
57+
guard let retentionPolicyAssignment = retentionPolicyAssignment else { return }
58+
59+
// Get
60+
waitUntil(timeout: .seconds(Constants.Timeout.default)) { done in
61+
self.client.retentionPolicy.getAssignment(assignmentId: retentionPolicyAssignment.id) { result in
62+
switch result {
63+
case let .success(assignment):
64+
expect(assignment.retentionPolicy?.id).to(equal(self.retentionPolicy.id))
65+
expect(assignment.assignedTo?.type).to(equal(RetentionPolicyAssignmentItemType.folder))
66+
expect(assignment.assignedTo?.id).to(equal(self.folder.id))
67+
case let .failure(error):
68+
fail("Expected get call to succeed, but instead got \(error)")
69+
}
70+
71+
done()
72+
}
73+
}
74+
75+
// Delete
76+
waitUntil(timeout: .seconds(Constants.Timeout.default)) { done in
77+
self.client.retentionPolicy.deleteAssignment(assignmentId: retentionPolicyAssignment.id) { result in
78+
if case let .failure(error) = result {
79+
fail("Expected delete call to succeed, but instead got \(error)")
80+
}
81+
82+
done()
83+
}
84+
}
85+
}
86+
}
87+
}
88+
}
89+
}

Sources/Modules/RetentionPolicyModule.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,19 @@ public class RetentionPoliciesModule {
9292
/// - id: Retention policy id.
9393
/// - name: Updated name of retention policy.
9494
/// - dispositionAction: If updating a `finite` policy, the disposition action can be `permanently_delete` or `remove_retention`.
95-
/// For indefinite policies, disposition action must be remove_retention.
95+
/// For indefinite policies, disposition action must be `remove_retention`.
9696
/// - status: Used to `retire` a retention policy if status is set to `retired`. If not retiring a policy, do not include or set to null.
9797
/// - setRetentionTypeToNonModifiable: If value is `false` retention type is not changed. If value is true retention type is changed to `non_modifiable`.
98+
/// - length: The retention_length is the amount of time, in days, to apply the retention policy to the selected content in days.
99+
/// Do not specify for `indefinite` policies. Required for `finite` policies.
98100
/// - completion: Returns either updated retention policy object or an error.
99101
public func update(
100102
policyId id: String,
101103
name: String? = nil,
102104
dispositionAction: DispositionAction? = nil,
103105
status: RetentionPolicyStatus? = nil,
104106
setRetentionTypeToNonModifiable: Bool = false,
107+
length: Int? = nil,
105108
completion: @escaping Callback<RetentionPolicy>
106109
) {
107110

@@ -112,6 +115,7 @@ public class RetentionPoliciesModule {
112115
if setRetentionTypeToNonModifiable {
113116
body["retention_type"] = RetentionType.nonModifiable.description
114117
}
118+
body["retention_length"] = length
115119

116120
boxClient.put(
117121
url: URL.boxAPIEndpoint("/2.0/retention_policies/\(id)", configuration: boxClient.configuration),
@@ -198,6 +202,21 @@ public class RetentionPoliciesModule {
198202
)
199203
}
200204

205+
/// Remove retention policy assignment
206+
///
207+
/// - Parameters:
208+
/// - id: Retention policy assignment ID.
209+
/// - completion: An empty response will be returned upon successful deletion or error if assignment cannot be deleted.
210+
public func deleteAssignment(
211+
assignmentId id: String,
212+
completion: @escaping Callback<Void>
213+
) {
214+
boxClient.delete(
215+
url: URL.boxAPIEndpoint("/2.0/retention_policy_assignments/\(id)", configuration: boxClient.configuration),
216+
completion: ResponseHandler.default(wrapping: completion)
217+
)
218+
}
219+
201220
/// Returns a list of all retention policy assignments associated with a specified retention policy.
202221
///
203222
/// - Parameters:

Tests/Modules/RetentionPolicyModuleSpecs.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,30 @@ class RetentionPolicyModuleSpecs: QuickSpec {
321321
}
322322
}
323323

324+
describe("deleteAssignment()") {
325+
it("should delete retention policy assignment") {
326+
let id = "11446498"
327+
stub(
328+
condition: isHost("api.box.com") &&
329+
isPath("/2.0/retention_policy_assignments/\(id)") &&
330+
isMethodDELETE()
331+
) { _ in
332+
OHHTTPStubsResponse(data: Data(), statusCode: 204, headers: [:])
333+
}
334+
waitUntil(timeout: .seconds(10)) { done in
335+
self.sut.retentionPolicy.deleteAssignment(assignmentId: id) { response in
336+
switch response {
337+
case .success:
338+
break
339+
case let .failure(error):
340+
fail("Expected call to deleteAssignment to succeed, but instead got \(error)")
341+
}
342+
done()
343+
}
344+
}
345+
}
346+
}
347+
324348
describe("listAssignments()") {
325349
it("should get a list of all retention policy assignments associated with a specified retention policy") {
326350
let id = "123456"

0 commit comments

Comments
 (0)