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
5923675c
Commit
5923675c
authored
Sep 01, 2015
by
Max Rothman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add management command for granting superuser access
parent
f2631faa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
common/djangoapps/student/management/commands/set_superuser.py
+46
-0
No files found.
common/djangoapps/student/management/commands/set_superuser.py
0 → 100644
View file @
5923675c
"""Management command to grant or revoke superuser access for one or more users"""
from
optparse
import
make_option
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
,
CommandError
class
Command
(
BaseCommand
):
"""Management command to grant or revoke superuser access for one or more users"""
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--unset'
,
action
=
'store_true'
,
dest
=
'unset'
,
default
=
False
,
help
=
'Set is_superuser to False instead of True'
),
)
args
=
'<user|email> [user|email ...]>'
help
=
"""
This command will set is_superuser to true for one or more users.
Lookup by username or email address, assumes usernames
do not look like email addresses.
"""
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
<
1
:
raise
CommandError
(
'Usage is set_superuser {0}'
.
format
(
self
.
args
))
for
user
in
args
:
try
:
if
'@'
in
user
:
userobj
=
User
.
objects
.
get
(
email
=
user
)
else
:
userobj
=
User
.
objects
.
get
(
username
=
user
)
if
options
[
'unset'
]:
userobj
.
is_superuser
=
False
else
:
userobj
.
is_superuser
=
True
userobj
.
save
()
except
Exception
as
err
:
# pylint: disable=broad-except
print
"Error modifying user with identifier {}: {}: {}"
.
format
(
user
,
type
(
err
)
.
__name__
,
err
.
message
)
print
'Success!'
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