Skip to content

Commit ad1ac63

Browse files
committed
refactor(user): deactivate more accurately describes this action
1 parent 5d9005b commit ad1ac63

File tree

9 files changed

+40
-64
lines changed

9 files changed

+40
-64
lines changed

compiler_admin/commands/user/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import click
22

3-
from compiler_admin.commands.user.alumni import alumni
43
from compiler_admin.commands.user.convert import convert
54
from compiler_admin.commands.user.create import create
5+
from compiler_admin.commands.user.deactivate import deactivate
66
from compiler_admin.commands.user.delete import delete
77
from compiler_admin.commands.user.offboard import offboard
88
from compiler_admin.commands.user.reset import reset
@@ -18,9 +18,9 @@ def user():
1818
pass
1919

2020

21-
user.add_command(alumni)
2221
user.add_command(convert)
2322
user.add_command(create)
23+
user.add_command(deactivate)
2424
user.add_command(delete)
2525
user.add_command(offboard)
2626
user.add_command(reset)

compiler_admin/commands/user/convert.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import click
22

33
from compiler_admin import RESULT_FAILURE
4-
from compiler_admin.commands.user.alumni import alumni
54
from compiler_admin.services.google import (
65
GROUP_PARTNERS,
76
GROUP_STAFF,
8-
OU_ALUMNI,
97
OU_CONTRACTORS,
108
OU_PARTNERS,
119
OU_STAFF,
@@ -19,24 +17,11 @@
1917
)
2018

2119

22-
ACCOUNT_TYPE_OU = {"alumni": OU_ALUMNI, "contractor": OU_CONTRACTORS, "partner": OU_PARTNERS, "staff": OU_STAFF}
20+
ACCOUNT_TYPE_OU = {"contractor": OU_CONTRACTORS, "partner": OU_PARTNERS, "staff": OU_STAFF}
2321

2422

2523
@click.command()
2624
@click.option("-f", "--force", is_flag=True, help="Don't ask for confirmation.")
27-
@click.option(
28-
"-n", "--notify", help="An email address to send the new password notification. Only valid for alumni conversion."
29-
)
30-
@click.option(
31-
"-e",
32-
"--recovery-email",
33-
help="An email address to use as the new recovery email. Only valid for alumni conversion.",
34-
)
35-
@click.option(
36-
"-p",
37-
"--recovery-phone",
38-
help="A phone number to use as the new recovery phone number. Only valid for alumni conversion.",
39-
)
4025
@click.argument("username")
4126
@click.argument("account_type", type=click.Choice(ACCOUNT_TYPE_OU.keys(), case_sensitive=False))
4227
@click.pass_context
@@ -52,11 +37,7 @@ def convert(ctx: click.Context, username: str, account_type: str, **kwargs):
5237

5338
click.echo(f"User exists, converting to: {account_type} for {account}")
5439

55-
if account_type == "alumni":
56-
# call the alumni command
57-
ctx.forward(alumni)
58-
59-
elif account_type == "contractor":
40+
if account_type == "contractor":
6041
if user_is_partner(account):
6142
remove_user_from_group(account, GROUP_PARTNERS)
6243
remove_user_from_group(account, GROUP_STAFF)

compiler_admin/commands/user/alumni.py renamed to compiler_admin/commands/user/deactivate.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
move_user_ou,
99
user_account_name,
1010
user_exists,
11+
user_is_deactivated,
1112
)
1213

1314

