Skip to content

Commit

Permalink
fix preprint state names
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Apr 18, 2024
1 parent 2fe1384 commit 01a7f3a
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 86 deletions.
6 changes: 3 additions & 3 deletions api/actions/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from api.base.utils import get_user_auth
from osf.models import CollectionSubmissionAction
from osf.models.action import BaseAction
from osf.models.mixins import ReviewableMixin, ReviewProviderMixin
from osf.models.mixins import PreprintStateMachineMixin, ModerationProviderMixin
from osf.utils.workflows import ReviewTriggers
from osf.utils import permissions as osf_permissions

Expand All @@ -30,10 +30,10 @@ def has_object_permission(self, request, view, obj):
if isinstance(obj, tuple(BaseAction.__subclasses__())):
target = obj.target
provider = target.provider
elif isinstance(obj, ReviewableMixin):
elif isinstance(obj, PreprintStateMachineMixin):
target = obj
provider = target.provider
elif isinstance(obj, ReviewProviderMixin):
elif isinstance(obj, ModerationProviderMixin):
provider = obj
elif isinstance(obj, CollectionSubmissionAction):
provider = obj
Expand Down
6 changes: 3 additions & 3 deletions api/actions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from framework.auth.oauth_scopes import CoreScopes
from osf.models import (
PreprintProvider,
ReviewAction,
PreprintStateAction,
NodeRequestAction,
PreprintRequestAction,
BaseAction,
Expand All @@ -31,7 +31,7 @@


def get_review_actions_queryset():
return ReviewAction.objects.prefetch_related(
return PreprintStateAction.objects.prefetch_related(
'creator__guids',
'target__guids',
'target__provider',
Expand Down Expand Up @@ -163,7 +163,7 @@ class ReviewActionListCreate(JSONAPIBaseView, generics.ListCreateAPIView, ListFi

parser_classes = (JSONAPIMultipleRelationshipsParser, JSONAPIMultipleRelationshipsParserForRegularJSON,)
serializer_class = ReviewActionSerializer
model_class = ReviewAction
model_class = PreprintStateAction

ordering = ('-created',)
view_category = 'actions'
Expand Down
4 changes: 2 additions & 2 deletions api/draft_nodes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
NodeFileHyperLinkField,
)
from api.base.utils import absolute_reverse
from api.nodes.serializers import NodeStorageProviderSerializer
from api.nodes.serializers import AddonStorageProviderSerializer


class DraftNodeSerializer(JSONAPISerializer):
Expand Down Expand Up @@ -45,7 +45,7 @@ class Meta:
type_ = 'draft-nodes'


class DraftNodeStorageProviderSerializer(NodeStorageProviderSerializer):
class DraftNodeStorageProviderSerializer(AddonStorageProviderSerializer):
files = NodeFileHyperLinkField(
related_view='draft_nodes:node-files',
related_view_kwargs={'node_id': '<node._id>', 'path': '<path>', 'provider': '<provider>'},
Expand Down
2 changes: 1 addition & 1 deletion api/nodes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ def get_absolute_url(self, obj):
)


class NodeStorageProviderSerializer(JSONAPISerializer):
class AddonStorageProviderSerializer(JSONAPISerializer):
id = ser.SerializerMethodField(read_only=True)
kind = ser.CharField(read_only=True)
name = ser.CharField(read_only=True)
Expand Down
6 changes: 3 additions & 3 deletions api/nodes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
NodeLinksSerializer,
NodeForksSerializer,
NodeDetailSerializer,
NodeStorageProviderSerializer,
AddonStorageProviderSerializer,
DraftRegistrationLegacySerializer,
DraftRegistrationDetailLegacySerializer,
NodeContributorsSerializer,
Expand Down Expand Up @@ -1500,7 +1500,7 @@ class NodeStorageProvidersList(JSONAPIBaseView, generics.ListAPIView, NodeMixin)
required_read_scopes = [CoreScopes.NODE_FILE_READ]
required_write_scopes = [CoreScopes.NODE_FILE_WRITE]

serializer_class = NodeStorageProviderSerializer
serializer_class = AddonStorageProviderSerializer
view_category = 'nodes'
view_name = 'node-storage-providers'

Expand Down Expand Up @@ -1531,7 +1531,7 @@ class NodeStorageProviderDetail(JSONAPIBaseView, generics.RetrieveAPIView, NodeM
required_read_scopes = [CoreScopes.NODE_FILE_READ]
required_write_scopes = [CoreScopes.NODE_FILE_WRITE]

serializer_class = NodeStorageProviderSerializer
serializer_class = AddonStorageProviderSerializer
view_category = 'nodes'
view_name = 'node-storage-provider-detail'

Expand Down
4 changes: 2 additions & 2 deletions api/preprints/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
NodeLicenseRelationshipField,
NodeLicenseSerializer,
NodeContributorsSerializer,
NodeStorageProviderSerializer,
AddonStorageProviderSerializer,
NodeContributorsCreateSerializer,
NodeContributorDetailSerializer,
get_license_details,
Expand Down Expand Up @@ -480,7 +480,7 @@ class PreprintContributorDetailSerializer(NodeContributorDetailSerializer, Prepr
index = ser.IntegerField(required=False, read_only=False, source='_order')


class PreprintStorageProviderSerializer(NodeStorageProviderSerializer):
class PreprintStorageProviderSerializer(AddonStorageProviderSerializer):
node = HideIfPreprint(ser.CharField(source='node_id', read_only=True))
preprint = ser.CharField(source='node_id', read_only=True)

Expand Down
4 changes: 2 additions & 2 deletions api/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rest_framework import permissions as drf_permissions

from framework.auth.oauth_scopes import CoreScopes
from osf.models import ReviewAction, Preprint, PreprintContributor
from osf.models import PreprintStateAction, Preprint, PreprintContributor
from osf.utils.requests import check_select_for_update

from api.actions.permissions import ReviewActionPermission
Expand Down Expand Up @@ -505,7 +505,7 @@ class PreprintActionList(JSONAPIBaseView, generics.ListCreateAPIView, ListFilter

parser_classes = (JSONAPIMultipleRelationshipsParser, JSONAPIMultipleRelationshipsParserForRegularJSON,)
serializer_class = ReviewActionSerializer
model_class = ReviewAction
model_class = PreprintStateAction

ordering = ('-created',)
view_category = 'preprints'
Expand Down
6 changes: 3 additions & 3 deletions api/registrations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from api.files.serializers import OsfStorageFileSerializer
from api.nodes.serializers import (
NodeSerializer,
NodeStorageProviderSerializer,
AddonStorageProviderSerializer,
NodeLicenseRelationshipField,
NodeLinksSerializer,
update_institutions,
Expand Down Expand Up @@ -851,9 +851,9 @@ class RegistrationFileSerializer(OsfStorageFileSerializer):
help_text='The registration that this file belongs to',
)

class RegistrationStorageProviderSerializer(NodeStorageProviderSerializer):
class RegistrationStorageProviderSerializer(AddonStorageProviderSerializer):
"""
Overrides NodeStorageProviderSerializer to lead to correct registration file links
Overrides AddonStorageProviderSerializer to lead to correct registration file links
"""
files = NodeFileHyperLinkField(
related_view='registrations:registration-files',
Expand Down
4 changes: 2 additions & 2 deletions osf/management/commands/create_fake_preprint_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from django.core.management.base import BaseCommand

from osf.models import ReviewAction, Preprint, OSFUser
from osf.models import PreprintStateAction, Preprint, OSFUser
from osf.utils.workflows import DefaultStates, DefaultTriggers

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,7 +48,7 @@ def handle(self, *args, **options):
states = [s.value for s in DefaultStates]
for preprint in Preprint.objects.filter(actions__isnull=True):
for i in range(num_actions):
action = ReviewAction(
action = PreprintStateAction(
target=preprint,
creator=user,
trigger=random.choice(triggers),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def populate_collection_provider_notification_subscriptions():
provider_admins = provider.get_group('admin').user_set.all()
provider_moderators = provider.get_group('moderator').user_set.all()

for subscription in provider.DEFAULT_SUBSCRIPTIONS:
for subscription in provider.DEFAULT_EMAIL_SUBSCRIPTIONS:
instance, created = NotificationSubscription.objects.get_or_create(
_id=f'{provider._id}_{subscription}',
event_name=subscription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def populate_registration_provider_notification_subscriptions():
logger.warn('Unable to find groups for provider "{}", assuming there are no subscriptions to create.'.format(provider._id))
continue

for subscription in provider.DEFAULT_SUBSCRIPTIONS:
for subscription in provider.DEFAULT_EMAIL_SUBSCRIPTIONS:
instance, created = NotificationSubscription.objects.get_or_create(
_id=f'{provider._id}_{subscription}',
event_name=subscription,
Expand Down
4 changes: 2 additions & 2 deletions osf/management/commands/update_auth_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.core.management.base import BaseCommand
from django.db import transaction

from osf.models.mixins import ReviewProviderMixin
from osf.models.mixins import ModerationProviderMixin

logger = logging.getLogger(__name__)

Expand All @@ -27,7 +27,7 @@ def handle(self, *args, **options):

# Start a transaction that will be rolled back if any exceptions are raised
with transaction.atomic():
for cls in ReviewProviderMixin.__subclasses__():
for cls in ModerationProviderMixin.__subclasses__():
for provider in cls.objects.all():
logger.info('Updating auth groups for review provider %s', provider)
provider.update_group_permissions()
Expand Down
2 changes: 1 addition & 1 deletion osf/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ class Migration(migrations.Migration):
bases=(models.Model, osf.models.base.QuerySetExplainMixin),
),
migrations.CreateModel(
name='ReviewAction',
name='PreprintStateAction',
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')),
Expand Down
2 changes: 1 addition & 1 deletion osf/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
NodeRequestAction,
PreprintRequestAction,
RegistrationAction,
ReviewAction,
PreprintStateAction,
SchemaResponseAction,
)
from .admin_log_entry import AdminLogEntry
Expand Down
2 changes: 1 addition & 1 deletion osf/models/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def target(self):
raise NotImplementedError()


class ReviewAction(BaseAction):
class PreprintStateAction(BaseAction):
target = models.ForeignKey('Preprint', related_name='actions', on_delete=models.CASCADE)

trigger = models.CharField(max_length=31, choices=ReviewTriggers.choices())
Expand Down
37 changes: 24 additions & 13 deletions osf/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from osf.utils.fields import NonNaiveDateTimeField
from osf.utils.datetime_aware_jsonfield import DateTimeAwareJSONField
from osf.utils.machines import (
ReviewsMachine,
PreprintStateMachine,
NodeRequestMachine,
PreprintRequestMachine,
)
Expand All @@ -45,8 +45,9 @@
from osf.utils.workflows import (
DefaultStates,
DefaultTriggers,
ReviewStates,
ReviewTriggers,
PreprintStates,
PreprintTriggers,
AbstractProviderStates
)

from osf.utils.requests import get_request_and_user_id
Expand Down Expand Up @@ -871,17 +872,22 @@ class Meta:
MachineClass = PreprintRequestMachine


class ReviewableMixin(MachineableMixin):
class PreprintStateMachineMixin(MachineableMixin):
"""Something that may be included in a reviewed collection and is subject to a reviews workflow.
"""
TriggersClass = ReviewTriggers
TriggersClass = PreprintTriggers

machine_state = models.CharField(max_length=15, db_index=True, choices=ReviewStates.choices(), default=ReviewStates.INITIAL.value)
machine_state = models.CharField(
max_length=15,
db_index=True,
choices=PreprintStates.choices(),
default=PreprintStates.INITIAL.value
)

class Meta:
abstract = True

MachineClass = ReviewsMachine
MachineClass = PreprintStateMachine

@property
def in_public_reviews_state(self):
Expand Down Expand Up @@ -955,12 +961,12 @@ def get_permissions(self, user):
return list(set(get_perms(user, self)) & set(self.perms_list))


class ReviewProviderMixin(GuardianMixin):
class ModerationProviderMixin(GuardianMixin):
"""A reviewed/moderated collection of objects.
"""

REVIEWABLE_RELATION_NAME = None
REVIEW_STATES = ReviewStates
REVIEW_STATES = AbstractProviderStates
STATE_FIELD_NAME = 'machine_state'

groups = REVIEW_GROUPS
Expand All @@ -969,11 +975,16 @@ class ReviewProviderMixin(GuardianMixin):
class Meta:
abstract = True

reviews_workflow = models.CharField(null=True, blank=True, max_length=30, choices=Workflows.choices())
reviews_workflow = models.CharField(
null=True,
blank=True,
max_length=30,
choices=Workflows.choices()
)
reviews_comments_private = models.BooleanField(null=True, blank=True)
reviews_comments_anonymous = models.BooleanField(null=True, blank=True)

DEFAULT_SUBSCRIPTIONS = ['new_pending_submissions']
DEFAULT_EMAIL_SUBSCRIPTIONS = ['new_pending_submissions']

@property
def is_reviewed(self):
Expand Down Expand Up @@ -1012,7 +1023,7 @@ def get_request_state_counts(self):

def add_to_group(self, user, group):
# Add default notification subscription
for subscription in self.DEFAULT_SUBSCRIPTIONS:
for subscription in self.DEFAULT_EMAIL_SUBSCRIPTIONS:
self.add_user_to_subscription(user, f'{self._id}_{subscription}')

return self.get_group(group).user_set.add(user)
Expand All @@ -1024,7 +1035,7 @@ def remove_from_group(self, user, group, unsubscribe=True):
raise ValueError('Cannot remove last admin.')
if unsubscribe:
# remove notification subscription
for subscription in self.DEFAULT_SUBSCRIPTIONS:
for subscription in self.DEFAULT_EMAIL_SUBSCRIPTIONS:
self.remove_user_from_subscription(user, f'{self._id}_{subscription}')

return _group.user_set.remove(user)
Expand Down
10 changes: 3 additions & 7 deletions osf/models/preprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .provider import PreprintProvider
from .preprintlog import PreprintLog
from .contributor import PreprintContributor
from .mixins import ReviewableMixin, Taggable, Loggable, GuardianMixin
from .mixins import PreprintStateMachineMixin, Taggable, Loggable, GuardianMixin
from .validators import validate_doi
from osf.utils.fields import NonNaiveDateTimeField
from osf.utils.workflows import DefaultStates, ReviewStates
Expand Down Expand Up @@ -108,8 +108,8 @@ def can_view(self, base_queryset=None, user=None, allow_contribs=True, public_on
return ret.distinct('id', 'created') if include_non_public else ret


class Preprint(DirtyFieldsMixin, GuidMixin, IdentifierMixin, ReviewableMixin, BaseModel, TitleMixin, DescriptionMixin,
Loggable, Taggable, ContributorMixin, GuardianMixin, SpamOverrideMixin, TaxonomizableMixin):
class Preprint(DirtyFieldsMixin, GuidMixin, IdentifierMixin, PreprintStateMachineMixin, BaseModel, TitleMixin, DescriptionMixin,
Loggable, Taggable, ContributorMixin, GuardianMixin, SpamOverrideMixin, TaxonomizableMixin):

objects = PreprintManager()
# Preprint fields that trigger a check to the spam filter on save
Expand Down Expand Up @@ -579,10 +579,6 @@ def set_published(self, published, auth, save=False):
# For legacy preprints, not logging
self.set_privacy('public', log=False, save=False)

# In case this provider is ever set up to use a reviews workflow, put this preprint in a sensible state
self.machine_state = ReviewStates.ACCEPTED.value
self.date_last_transitioned = self.date_published

# This preprint will have a tombstone page when it's withdrawn.
self.ever_public = True

Expand Down
Loading

0 comments on commit 01a7f3a

Please sign in to comment.