Skip to content

Commit

Permalink
Merge branch 'feature/django_upgrade' of https://github.com/CenterFor…
Browse files Browse the repository at this point in the history
…OpenScience/osf.io into upgrade-django-misc

* 'feature/django_upgrade' of https://github.com/CenterForOpenScience/osf.io:
  [ENG-3862] Move post-migrate signal out of migration stream for default providers (CenterForOpenScience#9971)
  • Loading branch information
John Tordoff committed Jul 28, 2022
2 parents e9fdd44 + 65b344b commit 0b4dd84
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 14 deletions.
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()
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'],
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()
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

0 comments on commit 0b4dd84

Please sign in to comment.