Skip to content
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

[ENG-3862][Take 2] Move post-migrate signal out of migration stream for default providers #9971

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions osf/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
update_permission_groups,
update_storage_regions,
update_waffle_flags,
update_default_providers
)

logger = logging.getLogger(__file__)
Expand Down Expand Up @@ -50,6 +51,11 @@ def ready(self):
dispatch_uid='osf.apps.create_cache_table'
)

post_migrate.connect(
update_default_providers,
dispatch_uid='osf.apps.update_default_providers'
)

post_migrate.connect(
update_blocked_email_domains,
dispatch_uid='osf.apps.update_blocked_email_domains'
Expand Down
4 changes: 0 additions & 4 deletions osf/migrations/0138_ensure_subjects_and_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,5 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(create_osf_registries, migrations.RunPython.noop),
] if getattr(settings, 'TEST_ENV', False) else [
migrations.RunPython(create_osf_preprints, migrations.RunPython.noop),
migrations.RunPython(create_subjects, migrations.RunPython.noop),
migrations.RunPython(create_osf_registries, migrations.RunPython.noop),
]
49 changes: 48 additions & 1 deletion osf/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import logging

from django.apps import apps
from django.db.utils import ProgrammingError
from django.core.management import call_command
from django.db.utils import ProgrammingError

from addons.osfstorage.settings import DEFAULT_REGION_ID, DEFAULT_REGION_NAME
from api.base import settings as api_settings
Expand All @@ -14,6 +14,22 @@

logger = logging.getLogger(__file__)

OSF_PREPRINTS_PROVIDER_DATA = {
'_id': 'osf',
'name': 'Open Science Framework',
'domain': osf_settings.DOMAIN,
'share_publish_type': 'Preprint',
'domain_redirect_enabled': False,
}

OSF_REGISTRIES_PROVIDER_DATA = {
'_id': 'osf',
'name': 'OSF Registries',
'domain': osf_settings.DOMAIN,
'share_publish_type': 'Registration',
'domain_redirect_enabled': False,
}


# Admin group permissions
def get_admin_read_permissions():
Expand Down Expand Up @@ -149,6 +165,37 @@ def create_cache_table(sender, verbosity=0, **kwargs):
call_command('createcachetable', tablename=api_settings.CACHES[api_settings.STORAGE_USAGE_CACHE_NAME]['LOCATION'])


def update_default_providers(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
if 'pytest' in sys.modules:
ensure_default_registration_provider()
cslzchen marked this conversation as resolved.
Show resolved Hide resolved
else:
ensure_default_providers()


def ensure_default_providers():
ensure_default_preprint_provider()
ensure_default_registration_provider()


def ensure_default_preprint_provider():
PreprintProvider = apps.get_model('osf', 'PreprintProvider')

PreprintProvider.objects.update_or_create(
_id=OSF_PREPRINTS_PROVIDER_DATA['_id'],
cslzchen marked this conversation as resolved.
Show resolved Hide resolved
defaults=OSF_PREPRINTS_PROVIDER_DATA
)


def ensure_default_registration_provider():
RegistrationProvider = apps.get_model('osf', 'RegistrationProvider')

RegistrationProvider.objects.update_or_create(
_id=OSF_REGISTRIES_PROVIDER_DATA['_id'],
defaults=OSF_REGISTRIES_PROVIDER_DATA
)


def add_registration_schemas(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
ensure_schemas()
Expand Down
5 changes: 3 additions & 2 deletions osf/models/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ def get_default_id(cls):
""",
[cls.default__id]
)
default_id = cursor.fetchone()[0]
return default_id
default_id = cursor.fetchone()
if default_id:
return default_id[0]

@property
def readable_type(self):
Expand Down
15 changes: 8 additions & 7 deletions osf_tests/test_registration_bulk_upload_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ def provider_subjects(self):

@pytest.fixture()
def registration_provider(self, open_ended_schema, provider_subjects):
osf_provider = RegistrationProvider.load('osf')
provider = RegistrationProvider.get_default()
cslzchen marked this conversation as resolved.
Show resolved Hide resolved
node_license = NodeLicense.objects.get(name='No license')
osf_provider.default_license = node_license
osf_provider.licenses_acceptable.add(node_license)
osf_provider.schemas.add(open_ended_schema)
osf_provider.subjects.add(*provider_subjects)
osf_provider.save()
return osf_provider
provider.default_license = node_license
provider.licenses_acceptable.add(node_license)
provider.schemas.add(open_ended_schema)
provider.subjects.add(*provider_subjects)
provider.licenses_acceptable.add(NodeLicense.objects.get(name='No license'))
provider.save()
return provider

@pytest.fixture()
def question_headers(self):
Expand Down