Skip to content

Commit d5e8ef8

Browse files
committed
feat(offboard): make delete optional
1 parent ad1ac63 commit d5e8ef8

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

compiler_admin/commands/user/offboard.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@
1616

1717
@click.command()
1818
@click.option("-a", "--alias", help="Another account to assign username as an alias.")
19+
@click.option("-d", "--delete", "_delete", is_flag=True, help="Also delete the account.")
1920
@click.option("-f", "--force", is_flag=True, help="Don't ask for confirmation.")
2021
@click.option("-n", "--notify", help="An email address to send the new password notification.")
2122
@click.argument("username")
2223
@click.pass_context
23-
def offboard(ctx: click.Context, username: str, alias: str = "", force: bool = False, **kwargs):
24-
"""Fully offboard a user from Compiler.
25-
26-
Args:
27-
username (str): The user account to offboard.
24+
def offboard(ctx: click.Context, username: str, alias: str = "", _delete: bool = False, force: bool = False, **kwargs):
25+
"""
26+
Fully offboard a user from Compiler.
2827
29-
alias (str): [Optional] account to assign username as an alias
30-
Returns:
31-
A value indicating if the operation succeeded or failed.
28+
Deactivate, back up email, transfer Calendar/Drive, and optionally delete.
3229
"""
3330
account = user_account_name(username)
3431

@@ -65,11 +62,14 @@ def offboard(ctx: click.Context, username: str, alias: str = "", force: bool = F
6562
CallGAMCommand(("show", "transfers", "olduser", username), stdout=stdout.name, stderr="stdout")
6663
status = " ".join(stdout.readlines())
6764
stdout.seek(0)
65+
click.echo("Transfer complete")
6866

67+
click.echo("Deprovisioning POP/IMAP")
6968
CallGAMCommand(("user", account, "deprovision", "popimap"))
7069

7170
# call the delete command
72-
ctx.forward(delete)
71+
if _delete:
72+
ctx.forward(delete)
7373

7474
if alias_account:
7575
click.echo(f"Adding an alias to account: {alias_account}")

tests/commands/user/test_offboard.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def mock_google_CallGYBCommand(mock_google_CallGYBCommand):
4545

4646

4747
@pytest.mark.usefixtures("mock_input_yes")
48+
@pytest.mark.parametrize("should_delete", [True, False])
4849
def test_offboard_confirm_yes(
4950
cli_runner,
5051
mock_google_user_exists,
@@ -53,18 +54,27 @@ def test_offboard_confirm_yes(
5354
mock_NamedTemporaryFile,
5455
mock_commands_deactivate,
5556
mock_commands_delete,
57+
should_delete,
5658
):
5759
mock_google_user_exists.return_value = True
5860

59-
result = cli_runner.invoke(offboard, ["username"])
61+
args = ["username"]
62+
if should_delete:
63+
args.append("--delete")
64+
65+
result = cli_runner.invoke(offboard, args)
6066

6167
assert result.exit_code == RESULT_SUCCESS
6268
assert mock_google_CallGAMCommand.call_count > 0
6369
mock_google_CallGYBCommand.assert_called_once()
6470
mock_NamedTemporaryFile.assert_called_once()
6571

6672
mock_commands_deactivate.callback.assert_called_once()
67-
mock_commands_delete.callback.assert_called_once()
73+
74+
if should_delete:
75+
mock_commands_delete.callback.assert_called_once()
76+
else:
77+
mock_commands_delete.callback.assert_not_called()
6878

6979

7080
@pytest.mark.usefixtures("mock_input_no")

0 commit comments

Comments
 (0)