Skip to content

Commit 0d0d9c9

Browse files
author
amgrobelny-box
committed
Fixed remove user, fixed total count on list user
1 parent 10a1524 commit 0d0d9c9

File tree

8 files changed

+95
-14
lines changed

8 files changed

+95
-14
lines changed

BoxCLI/BoxCLIInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public class BoxCLIInfo
44
{
55
public const string ProductTitle = "Box CLI";
66

7-
public const string Version = "1.1.0";
7+
public const string Version = "1.1.1";
88
}
99
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using Box.V2;
5+
using Box.V2.Auth;
6+
using Box.V2.Config;
7+
using Box.V2.Converter;
8+
using Box.V2.Managers;
9+
using Box.V2.Models;
10+
using Box.V2.Services;
11+
12+
namespace BoxCLI.CommandUtilities.CommandModels
13+
{
14+
public class BoxUsersManagerCommand : BoxUsersManager
15+
{
16+
public BoxUsersManagerCommand(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser = null, bool? suppressNotifications = default(bool?))
17+
: base(config, service, converter, auth, asUser, suppressNotifications)
18+
{
19+
}
20+
21+
public async Task<BoxUser> RemoveFromEnterprise(string userId)
22+
{
23+
var updateUserUri = new Uri($"{Constants.UserEndpointString}{userId}");
24+
var request = new BoxRequest(updateUserUri);
25+
request.Method = RequestMethod.Put;
26+
request.Payload = "{\"enterprise\": null}";
27+
28+
IBoxResponse<BoxUser> response = await ToResponseAsync<BoxUser>(request).ConfigureAwait(false);
29+
30+
return response.ResponseObject;
31+
}
32+
}
33+
}

BoxCLI/Commands/UserSubCommands/UserCreateCommand.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,16 @@ private async Task RunCreate()
107107
{
108108
role = "user";
109109
}
110-
var userRequest = base.CreateUserRequest(this._name.Value, "", role, false,
111-
this._language.Value(), this._jobTitle.Value(), this._phoneNumber.Value(), this._address.Value(), this._spaceAmount.Value(),
112-
this._status.Value(), this._syncDisable.HasValue(), this._syncEnable.HasValue(), this._isExemptFromDeviceLimits.HasValue(),
113-
this._notExemptFromDeviceLimits.HasValue(), this._isExemptFromLoginVerificaton.HasValue(), this._notExemptFromLoginVerification.HasValue(),
114-
this._isPasswordResetRequired.HasValue(), login: this._login.Value);
110+
var userRequest = base.CreateUserRequest(name: this._name.Value, role: role,
111+
language: this._language.Value(), jobTitle: this._jobTitle.Value(),
112+
phoneNumber: this._phoneNumber.Value(), address: this._address.Value(),
113+
spaceAmount: this._spaceAmount.Value(), status: this._status.Value(),
114+
syncDisable: this._syncDisable.HasValue(), syncEnable: this._syncEnable.HasValue(),
115+
isExemptFromDeviceLimits: this._isExemptFromDeviceLimits.HasValue(),
116+
notExemptFromDeviceLimits: this._notExemptFromDeviceLimits.HasValue(),
117+
isExemptFromLoginVerificaton: this._isExemptFromLoginVerificaton.HasValue(),
118+
notExemptFromLoginVerification: this._notExemptFromLoginVerification.HasValue(),
119+
isPasswordResetRequired: this._isPasswordResetRequired.HasValue(), login: this._login.Value);
115120
if (this._appUser.HasValue())
116121
{
117122
userRequest.IsPlatformAccessOnly = true;

BoxCLI/Commands/UserSubCommands/UserListCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public async Task RunList()
7474
{
7575
return user.Login.Contains("AppUser");
7676
});
77+
users.TotalCount = users.Entries.Count;
7778
}
7879
else
7980
{
@@ -98,6 +99,7 @@ public async Task RunList()
9899
{
99100
return user.Login.Contains("AppUser");
100101
});
102+
users.TotalCount = users.Entries.Count;
101103
if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
102104
{
103105
base.OutputJson(users);

BoxCLI/Commands/UserSubCommands/UserSubCommandBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected async Task CreateUsersFromFile(string path, string asUser = "",
147147
}
148148
}
149149

