Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
47401742
Commit
47401742
authored
Jun 18, 2016
by
Kyle Crawshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added 'unusable_password' argument to 'manage_user' management command
parent
519ebed6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletions
+30
-1
common/djangoapps/student/management/commands/manage_user.py
+7
-1
common/djangoapps/student/management/tests/test_manage_user.py
+23
-0
No files found.
common/djangoapps/student/management/commands/manage_user.py
View file @
47401742
...
...
@@ -23,6 +23,7 @@ class Command(BaseCommand):
parser
.
add_argument
(
'--remove'
,
dest
=
'is_remove'
,
action
=
'store_true'
)
parser
.
add_argument
(
'--superuser'
,
dest
=
'is_superuser'
,
action
=
'store_true'
)
parser
.
add_argument
(
'--staff'
,
dest
=
'is_staff'
,
action
=
'store_true'
)
parser
.
add_argument
(
'--unusable-password'
,
dest
=
'unusable_password'
,
action
=
'store_true'
)
parser
.
add_argument
(
'-g'
,
'--groups'
,
nargs
=
'*'
,
default
=
[])
def
_maybe_update
(
self
,
user
,
attribute
,
new_value
):
...
...
@@ -68,7 +69,7 @@ class Command(BaseCommand):
user
.
delete
()
@transaction.atomic
def
handle
(
self
,
username
,
email
,
is_remove
,
is_staff
,
is_superuser
,
groups
,
*
args
,
**
options
):
def
handle
(
self
,
username
,
email
,
is_remove
,
is_staff
,
is_superuser
,
groups
,
unusable_password
,
*
args
,
**
options
):
if
is_remove
:
return
self
.
_handle_remove
(
username
,
email
)
...
...
@@ -91,6 +92,11 @@ class Command(BaseCommand):
self
.
_maybe_update
(
user
,
'is_staff'
,
is_staff
)
self
.
_maybe_update
(
user
,
'is_superuser'
,
is_superuser
)
# Set unusable password if specified
if
unusable_password
and
user
.
has_usable_password
():
self
.
stderr
.
write
(
_
(
'Setting unusable password for user "{}"'
)
.
format
(
user
))
user
.
set_unusable_password
()
# Ensure the user has a profile
try
:
__
=
user
.
profile
...
...
common/djangoapps/student/management/tests/test_manage_user.py
View file @
47401742
...
...
@@ -48,6 +48,29 @@ class TestManageUserCommand(TestCase):
call_command
(
'manage_user'
,
TEST_USERNAME
,
TEST_EMAIL
,
'--remove'
)
self
.
assertEqual
([],
list
(
User
.
objects
.
all
()))
def
test_unusable_password
(
self
):
"""
Ensure that a user's password is set to an unusable_password.
"""
user
=
User
.
objects
.
create
(
username
=
TEST_USERNAME
,
email
=
TEST_EMAIL
)
self
.
assertEqual
([(
TEST_USERNAME
,
TEST_EMAIL
)],
[(
u
.
username
,
u
.
email
)
for
u
in
User
.
objects
.
all
()])
user
.
set_password
(
User
.
objects
.
make_random_password
())
user
.
save
()
# Run once without passing --unusable-password and make sure the password is usable
call_command
(
'manage_user'
,
TEST_USERNAME
,
TEST_EMAIL
)
user
=
User
.
objects
.
get
(
username
=
TEST_USERNAME
,
email
=
TEST_EMAIL
)
self
.
assertTrue
(
user
.
has_usable_password
())
# Make sure the user now has an unusable_password
call_command
(
'manage_user'
,
TEST_USERNAME
,
TEST_EMAIL
,
'--unusable-password'
)
user
=
User
.
objects
.
get
(
username
=
TEST_USERNAME
,
email
=
TEST_EMAIL
)
self
.
assertFalse
(
user
.
has_usable_password
())
# check idempotency
call_command
(
'manage_user'
,
TEST_USERNAME
,
TEST_EMAIL
,
'--unusable-password'
)
self
.
assertFalse
(
user
.
has_usable_password
())
def
test_wrong_email
(
self
):
"""
Ensure that the operation is aborted if the username matches an
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment