diff --git a/Box.V2.Test/BoxGroupsManagerTest.cs b/Box.V2.Test/BoxGroupsManagerTest.cs index 0e71f85b9..2aa9bbc61 100644 --- a/Box.V2.Test/BoxGroupsManagerTest.cs +++ b/Box.V2.Test/BoxGroupsManagerTest.cs @@ -22,18 +22,27 @@ public BoxGroupsManagerTest() [TestCategory("CI-UNIT-TEST")] public async Task GetGroupItems_ValidResponse_ValidGroups() { + IBoxRequest boxRequest = null; Handler.Setup(h => h.ExecuteAsync>(It.IsAny())) .Returns(() => Task.FromResult>>(new BoxResponse>() { Status = ResponseStatus.Success, ContentString = @"{""total_count"": 14, - ""entries"": [ {""type"": ""group"", ""id"": ""26477"", ""name"": ""adfasdf"", ""created_at"": ""2011-02-15T14:07:22-08:00"", ""modified_at"": ""2011-10-05T19:04:40-07:00""}, - {""type"": ""group"", ""id"": ""1263"", ""name"": ""Enterprise Migration"", ""created_at"": ""2009-04-20T19:36:17-07:00"", ""modified_at"": ""2011-10-05T19:05:10-07:00""}], + ""entries"": [ {""type"": ""group"", ""id"": ""26477"", ""name"": ""adfasdf"", ""created_at"": ""2011-02-15T14:07:22-08:00"", ""modified_at"": ""2011-10-05T19:04:40-07:00"", ""invitability_level"": ""none""}, + {""type"": ""group"", ""id"": ""1263"", ""name"": ""Enterprise Migration"", ""created_at"": ""2009-04-20T19:36:17-07:00"", ""modified_at"": ""2011-10-05T19:05:10-07:00"", ""invitability_level"": ""admins_only""}], ""limit"": 2, ""offset"": 0}" - })); + })) + .Callback(r => boxRequest = r); - BoxCollection items = await _groupsManager.GetAllGroupsAsync(); + /*** Act ***/ + BoxCollection items = await _groupsManager.GetAllGroupsAsync(filterTerm: "test"); + + /*** Assert ***/ + + // Request check + Assert.AreEqual("filter_term=test", boxRequest.GetQueryString()); + // Response check Assert.AreEqual(items.TotalCount, 14, "Wrong total count"); Assert.AreEqual(items.Entries.Count, 2, "Wrong count of entries"); Assert.AreEqual(items.Entries[0].Type, "group", "Wrong type"); @@ -41,6 +50,7 @@ public async Task GetGroupItems_ValidResponse_ValidGroups() Assert.AreEqual(items.Entries[0].Name, "adfasdf", "Wrong name"); Assert.AreEqual(items.Entries[0].CreatedAt, DateTime.Parse("2011-02-15T14:07:22-08:00"), "Wrong created at"); Assert.AreEqual(items.Entries[0].ModifiedAt, DateTime.Parse("2011-10-05T19:04:40-07:00"), "Wrong modified at"); + Assert.AreEqual(items.Entries[0].InvitabilityLevel, "none"); Assert.AreEqual(items.Offset, 0, "Wrong offset"); Assert.AreEqual(items.Limit, 2, "Wrong limit"); } diff --git a/Box.V2/Managers/BoxGroupsManager.cs b/Box.V2/Managers/BoxGroupsManager.cs index 743985d30..43163dae9 100644 --- a/Box.V2/Managers/BoxGroupsManager.cs +++ b/Box.V2/Managers/BoxGroupsManager.cs @@ -32,14 +32,20 @@ public BoxGroupsManager(IBoxConfig config, IBoxService service, IBoxConverter co /// The offset of the results. Refer to the Box API for more details. /// Attribute(s) to include in the response. /// Whether or not to auto-paginate to fetch all groups; defaults to false. + /// Limits the results to only groups whose name starts with the search term. /// A collection of groups. - public async Task> GetAllGroupsAsync(int? limit = null, int? offset = null, IEnumerable fields = null, bool autoPaginate = false) + public async Task> GetAllGroupsAsync(int? limit = null, int? offset = null, IEnumerable fields = null, bool autoPaginate = false, string filterTerm = null) { BoxRequest request = new BoxRequest(_config.GroupsEndpointUri) .Param(ParamFields, fields) .Param("limit", limit.ToString()) .Param("offset", offset.ToString()); + if (filterTerm != null) + { + request.Param("filter_term", filterTerm); + } + if (autoPaginate) { if (!limit.HasValue) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7531591a7..1fdac652b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ **New Features and Enhancements:** +- Add support for filtering when getting Groups (#703) - Add zip functionality (#700) - Deprecate one of the overloaded `ExecuteMetadataQueryAsync()` methods (#699) - Add support for `copyInstanceOnItemCopy` field for metadata templates (#698) diff --git a/docs/groups.md b/docs/groups.md index b28886cd8..5430809d3 100644 --- a/docs/groups.md +++ b/docs/groups.md @@ -54,7 +54,7 @@ Get All Groups -------------- To get a list of all groups in the calling user's enterprise, call -`GroupsManager.GetAllGroupsAsync(int? limit = null, int? offset = null, IEnumerable fields = null, bool autoPaginate = false)`. +`GroupsManager.GetAllGroupsAsync(int? limit = null, int? offset = null, IEnumerable fields = null, bool autoPaginate = false, string filterTerm = null)`. Note that this requires permission to view an enterprise's groups, which is reserved for enterprise administrators. @@ -186,4 +186,4 @@ view groups, which is restricted to enterprise administrators. ```c# BoxCollection memberships = await client.GroupsManager .GetAllGroupMembershipsForUserAsync(userId: "11111"); -``` \ No newline at end of file +```