150-
protected BoxUserRequest CreateUserRequest(string name = "", string userId = "", string role = "", bool removeFromEnterprise = false,
150+
protected BoxUserRequest CreateUserRequest(string name = "", string userId = "", string role = "",
151151
string language = "", string jobTitle = "", string phoneNumber = "", string address = "", string spaceAmount = "", string status = "",
152152
bool syncDisable = false, bool syncEnable = false, bool isExemptFromDeviceLimits = false, bool notExemptFromDeviceLimits = false,
153153
bool isExemptFromLoginVerificaton = false, bool notExemptFromLoginVerification = false, bool isPasswordResetRequired = false, string login = "")
@@ -168,7 +168,6 @@ protected BoxUserRequest CreateUserRequest(string name = "", string userId = "",
168168
BoxUserRequest userRequest = new BoxUserRequest();
169169
if (!string.IsNullOrEmpty(login)) { userRequest.Login = login; }
170170
if (!string.IsNullOrEmpty(userId)) { userRequest.Id = userId; }
171-
if (removeFromEnterprise) { userRequest.Enterprise = "null"; }
172171
if (!string.IsNullOrEmpty(name)) { userRequest.Name = name; }
173172
if (!string.IsNullOrEmpty(role))
174173
{

BoxCLI/Commands/UserSubCommands/UserUpdateCommand.cs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BoxCLI.BoxHome;
55
using BoxCLI.BoxPlatform.Service;
66
using BoxCLI.CommandUtilities;
7+
using BoxCLI.CommandUtilities.CommandModels;
78
using BoxCLI.CommandUtilities.CommandOptions;
89
using BoxCLI.CommandUtilities.Globalization;
910
using Microsoft.Extensions.CommandLineUtils;
@@ -29,6 +30,7 @@ public class UserUpdateCommand : UserSubCommandBase
2930
private CommandOption _isExemptFromLoginVerificaton;
3031
private CommandOption _notExemptFromLoginVerification;
3132
private CommandOption _isPasswordResetRequired;
33+
private CommandOption _dontPrompt;
3234
private CommandLineApplication _app;
3335
private IBoxHome _home;
3436

@@ -60,6 +62,7 @@ public override void Configure(CommandLineApplication command)
6062
_isExemptFromLoginVerificaton = command.Option("--is-exempt-login-verification", "Exempt user from two-factor auth", CommandOptionType.NoValue);
6163
_notExemptFromLoginVerification = command.Option("--not-exempt-login-verification", "User is not exempt from two-factor auth", CommandOptionType.NoValue);
6264
_isPasswordResetRequired = command.Option("--password-reset", "Force the user to reset password", CommandOptionType.NoValue);
65+
_dontPrompt = SuppressDeletePromptOption.ConfigureOption(command);
6366
command.OnExecute(async () =>
6467
{
6568
return await this.Execute();
@@ -77,12 +80,46 @@ private async Task RunUpdate()
7780
{
7881
base.CheckForUserId(this._userId.Value, this._app);
7982
var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value());
80-
var userRequest = base.CreateUserRequest(this._name.Value(), this._userId.Value, this._role.Value(), this._enterprise.HasValue(),
81-
this._language.Value(), this._jobTitle.Value(), this._phoneNumber.Value(), this._address.Value(), this._spaceAmount.Value(),
82-
this._status.Value(), this._syncDisable.HasValue(), this._syncEnable.HasValue(), this._isExemptFromDeviceLimits.HasValue(),
83-
this._notExemptFromDeviceLimits.HasValue(), this._isExemptFromLoginVerificaton.HasValue(), this._notExemptFromLoginVerification.HasValue(),
84-
this._isPasswordResetRequired.HasValue());
83+
// TODO: Update after SDK is fixed
84+
if (this._enterprise.HasValue())
85+
{
86+
boxClient.AddResourcePlugin<BoxUsersManagerCommand>();
87+
var command = boxClient.ResourcePlugins.Get<BoxUsersManagerCommand>();
88+
BoxUser userRemoved;
89+
if (this._dontPrompt.HasValue())
90+
{
91+
userRemoved = await command.RemoveFromEnterprise(this._userId.Value);
92+
Reporter.WriteSuccess($"Removed user {userRemoved.Id} from your Enterprise.");
93+
return;
94+
}
95+
else
96+
{
97+
Reporter.WriteWarningNoNewLine("Are you sure you want to remove this user from your Enterprise? y/N ");
98+
var yNKey = "n";
99+
yNKey = Console.ReadLine().ToLower();
100+
if (yNKey != "y")
101+
{
102+
Reporter.WriteInformation("Aborted removing user.");
103+
return;
104+
}
105+
else
106+
{
107+
userRemoved = await command.RemoveFromEnterprise(this._userId.Value);
108+
Reporter.WriteSuccess($"Removed user {userRemoved.Id} from your Enterprise.");
109+
return;
110+
}
111+
}
85112

113+
}
114+
var userRequest = base.CreateUserRequest(name: this._name.Value(), userId: this._userId.Value,
115+
role: this._role.Value(), language: this._language.Value(), jobTitle: this._jobTitle.Value(),
116+
phoneNumber: this._phoneNumber.Value(), address: this._address.Value(), spaceAmount: this._spaceAmount.Value(),
117+
status: this._status.Value(), syncDisable: this._syncDisable.HasValue(), syncEnable: this._syncEnable.HasValue(),
118+
isExemptFromDeviceLimits: this._isExemptFromDeviceLimits.HasValue(),
119+
notExemptFromDeviceLimits: this._notExemptFromDeviceLimits.HasValue(),
120+
isExemptFromLoginVerificaton: this._isExemptFromLoginVerificaton.HasValue(),
121+
notExemptFromLoginVerification: this._notExemptFromLoginVerification.HasValue(),
122+
isPasswordResetRequired: this._isPasswordResetRequired.HasValue());
86123
BoxUser updatedUser = await boxClient.UsersManager.UpdateUserInformationAsync(userRequest);
87124

88125
if (updatedUser.Id == this._userId.Value)

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.1.1
4+
- Fixed bug preventing removal of a user from an Enterprise and conversion to a free user account.
5+
- Fixed bug that returned incorrect total count when using `box list users -m` to only list managed users.
6+
37
## 1.1.0
48
- Added new feature on all commands for using an individual token. Add the `--token` option to perform an individual command with the Box CLI using a specific token you provide. The feature is most useful when paired with the Developer Token you can generate through the Box Developer Console. When working with an application you create in the Box Developer Console, you will not need to authorize the application into a Box Enterprise before working with the Developer Token. For example usage: `box users get me --token <token_string>`. Certain commands may fail based on the permissions of the user to which the token you use belongs.
59
- Fixed a bug preventing `previewer` being used when adding or updating a collaboration.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Box CLI
2-
## Current Version: 1.0.2
2+
## Current Version: 1.1.1
3+
## [Download the latest version of the CLI](https://developer.box.com/docs/box-cli)
34
## Prerequisites for Building from Source
45
* [.Net Core SDK v2.0](https://www.microsoft.com/net/core)
56

0 commit comments

Comments
 (0)