Skip to content

Commit

Permalink
remove default provider population from migration to post-migrate signal
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Jul 21, 2022
1 parent 65b0360 commit 6a9ad7a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 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
3 changes: 0 additions & 3 deletions osf/migrations/0138_ensure_subjects_and_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ 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),
]
45 changes: 45 additions & 0 deletions osf/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.apps import apps
from django.db.utils import ProgrammingError
from django.core.management import call_command
from website import settings

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

logger = logging.getLogger(__file__)

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

OSF_REGISTRIES_PROVIDER_DATA = {
'_id': 'osf',
'name': 'OSF Registries',
'domain': 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,35 @@ 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()


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
1 change: 1 addition & 0 deletions osf_tests/test_registration_bulk_upload_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def registration_provider(self, open_ended_schema, provider_subjects):
osf_provider.licenses_acceptable.add(node_license)
osf_provider.schemas.add(open_ended_schema)
osf_provider.subjects.add(*provider_subjects)
osf_provider.licenses_acceptable.add(NodeLicense.objects.get(name='No license'))
osf_provider.save()
return osf_provider

Expand Down

0 comments on commit 6a9ad7a

Please sign in to comment.