Skip to content

Commit

Permalink
[ENG-3868] Move blocked email domains to post-migrate signal (#9958)
Browse files Browse the repository at this point in the history
* Fix signal and clean-up
* don't use bulk create until ignore_conflicts exsists
* allow BLACKLISTED_DOMAINS to be seamlessly overridden

Co-authored-by: John Tordoff <>
  • Loading branch information
Johnetordoff authored and cslzchen committed Jul 27, 2022
1 parent 5746a84 commit c2c5e4e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
14 changes: 11 additions & 3 deletions osf/apps.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import logging

from django.apps import AppConfig as BaseAppConfig
from django.db.models.signals import post_migrate

from osf.migrations import (
update_permission_groups,
update_waffle_flags,
add_registration_schemas,
create_cache_table,
update_blocked_email_domains,
update_license,
add_registration_schemas
update_permission_groups,
update_waffle_flags,
)

logger = logging.getLogger(__file__)
Expand Down Expand Up @@ -45,3 +48,8 @@ def ready(self):
create_cache_table,
dispatch_uid='osf.apps.create_cache_table'
)

post_migrate.connect(
update_blocked_email_domains,
dispatch_uid='osf.apps.update_blocked_email_domains'
)
3 changes: 3 additions & 0 deletions osf/migrations/0136_preprint_node_divorce.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

logger = logging.getLogger(__name__)


def reverse_func(apps, schema_editor):
PreprintContributor = apps.get_model('osf', 'PreprintContributor')
PreprintTags = apps.get_model('osf', 'Preprint_Tags')
Expand Down Expand Up @@ -83,8 +84,10 @@ def reverse_func(apps, schema_editor):
modified_field.auto_now = True
node_modified_field.auto_now = True


group_format = 'preprint_{self.id}_{group}'


def format_group(self, name):
return group_format.format(self=self, group=name)

Expand Down
2 changes: 0 additions & 2 deletions osf/migrations/0147_blacklistedemaildomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,4 @@ class Migration(migrations.Migration):
'abstract': False,
},
),
migrations.RunPython(populate_blacklisted_domains, remove_blacklisted_domains)

]
12 changes: 12 additions & 0 deletions osf/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from api.base import settings as api_settings
from osf.management.commands.manage_switch_flags import manage_waffle
from osf.utils.migrations import ensure_schemas, map_schemas_to_schemablocks
from website import settings as osf_settings

logger = logging.getLogger(__file__)

Expand Down Expand Up @@ -150,3 +151,14 @@ def add_registration_schemas(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
ensure_schemas()
map_schemas_to_schemablocks()


def update_blocked_email_domains(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
from django.apps import apps
NotableEmailDomain = apps.get_model('osf', 'NotableEmailDomain')
for domain in osf_settings.BLACKLISTED_DOMAINS:
NotableEmailDomain.objects.update_or_create(
domain=domain,
defaults={'note': NotableEmailDomain.Note.EXCLUDE_FROM_ACCOUNT_CREATION},
)

0 comments on commit c2c5e4e

Please sign in to comment.