@@ -17,34 +18,40 @@
1718
@click.option(
1819
"-e",
1920
"--recovery-email",
21+
default="",
2022
help="An email address to use as the new recovery email. Without a value, clears the recovery email.",
2123
)
2224
@click.option(
2325
"-p",
2426
"--recovery-phone",
27+
default="",
2528
help="A phone number to use as the new recovery phone number. Without a value, clears the recovery phone number.",
2629
)
2730
@click.argument("username")
2831
@click.pass_context
29-
def alumni(
32+
def deactivate(
3033
ctx: click.Context, username: str, force: bool = False, recovery_email: str = "", recovery_phone: str = "", **kwargs
3134
):
3235
"""
33-
Convert a user to a Compiler alumni.
36+
Deactivate (but do not delete) a user.
3437
"""
3538
account = user_account_name(username)
3639

3740
if not user_exists(account):
3841
click.echo(f"User does not exist: {account}")
3942
raise SystemExit(RESULT_FAILURE)
4043

44+
if user_is_deactivated(account):
45+
click.echo("User is already deactivated")
46+
raise SystemExit(RESULT_FAILURE)
47+
4148
if not force:
42-
cont = input(f"Convert account to alumni for {account}? (Y/n): ")
49+
cont = input(f"Deactivate account {account}? (Y/n): ")
4350
if not cont.lower().startswith("y"):
44-
click.echo("Aborting conversion.")
51+
click.echo("Aborting deactivation")
4552
raise SystemExit(RESULT_SUCCESS)
4653

47-
click.echo(f"User exists, converting to alumni: {account}")
54+
click.echo(f"User exists, deactivating: {account}")
4855

4956
click.echo("Removing from groups")
5057
CallGAMCommand(("user", account, "delete", "groups"))
@@ -71,3 +78,5 @@ def alumni(
7178
click.echo("Turning off 2FA")
7279
command = ("user", account, "turnoff2sv")
7380
CallGAMCommand(command)
81+
82+
click.echo(f"User is deactivated: {account}")

compiler_admin/commands/user/offboard.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import click
44

55
from compiler_admin import RESULT_FAILURE, RESULT_SUCCESS
6-
from compiler_admin.commands.user.alumni import alumni
6+
from compiler_admin.commands.user.deactivate import deactivate
77
from compiler_admin.commands.user.delete import delete
88
from compiler_admin.services.google import (
99
USER_ARCHIVE,
@@ -49,8 +49,8 @@ def offboard(ctx: click.Context, username: str, alias: str = "", force: bool = F
4949

5050
click.echo(f"User exists, offboarding: {account}")
5151

52-
# call the alumni command
53-
ctx.forward(alumni)
52+
# call the deactivate command
53+
ctx.forward(deactivate)
5454

5555
click.echo("Backing up email")
5656
CallGYBCommand(("--service-account", "--email", account, "--action", "backup"))

tests/commands/user/test_convert.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
from compiler_admin.commands.user.convert import convert, __name__ as MODULE
55

66

7-
@pytest.fixture
8-
def mock_commands_alumni(mock_commands_alumni):
9-
return mock_commands_alumni(MODULE)
10-
11-
127
@pytest.fixture
138
def mock_google_user_exists(mock_google_user_exists):
149
return mock_google_user_exists(MODULE)
@@ -86,15 +81,6 @@ def test_convert_user_exists_bad_account_type(cli_runner, mock_google_move_user_
8681
assert mock_google_move_user_ou.call_count == 0
8782

8883

89-
@pytest.mark.usefixtures("mock_google_user_exists_true")
90-
def test_convert_alumni(cli_runner, mock_commands_alumni, mock_google_move_user_ou):
91-
result = cli_runner.invoke(convert, ["username", "alumni"])
92-
93-
assert result.exit_code == RESULT_SUCCESS
94-
mock_commands_alumni.callback.assert_called_once()
95-
mock_google_move_user_ou.assert_called_once()
96-
97-
9884
@pytest.mark.usefixtures(
9985
"mock_google_user_exists_true", "mock_google_user_is_partner_false", "mock_google_user_is_staff_false"
10086
)

tests/commands/user/test_alumni.py renamed to tests/commands/user/test_deactivate.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from compiler_admin import RESULT_FAILURE, RESULT_SUCCESS
4-
from compiler_admin.commands.user.alumni import alumni, __name__ as MODULE
4+
from compiler_admin.commands.user.deactivate import deactivate, __name__ as MODULE
55
from compiler_admin.services.google import OU_ALUMNI
66

77

@@ -40,10 +40,10 @@ def mock_google_user_exists(mock_google_user_exists):
4040
return mock_google_user_exists(MODULE)
4141

4242

43-
def test_alumni_user_does_not_exists(cli_runner, mock_google_user_exists, mock_google_CallGAMCommand):
43+
def test_deactivate_user_does_not_exists(cli_runner, mock_google_user_exists, mock_google_CallGAMCommand):
4444
mock_google_user_exists.return_value = False
4545

46-
result = cli_runner.invoke(alumni, ["username"])
46+
result = cli_runner.invoke(deactivate, ["username"])
4747

4848
assert result.exit_code == RESULT_FAILURE
4949
assert result.exception
@@ -52,37 +52,37 @@ def test_alumni_user_does_not_exists(cli_runner, mock_google_user_exists, mock_g
5252

5353

5454
@pytest.mark.usefixtures("mock_input_yes")
55-
def test_alumni_confirm_yes(
55+
def test_deactivate_confirm_yes(
5656
cli_runner, mock_google_user_exists, mock_google_CallGAMCommand, mock_google_move_user_ou, mock_commands_reset
5757
):
5858
mock_google_user_exists.return_value = True
5959

60-
result = cli_runner.invoke(alumni, ["username"])
60+
result = cli_runner.invoke(deactivate, ["username"])
6161

6262
assert result.exit_code == RESULT_SUCCESS
6363
mock_google_CallGAMCommand.assert_called()
6464
mock_google_move_user_ou.assert_called_once_with("username@compiler.la", OU_ALUMNI)
6565

6666

6767
@pytest.mark.usefixtures("mock_input_no")
68-
def test_alumni_confirm_no(
68+
def test_deactivate_confirm_no(
6969
cli_runner, mock_google_user_exists, mock_google_CallGAMCommand, mock_google_move_user_ou, mock_commands_reset
7070
):
7171
mock_google_user_exists.return_value = True
7272

73-
result = cli_runner.invoke(alumni, ["username"])
73+
result = cli_runner.invoke(deactivate, ["username"])
7474

7575
assert result.exit_code == RESULT_SUCCESS
7676
mock_google_CallGAMCommand.assert_not_called()
7777
mock_google_move_user_ou.assert_not_called()
7878

7979

80-
def test_alumni_force(
80+
def test_deactivate_force(
8181
cli_runner, mock_google_user_exists, mock_google_CallGAMCommand, mock_google_move_user_ou, mock_commands_reset
8282
):
8383
mock_google_user_exists.return_value = True
8484

85-
result = cli_runner.invoke(alumni, ["--force", "username"])
85+
result = cli_runner.invoke(deactivate, ["--force", "username"])
8686

8787
assert result.exit_code == RESULT_SUCCESS
8888
mock_google_CallGAMCommand.assert_called()

tests/commands/user/test_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
from compiler_admin.commands.user import user
44

55

6-
@pytest.mark.parametrize("command", ["alumni", "convert", "create", "delete", "offboard", "reset", "restore", "signout"])
6+
@pytest.mark.parametrize("command", ["convert", "create", "deactivate", "delete", "offboard", "reset", "restore", "signout"])
77
def test_user_commands(command):
88
assert command in user.commands

tests/commands/user/test_offboard.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def mock_NamedTemporaryFile(mock_NamedTemporaryFile_with_readlines):
2020

2121

2222
@pytest.fixture
23-
def mock_commands_alumni(mock_commands_alumni):
24-
return mock_commands_alumni(MODULE)
23+
def mock_commands_deactivate(mock_commands_deactivate):
24+
return mock_commands_deactivate(MODULE)
2525

2626

2727
@pytest.fixture
@@ -51,7 +51,7 @@ def test_offboard_confirm_yes(
5151
mock_google_CallGAMCommand,
5252
mock_google_CallGYBCommand,
5353
mock_NamedTemporaryFile,
54-
mock_commands_alumni,
54+
mock_commands_deactivate,
5555
mock_commands_delete,
5656
):
5757
mock_google_user_exists.return_value = True
@@ -63,7 +63,7 @@ def test_offboard_confirm_yes(
6363
mock_google_CallGYBCommand.assert_called_once()
6464
mock_NamedTemporaryFile.assert_called_once()
6565

66-
mock_commands_alumni.callback.assert_called_once()
66+
mock_commands_deactivate.callback.assert_called_once()
6767
mock_commands_delete.callback.assert_called_once()
6868

6969

@@ -73,7 +73,7 @@ def test_offboard_confirm_no(
7373
mock_google_user_exists,
7474
mock_google_CallGAMCommand,
7575
mock_google_CallGYBCommand,
76-
mock_commands_alumni,
76+
mock_commands_deactivate,
7777
mock_commands_delete,
7878
):
7979
mock_google_user_exists.return_value = True
@@ -84,7 +84,7 @@ def test_offboard_confirm_no(
8484
mock_google_CallGAMCommand.assert_not_called()
8585
mock_google_CallGYBCommand.assert_not_called()
8686

87-
mock_commands_alumni.callback.assert_not_called()
87+
mock_commands_deactivate.callback.assert_not_called()
8888
mock_commands_delete.callback.assert_not_called()
8989

9090

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def __mock_command(module):
7777

7878

7979
@pytest.fixture
80-
def mock_commands_alumni(mock_command):
81-
"""Fixture returns a function that patches the alumni function in a given module."""
82-
return mock_command("alumni")
80+
def mock_commands_deactivate(mock_command):
81+
"""Fixture returns a function that patches the deactivate function in a given module."""
82+
return mock_command("deactivate")
8383

8484

8585
@pytest.fixture

0 commit comments

Comments
 (0)