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 upguard-indexes

* 'feature/django_upgrade' of https://github.com/CenterForOpenScience/osf.io:
  [ENG-3867] Create Storage Regions on post migration signal (CenterForOpenScience#9965)

# Conflicts:
#	osf/migrations/__init__.py
  • Loading branch information
John Tordoff committed Jul 21, 2022
2 parents 37a61ff + 65b0360 commit aef69e0
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
6 changes: 6 additions & 0 deletions api_tests/base/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from tests.utils import make_drf_request_with_version

from osf.models import RegistrationSchema
from osf.migrations import ensure_default_providers

from api.base.settings.defaults import API_BASE
from api.schemas.serializers import SchemaSerializer
Expand Down Expand Up @@ -90,6 +91,11 @@ def valued_field(*args, **kwargs):


class TestSerializerMetaType(ApiTestCase):

@pytest.fixture(autouse=True)
def default_provider(self):
ensure_default_providers()

def test_expected_serializers_have_meta_types(self):
for ser in SER_CLASSES:
assert hasattr(
Expand Down
6 changes: 6 additions & 0 deletions osf/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
update_blocked_email_domains,
update_license,
update_permission_groups,
update_storage_regions,
update_waffle_flags,
)

Expand Down Expand Up @@ -53,3 +54,8 @@ def ready(self):
update_blocked_email_domains,
dispatch_uid='osf.apps.update_blocked_email_domains'
)

post_migrate.connect(
update_storage_regions,
dispatch_uid='osf.apps.update_storage_regions'
)
1 change: 0 additions & 1 deletion osf/migrations/0099_add_default_storage_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(add_osfstorage_addon, remove_osfstorage_addon),
]
40 changes: 20 additions & 20 deletions osf/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

from django.db.utils import ProgrammingError
from website.settings import APP_PATH
from addons.osfstorage.settings import DEFAULT_REGION_ID, DEFAULT_REGION_NAME

from django.apps import apps
from website import settings

from django.core.management import call_command

from addons.osfstorage.settings import DEFAULT_REGION_ID, DEFAULT_REGION_NAME
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
Expand Down Expand Up @@ -164,25 +164,6 @@ def update_waffle_flags(sender, verbosity=0, **kwargs):
logger.info('Waffle flags have been synced')


def update_storage_regions(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
ensure_default_storage_region()


def ensure_default_storage_region():
osfstorage_config = apps.get_app_config('addons_osfstorage')
Region = apps.get_model('addons_osfstorage', 'Region')
Region.objects.update_or_create(
_id=DEFAULT_REGION_ID,
defaults={
'name': DEFAULT_REGION_NAME,
'waterbutler_credentials': osfstorage_config.WATERBUTLER_CREDENTIALS,
'waterbutler_settings': osfstorage_config.WATERBUTLER_SETTINGS,
'waterbutler_url': settings.WATERBUTLER_URL
}
)


def ensure_subjects():
Subject = apps.get_model('osf.subject')
PreprintProvider = apps.get_model('osf.preprintprovider')
Expand Down Expand Up @@ -275,3 +256,22 @@ def update_blocked_email_domains(sender, verbosity=0, **kwargs):
domain=domain,
defaults={'note': NotableEmailDomain.Note.EXCLUDE_FROM_ACCOUNT_CREATION},
)


def update_storage_regions(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
ensure_default_storage_region()


def ensure_default_storage_region():
osfstorage_config = apps.get_app_config('addons_osfstorage')
Region = apps.get_model('addons_osfstorage', 'Region')
Region.objects.get_or_create(
_id=DEFAULT_REGION_ID,
name=DEFAULT_REGION_NAME,
defaults={
'waterbutler_credentials': osfstorage_config.WATERBUTLER_CREDENTIALS,
'waterbutler_settings': osfstorage_config.WATERBUTLER_SETTINGS,
'waterbutler_url': osf_settings.WATERBUTLER_URL
}
)
9 changes: 9 additions & 0 deletions osf_tests/test_draft_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from framework.exceptions import PermissionsError
from osf.exceptions import UserNotAffiliatedError, DraftRegistrationStateError, NodeStateError
from osf.models import RegistrationSchema, DraftRegistration, DraftRegistrationContributor, NodeLicense, Node, NodeLog
from osf.migrations import ensure_default_providers
from osf.utils.migrations import ensure_schemas, map_schemas_to_schemablocks
from osf.utils.permissions import ADMIN, READ, WRITE
from osf_tests.test_node import TestNodeEditableFieldsMixin, TestTagging, TestNodeSubjects
from osf_tests.test_node_license import TestNodeLicenses
Expand Down Expand Up @@ -36,6 +38,13 @@ def draft_registration(project):

class TestDraftRegistrations:
# copied from tests/test_registrations/test_models.py

@pytest.fixture(autouse=True)
def default_providers(self):
ensure_schemas()
map_schemas_to_schemablocks()
ensure_default_providers()

def test_factory(self):
draft = factories.DraftRegistrationFactory()
assert draft.branched_from is not None
Expand Down
1 change: 1 addition & 0 deletions website/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2108,4 +2108,5 @@ def from_node_usage(cls, usage_bytes, private_limit=None, public_limit=None):
CAS_LOG_LEVEL = 3 # ERROR

PREPRINT_METRICS_START_DATE = datetime.datetime(2019, 1, 1)

WAFFLE_VALUES_YAML = 'osf/features.yaml'

0 comments on commit aef69e0

Please sign in to comment.