-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from girder/oauth-design
- Loading branch information
Showing
5 changed files
with
146 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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,44 @@ | ||
from django.db import migrations | ||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor | ||
from django.db.migrations.state import StateApps | ||
|
||
|
||
def create_default_allauth(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor): | ||
User = apps.get_model('auth', 'User') # noqa: N806 | ||
EmailAddress = apps.get_model('account', 'EmailAddress') # noqa: N806 | ||
|
||
user = User.objects.create_user( | ||
username='[email protected]', | ||
email='[email protected]', | ||
password='password', | ||
first_name='John', | ||
last_name='Doe', | ||
) | ||
EmailAddress.objects.create( | ||
user=user, | ||
email=user.email, | ||
verified=True, | ||
primary=True, | ||
) | ||
|
||
|
||
def delete_default_allauth(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor): | ||
User = apps.get_model('auth', 'User') # noqa: N806 | ||
|
||
User.objects.filter(email='[email protected]').delete() | ||
# EmailAddress will cascade delete | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('auth_style_design', '0001_default_site'), | ||
# This is the final auth app migration | ||
('auth', '0012_alter_user_first_name_max_length'), | ||
# This is the final account (Allauth) app migration | ||
('account', '0002_email_max_length'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_default_allauth, delete_default_allauth), | ||
] |
39 changes: 39 additions & 0 deletions
39
dev/auth_style_design/migrations/0003_default_oauth_application.py
This file contains 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,39 @@ | ||
from django.db import migrations | ||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor | ||
from django.db.migrations.state import StateApps | ||
|
||
|
||
def create_default_oauth_application(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor): | ||
User = apps.get_model('auth', 'User') # noqa: N806 | ||
Application = apps.get_model('oauth2_provider', 'Application') # noqa: N806 | ||
|
||
user = User.objects.get(email='[email protected]') | ||
Application.objects.create( | ||
user=user, | ||
redirect_uris='http://127.0.0.1:8000/ urn:ietf:wg:oauth:2.0:oob', | ||
client_type='public', # Application.CLIENT_PUBLIC | ||
authorization_grant_type='authorization-code', # Application.GRANT_AUTHORIZATION_CODE | ||
client_secret='', | ||
name='auth-style-design', | ||
) | ||
|
||
|
||
def delete_default_oauth_application(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor): | ||
Application = apps.get_model('oauth2_provider', 'Application') # noqa: N806 | ||
|
||
Application.objects.filter(name='auth-style-design').delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('auth_style_design', '0002_default_allauth'), | ||
# This is the final auth app migration | ||
('auth', '0012_alter_user_first_name_max_length'), | ||
# This is the final oauth2_provider app migration | ||
('oauth2_provider', '0005_auto_20211222_2352'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_default_oauth_application, delete_default_oauth_application), | ||
] |
This file contains 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 |
---|---|---|
|
@@ -28,4 +28,3 @@ <h3>Auth templates</h3> | |
</ul> | ||
</body> | ||
</html> | ||
|
This file contains 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 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