Skip to content

Commit ad1de64

Browse files
authored
Add option to retire user with no edx account (#2891)
1 parent 1d496b4 commit ad1de64

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

users/management/commands/retire_users.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class Command(BaseCommand):
4545
For blocking user(s) use --block option:\n
4646
`./manage.py retire_users [email protected] --block` or do \n
4747
`./manage.py retire_users -u [email protected] -b` \n or do \n
48+
49+
For retiring a user who doesn't have an edX account, use the `--no-edx` option to retire user anyway:\n
50+
./manage.py retire_users [email protected] --no-edx \n
4851
"""
4952

5053
def create_parser(self, prog_name, subcommand): # pylint: disable=arguments-differ
@@ -76,13 +79,22 @@ def add_arguments(self, parser):
7679
help="If provided, user's email will be hashed and added to the blocklist",
7780
)
7881

82+
parser.add_argument(
83+
"-e",
84+
"--no-edx",
85+
action="store_true",
86+
dest="no_edx",
87+
help="If provided, user will be retired even if they do not have an edX account",
88+
)
89+
7990
def get_retired_email(self, email):
8091
"""Convert user email to retired email format."""
8192
return user_util.get_retired_email(email, RETIRED_USER_SALTS, RETIRED_EMAIL_FMT)
8293

8394
def handle(self, *args, **kwargs): # noqa: ARG002
8495
users = kwargs.get("users", [])
8596
block_users = kwargs.get("block_users")
97+
no_edx = kwargs.get("no_edx", False)
8698

8799
if not users:
88100
self.stderr.write(
@@ -103,21 +115,21 @@ def handle(self, *args, **kwargs): # noqa: ARG002
103115
)
104116
)
105117
continue
106-
107-
resp = bulk_retire_edx_users(user.edx_username)
108-
if user.edx_username not in resp["successful_user_retirements"]:
109-
self.stderr.write(
110-
self.style.ERROR(
111-
f"Could not initiate retirement request on edX for user {user}"
118+
if not no_edx:
119+
resp = bulk_retire_edx_users(user.edx_username)
120+
if user.edx_username not in resp["successful_user_retirements"]:
121+
self.stderr.write(
122+
self.style.ERROR(
123+
f"Could not initiate retirement request on edX for user {user}"
124+
)
112125
)
113-
)
114-
continue
115-
else:
116-
self.stdout.write(
117-
self.style.SUCCESS(
118-
f"Retirement request initiated on edX for User: '{user}'"
126+
continue
127+
else:
128+
self.stdout.write(
129+
self.style.SUCCESS(
130+
f"Retirement request initiated on edX for User: '{user}'"
131+
)
119132
)
120-
)
121133

122134
user.is_active = False
123135

0 commit comments

Comments
 (0)