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)
  [ENG-3866] Move citation style population out of migration stream (CenterForOpenScience#9966)
  [ENG-3868] Move blocked email domains to post-migrate signal (CenterForOpenScience#9958)
  [ENG-3863] Move schema ensuring and schema blocks update to post-migrate signals (CenterForOpenScience#9974)
  [ENG-3865] Create Licenses using post-migrate signal (CenterForOpenScience#9961)
  [ENG-3836] Investigate waffle flags (CenterForOpenScience#9950)
  move createcachetable to post migrate signal (CenterForOpenScience#9944)
  remove post-migrate signals from migration stream (CenterForOpenScience#9964)
  [ENG-3898][ENG-3899]Model support for OutcomeArtifact update and delete (CenterForOpenScience#9989)
  Make OutcomeArtifact.identifier nullable (CenterForOpenScience#9986)
  [ENG-3894] Outcome models (CenterForOpenScience#9975)
  revert color picker to working version (CenterForOpenScience#9968)

# Conflicts:
#	api/base/settings/defaults.py
#	osf/migrations/0037_ensure_licenses.py
#	osf/migrations/0038_ensure_schemas.py
#	osf/migrations/0074_parse_citation_styles.py
#	osf/migrations/0077_ensure_schemas.py
#	osf/migrations/0078_ensure_schemas.py
#	osf/migrations/0080_ensure_schemas.py
#	osf/migrations/0083_add_ember_waffle_flags.py
#	osf/migrations/0095_add_url_to_licenses.py
#	osf/migrations/0095_ensure_licenses.py
#	osf/migrations/0096_ensure_schemas.py
#	osf/migrations/0099_add_default_storage_region.py
#	osf/migrations/0107_add_dependent_styles.py
#	osf/migrations/0112_ensure_schemas.py
#	osf/migrations/0121_remove_support_page_waffle_flag.py
#	osf/migrations/0121_remove_waffle_flags.py
#	osf/migrations/0135_user_settings_waffles.py
#	osf/migrations/0136_add_ember_auth_register_waffle_flag.py
#	osf/migrations/0136_preprint_node_divorce.py
#	osf/migrations/0137_transfer_preprint_service_permissions.py
#	osf/migrations/0138_ensure_subjects_and_providers.py
#	osf/migrations/0142_change_registration_schemas.py
#	osf/migrations/0142_remove_forks_flag.py
#	osf/migrations/0142_remove_waffle_analytics_flags.py
#	osf/migrations/0144_add_prereg_winddown_switches.py
#	osf/migrations/0147_blacklistedemaildomain.py
#	osf/migrations/0149_add_datacite_doi_switch.py
#	osf/migrations/0152_ensure_schemas.py
#	osf/migrations/0154_remove_ember_project_registrations_flag.py
#	osf/migrations/0156_create_cache_table.py
#	osf/migrations/0157_add_storage_usage_flag.py
#	osf/migrations/0162_post_migrate.py
#	osf/migrations/0167_auto_20190506_1556.py
#	osf/migrations/0170_ensure_schemas.py
#	osf/migrations/0172_ensure_schemas.py
#	osf/migrations/0173_ensure_schemas.py
#	osf/migrations/0174_add_ab_testing_home_page_version_b_flag.py
#	osf/migrations/0191_migrate_schemas_to_schemablocks.py
#	osf/migrations/0195_add_enable_chronos_waffle_flag.py
#	osf/migrations/0196_update_schemas.py
#	osf/migrations/0197_add_ab_testing_home_page_hero_text_version_b_flag.py
#	osf/migrations/0199_draft_node_permissions.py
#	osf/migrations/0201_add_egap_flag.py
#	osf/migrations/0204_ensure_schemas.py
#	osf/migrations/0207_ensure_schemas.py
#	osf/migrations/0207_update_schemas2.py
#	osf/migrations/0208_update_EGAP_schema.py
#	osf/migrations/0221_add_schemas.py
#	osf/migrations/0227_add_secondary_data.py
#	osf/migrations/__init__.py
#	osf_tests/test_registration_bulk_upload_parser.py
  • Loading branch information
John Tordoff committed Jul 27, 2022
2 parents 57f3a9e + 250b832 commit f31cfc3
Show file tree
Hide file tree
Showing 17 changed files with 1,671 additions and 329 deletions.
2 changes: 1 addition & 1 deletion admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"babel-core": "^6.0.0",
"babel-loader": "^6.4.1",
"bootstrap-colorpicker": "^3.4.0",
"bootstrap-colorpicker": "^2.5.2",
"bootstrap-tagsinput": "^0.7.1",
"bower": "^1.3.12",
"font-awesome": "^4.5.0",
Expand Down
1,169 changes: 873 additions & 296 deletions admin/yarn.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion api/base/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,4 @@
TRAVIS_ENV = False

CITATION_STYLES_REPO_URL = 'https://github.com/CenterForOpenScience/styles/archive/88e6ed31a91e9f5a480b486029cda97b535935d4.zip'

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
18 changes: 18 additions & 0 deletions osf/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,21 @@ def __init__(self, response, invalid_responses=None, unsupported_keys=None):
)

super().__init__(error_message)


class IdentifierHasReferencesError(OSFError):
pass


class NoPIDError(OSFError):
pass


class CannotFinalizeArtifactError(OSFError):

def __init__(self, artifact, incomplete_fields):
self.incomplete_fields = incomplete_fields
self.message = (
f'Could not set `finalized=True` for OutcomeArtifact with id [{artifact._id}]. '
f'The following required fields are not set: {incomplete_fields}'
)
109 changes: 109 additions & 0 deletions osf/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3503,4 +3503,113 @@ class Migration(migrations.Migration):
model_name='abstractnode',
index=models.Index(fields=['-registered_date'], name='registered_date_index'),
),
migrations.CreateModel(
name='Outcome',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created',
django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
('modified',
django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
('_id', models.CharField(db_index=True, default=osf.models.base.generate_object_id, max_length=24,
unique=True)),
('title', models.TextField(validators=[osf.models.validators.validate_title])),
('description', models.TextField(blank=True, default='')),
('category', models.CharField(blank=True,
choices=[('analysis', 'Analysis'), ('communication', 'Communication'),
('data', 'Data'), ('hypothesis', 'Hypothesis'),
('instrumentation', 'Instrumentation'),
('methods and measures', 'Methods and Measures'),
('procedure', 'Procedure'), ('project', 'Project'),
('software', 'Software'), ('other', 'Other'),
('', 'Uncategorized')], default='', max_length=255)),
('affiliated_institutions', models.ManyToManyField(related_name='outcomes', to='osf.Institution')),
],
options={
'abstract': False,
},
bases=(models.Model, osf.models.base.QuerySetExplainMixin),
),
migrations.CreateModel(
name='OutcomeArtifact',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created',
django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
('modified',
django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
('_id', models.CharField(db_index=True, default=osf.models.base.generate_object_id, max_length=24,
unique=True)),
('artifact_type', models.IntegerField(
choices=[(0, 'UNDEFINED'), (1, 'DATA'), (11, 'CODE'), (21, 'MATERIALS'), (31, 'PAPERS'),
(41, 'SUPPLEMENTS'), (1001, 'PRIMARY')], default=osf.utils.outcomes.ArtifactTypes(0))),
('title', models.TextField()),
('description', models.TextField()),
('identifier', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE,
related_name='artifact_metadata', to='osf.Identifier')),
('outcome',
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='artifact_metadata',
to='osf.Outcome')),
],
options={
'ordering': ['artifact_type', 'title'],
},
bases=(models.Model, osf.models.base.QuerySetExplainMixin),
),
migrations.AddField(
model_name='outcome',
name='artifacts',
field=models.ManyToManyField(through='osf.OutcomeArtifact', to='osf.Identifier'),
),
migrations.AddField(
model_name='outcome',
name='node_license',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL,
related_name='outcomes', to='osf.NodeLicenseRecord'),
),
migrations.AddField(
model_name='outcome',
name='subjects',
field=models.ManyToManyField(blank=True, related_name='outcomes', to='osf.Subject'),
),
migrations.AddField(
model_name='outcome',
name='tags',
field=models.ManyToManyField(related_name='outcome_tagged', to='osf.Tag'),
),
migrations.AddIndex(
model_name='outcomeartifact',
index=models.Index(fields=['outcome', 'artifact_type'], name='osf_outcome_outcome_a62f5c_idx'),
),
migrations.AlterUniqueTogether(
name='outcomeartifact',
unique_together=set([('outcome', 'identifier', 'artifact_type')]),
),
migrations.AddField(
model_name='outcomeartifact',
name='deleted',
field=osf.utils.fields.NonNaiveDateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='outcomeartifact',
name='finalized',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='outcomeartifact',
name='description',
field=models.TextField(blank=True),
),
migrations.AlterField(
model_name='outcomeartifact',
name='title',
field=models.TextField(blank=True),
),
migrations.AlterField(
model_name='outcomeartifact',
name='artifact_type',
field=models.IntegerField(
choices=[(0, 'UNDEFINED'), (1, 'DATA'), (11, 'ANALYTIC_CODE'), (21, 'MATERIALS'), (31, 'PAPERS'),
(41, 'SUPPLEMENTS'), (1001, 'PRIMARY')], default=osf.utils.outcomes.ArtifactTypes(0)),
),
]
18 changes: 0 additions & 18 deletions osf/migrations/0003_alter_basefilenode_name.py

This file was deleted.

16 changes: 12 additions & 4 deletions osf/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
import sys
import os
import json
import logging

from django.db.utils import ProgrammingError
from website.settings import APP_PATH

from django.apps import apps
from website import settings


import logging

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

from addons.osfstorage.settings import DEFAULT_REGION_ID, DEFAULT_REGION_NAME
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
Expand Down Expand Up @@ -164,6 +166,7 @@ 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()
Expand Down Expand Up @@ -263,6 +266,11 @@ def update_blocked_email_domains(sender, verbosity=0, **kwargs):
)


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')
Expand Down
2 changes: 2 additions & 0 deletions osf/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@
from osf.models.schema_response_block import SchemaResponseBlock # noqa
from osf.models.registration_bulk_upload_job import RegistrationBulkUploadJob # noqa
from osf.models.registration_bulk_upload_row import RegistrationBulkUploadRow # noqa
from osf.models.outcomes import Outcome # noqa
from osf.models.outcome_artifacts import OutcomeArtifact # noqa
8 changes: 8 additions & 0 deletions osf/models/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils import timezone

from osf.exceptions import IdentifierHasReferencesError
from osf.models.base import BaseModel, ObjectIDMixin
from osf.utils.fields import NonNaiveDateTimeField

Expand All @@ -28,6 +30,12 @@ def remove(self, save=True):
if save:
self.save()

def delete(self):
'''Used to delete an orphaned Identifier (distinct from setting `deleted`)'''
if self.object_id or self.artifact_metadata.filter(deleted__isnull=True).exists():
raise IdentifierHasReferencesError
super().delete()


class IdentifierMixin(models.Model):
"""Model mixin that adds methods for getting and setting Identifier objects
Expand Down
13 changes: 7 additions & 6 deletions osf/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,7 @@ def stage_m2m_values(self, fieldname, resource, alternative_resource=None):
else:
return []

def copy_editable_fields(self, resource, auth=None, alternative_resource=None, save=True):
def copy_editable_fields(self, resource, auth=None, alternative_resource=None, include_contributors=True, save=True):
"""
Copy various editable fields from the 'resource' object to the current object.
Includes, title, description, category, contributors, node_license, tags, subjects, and affiliated_institutions
Expand All @@ -2257,11 +2257,12 @@ def copy_editable_fields(self, resource, auth=None, alternative_resource=None, s
self.set_editable_attribute('category', resource, alternative_resource)
self.set_editable_attribute('node_license', resource, alternative_resource)

# Contributors will always come from "resource", as contributor constraints
# will require contributors to be present on the resource
self.copy_contributors_from(resource)
# Copy unclaimed records for unregistered users
self.copy_unclaimed_records(resource)
if include_contributors:
# Contributors will always come from "resource", as contributor constraints
# will require contributors to be present on the resource
self.copy_contributors_from(resource)
# Copy unclaimed records for unregistered users
self.copy_unclaimed_records(resource)

self.tags.add(*self.stage_m2m_values('all_tags', resource, alternative_resource))
self.subjects.add(*self.stage_m2m_values('subjects', resource, alternative_resource))
Expand Down
7 changes: 6 additions & 1 deletion osf/models/nodelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class NodeLog(ObjectIDMixin, BaseModel):

MIGRATED_QUICK_FILES = 'migrated_quickfiles'

RESOURCE_ADDED = 'resource_identifier_added'
RESOURCE_UPDATED = 'resource_identifier_udpated'
RESOURCE_REMOVED = 'resource_identifier_removed'

actions = ([CHECKED_IN, CHECKED_OUT, FILE_TAG_REMOVED, FILE_TAG_ADDED, CREATED_FROM, PROJECT_CREATED,
PROJECT_REGISTERED, PROJECT_DELETED, NODE_CREATED, NODE_FORKED, NODE_REMOVED,
NODE_ACCESS_REQUESTS_ENABLED, NODE_ACCESS_REQUESTS_DISABLED,
Expand All @@ -157,7 +161,8 @@ class NodeLog(ObjectIDMixin, BaseModel):
PREREG_REGISTRATION_INITIATED, PROJECT_CREATED_FROM_DRAFT_REG,
GROUP_ADDED, GROUP_UPDATED, GROUP_REMOVED,
AFFILIATED_INSTITUTION_ADDED, AFFILIATED_INSTITUTION_REMOVED, PREPRINT_INITIATED,
PREPRINT_FILE_UPDATED, PREPRINT_LICENSE_UPDATED, VIEW_ONLY_LINK_ADDED, VIEW_ONLY_LINK_REMOVED] + list(sum([
PREPRINT_FILE_UPDATED, PREPRINT_LICENSE_UPDATED, VIEW_ONLY_LINK_ADDED, VIEW_ONLY_LINK_REMOVED,
RESOURCE_ADDED, RESOURCE_UPDATED, RESOURCE_REMOVED] + list(sum([
config.actions for config in apps.get_app_configs() if config.name.startswith('addons.')
], tuple())))
action_choices = [(action, action.upper()) for action in actions]
Expand Down
Loading

0 comments on commit f31cfc3

Please sign in to comment.