-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Script for granting existing instructors creator access. #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
42f7115
Script for making all instructors content creators.
3babf53
Handle the case of script being terminated before the user was deleted.
ce100ba
Add doc strings.
0e0f229
Add doc strings.
27e720c
Make it clear that this should only be run once.
f095c5f
Add ENABLE_CREATOR_GROUP (set to False).
32e6d48
pep8/pylint cleanup.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
cms/djangoapps/contentstore/management/commands/populate_creators.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """ | ||
| Script for granting existing course instructors course creator privileges. | ||
| """ | ||
| from auth.authz import _grant_instructors_creator_access | ||
| from django.core.management.base import BaseCommand | ||
|
|
||
| from django.contrib.auth.models import User | ||
| from django.db.utils import IntegrityError | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| """ | ||
| Script for granting existing course instructors course creator privileges. | ||
| """ | ||
| help = 'Grants all users with INSTRUCTOR role permission to create courses' | ||
|
|
||
| def handle(self, *args, **options): | ||
| """ | ||
| The logic of the command. | ||
| """ | ||
| username = 'populate_creators_command' | ||
| email = 'grant+creator+access@edx.org' | ||
| try: | ||
| admin = User.objects.create_user(username, email, 'foo') | ||
| admin.is_staff = True | ||
| admin.save() | ||
| except IntegrityError: | ||
| # If the script did not complete the last time it was run, | ||
| # the admin user will already exist. | ||
| admin = User.objects.get(username=username, email=email) | ||
|
|
||
| _grant_instructors_creator_access(admin) | ||
| admin.delete() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should document that this is to grandfather in existing instructors. Ideally this will only be run once, ever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will update it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps I should just add a task to delete this code (and the django command) at the end of this story?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although perhaps we will want to run it on edx at some point. Hmmmmm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this kinda feels like a "Migration", but without a schema change. I don't know much about those tools to make a recommendation, maybe Dave O or Victor might have a suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All add a task to the story to delete the code if appropriate.