From adfcdc0e12713a3094fd94da745ec2a448cbeb1c Mon Sep 17 00:00:00 2001 From: Jonathan Black <45244911+jblack6-byu@users.noreply.github.com> Date: Fri, 13 Nov 2020 11:16:41 -0700 Subject: [PATCH] Fixed an issue where a user could not be rolled out of the enterprise. --- Box.V2/Converter/BoxJsonConverter.cs | 9 ++++++++- Box.V2/Managers/BoxUsersManager.cs | 7 ++++--- .../Models/Request/BoxUserRollOutRequest.cs | 19 +++++++++++++++++++ docs/users.md | 16 ++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 Box.V2/Models/Request/BoxUserRollOutRequest.cs diff --git a/Box.V2/Converter/BoxJsonConverter.cs b/Box.V2/Converter/BoxJsonConverter.cs index ad8789091..eea76cdce 100644 --- a/Box.V2/Converter/BoxJsonConverter.cs +++ b/Box.V2/Converter/BoxJsonConverter.cs @@ -1,4 +1,4 @@ -using Box.V2.Config; +using Box.V2.Config; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -43,6 +43,13 @@ public T Parse(string content) /// JSON string public string Serialize(T entity) { + if (entity is Box.V2.Models. BoxUserRollOutRequest) + { + return JsonConvert.SerializeObject(entity, new JsonSerializerSettings() + { + DateFormatString = Constants.RFC3339DateFormat + }); + } return JsonConvert.SerializeObject(entity, _settings); } } diff --git a/Box.V2/Managers/BoxUsersManager.cs b/Box.V2/Managers/BoxUsersManager.cs index 233e38142..6279e49ab 100644 --- a/Box.V2/Managers/BoxUsersManager.cs +++ b/Box.V2/Managers/BoxUsersManager.cs @@ -58,12 +58,13 @@ public async Task CreateEnterpriseUserAsync(BoxUserRequest userRequest, /// /// Used to edit the settings and information about a user. This method only works for enterprise admins. To roll a user out - /// of the enterprise (and convert them to a standalone free user), update the special enterprise attribute to be null. + /// of the enterprise (and convert them to a standalone free user), use the BoxUserRollOutRequest object for user request and set their user ID. /// - /// BoxUserRequest object. + /// The type of Request to make. Must inherit from BoxRequestEntity + /// An object that inherits from the class BoxRequestEntity. At this point only BoxUserRequest and BoxUserRollOutRequest. /// Attribute(s) to include in the response. /// Returns the user object for the updated user. Errors may be thrown when the fields are invalid or this API call is made from a non-admin account. - public async Task UpdateUserInformationAsync(BoxUserRequest userRequest, IEnumerable fields = null) + public async Task UpdateUserInformationAsync(T userRequest, IEnumerable fields = null) where T : BoxRequestEntity { userRequest.ThrowIfNull("userRequest") .Id.ThrowIfNullOrWhiteSpace("userRequest.Id"); diff --git a/Box.V2/Models/Request/BoxUserRollOutRequest.cs b/Box.V2/Models/Request/BoxUserRollOutRequest.cs new file mode 100644 index 000000000..05840d561 --- /dev/null +++ b/Box.V2/Models/Request/BoxUserRollOutRequest.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + + +namespace Box.V2.Models +{ + /// + /// A request class for rolling users out of box + /// + public class BoxUserRollOutRequest : BoxRequestEntity + { + /// + /// Setting this to null will roll the user out of the enterprise and make them a free user + /// + [JsonProperty(PropertyName = "enterprise")] + public string Enterprise { get; set; } + + } +} diff --git a/docs/users.md b/docs/users.md index ecf2aa819..2202e968c 100644 --- a/docs/users.md +++ b/docs/users.md @@ -107,6 +107,22 @@ var updates = new BoxUserRequest() BoxUser updatedUser = await client.UsersManager.UpdateUserInformationAsync(updates); ``` +Roll User Out of Enterprise +--------------------------- + +To update a user's information, call +`UsersManager.UpdateUserInformationAsync(BoxUserRollOutRequest userRequest, IEnumerable fields = null)` +with only the id. + + +```c# +var updates = new BoxUserRollOutRequest() +{ + Id = "44444" +}; +BoxUser updatedUser = await client.UsersManager.UpdateUserInformationAsync(updates); +``` + Delete User -----------