Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprints state fixes #210

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 5 additions & 5 deletions api/actions/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
from osf.utils.workflows import (
DefaultStates,
DefaultTriggers,
ReviewStates,
ReviewTriggers,
PreprintStates,
PreprintTriggers,
RegistrationModerationTriggers,
SchemaResponseTriggers,
)
Expand Down Expand Up @@ -183,9 +183,9 @@ class Meta:
])

comment = HideIfProviderCommentsPrivate(ser.CharField(max_length=65535, required=False))
trigger = ser.ChoiceField(choices=ReviewTriggers.choices())
from_state = ser.ChoiceField(choices=ReviewStates.choices(), read_only=True)
to_state = ser.ChoiceField(choices=ReviewStates.choices(), read_only=True)
trigger = ser.ChoiceField(choices=PreprintTriggers.choices())
from_state = ser.ChoiceField(choices=PreprintStates.choices(), read_only=True)
to_state = ser.ChoiceField(choices=PreprintStates.choices(), read_only=True)

provider = RelationshipField(
read_only=True,
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
12 changes: 6 additions & 6 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 All @@ -35,7 +35,7 @@
from osf.exceptions import NodeStateError
from osf.models import Node
from osf.utils.registrations import strip_registered_meta_comments
from osf.utils.workflows import ApprovalStates
from osf.utils.workflows import SanctionsStates


class RegistrationSerializer(NodeSerializer):
Expand Down Expand Up @@ -434,7 +434,7 @@ def get_registered_meta(self, obj):

def get_registration_responses(self, obj):
latest_approved_response = obj.root.schema_responses.filter(
reviews_state=ApprovalStates.APPROVED.db_name,
reviews_state=SanctionsStates.APPROVED.db_name,
).first()
if latest_approved_response is not None:
return self.anonymize_fields(obj, latest_approved_response.all_responses)
Expand Down Expand Up @@ -477,7 +477,7 @@ def get_original_response_id(self, obj):

def get_latest_response_id(self, obj):
latest_approved = obj.root.schema_responses.filter(
reviews_state=ApprovalStates.APPROVED.db_name,
reviews_state=SanctionsStates.APPROVED.db_name,
).first()
if latest_approved:
return latest_approved._id
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 api/registrations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from osf.models import Registration, OSFUser, RegistrationProvider, OutcomeArtifact, CedarMetadataRecord
from osf.utils.permissions import WRITE_NODE
from osf.utils.workflows import ApprovalStates
from osf.utils.workflows import SanctionsStates

from api.base import permissions as base_permissions
from api.base import generic_bulk_views as bulk_views
Expand Down Expand Up @@ -933,7 +933,7 @@ def get_default_queryset(self):
return all_responses.filter(
reviews_state__in=[state.db_name for state in MODERATOR_VISIBLE_STATES],
)
return all_responses.filter(reviews_state=ApprovalStates.APPROVED.db_name)
return all_responses.filter(reviews_state=SanctionsStates.APPROVED.db_name)

def get_queryset(self):
return self.get_queryset_from_request()
Expand Down
6 changes: 3 additions & 3 deletions api/schema_responses/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from api.base.parsers import JSONSchemaParser

from osf.models import Registration, SchemaResponse, SchemaResponseAction
from osf.utils.workflows import ApprovalStates
from osf.utils.workflows import SanctionsStates


MODERATOR_VISIBLE_STATES = [ApprovalStates.PENDING_MODERATION, ApprovalStates.APPROVED]
MODERATOR_VISIBLE_STATES = [SanctionsStates.PENDING_MODERATION, SanctionsStates.APPROVED]


class SchemaResponseParentPermission:
Expand Down Expand Up @@ -58,7 +58,7 @@ def has_object_permission(self, request, view, obj):
auth = get_user_auth(request)
if request.method in permissions.SAFE_METHODS:
return (
(parent.is_public and schema_response.state is ApprovalStates.APPROVED)
(parent.is_public and schema_response.state is SanctionsStates.APPROVED)
or (
auth.user is not None
and parent.is_moderated
Expand Down
6 changes: 3 additions & 3 deletions api/schema_responses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Registration,
SchemaResponse,
)
from osf.utils.workflows import ApprovalStates
from osf.utils.workflows import SanctionsStates


class RegistrationSchemaResponseSerializer(JSONAPISerializer):
Expand Down Expand Up @@ -138,11 +138,11 @@ def create(self, validated_data):
raise Conflict(detail=str(exc))

def update(self, schema_response, validated_data):
if schema_response.state is not ApprovalStates.IN_PROGRESS:
if schema_response.state is not SanctionsStates.IN_PROGRESS:
raise Conflict(
detail=(
f'SchemaResponse has state `{schema_response.reviews_state}` '
f'state must be {ApprovalStates.IN_PROGRESS.db_name}',
f'state must be {SanctionsStates.IN_PROGRESS.db_name}',
),
)

Expand Down
4 changes: 2 additions & 2 deletions api/schema_responses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from osf.exceptions import SchemaResponseStateError
from osf.models import SchemaResponse, SchemaResponseAction
from osf.utils.workflows import ApprovalStates
from osf.utils.workflows import SanctionsStates


class SchemaResponseList(JSONAPIBaseView, ListFilterMixin, generics.ListCreateAPIView):
Expand Down Expand Up @@ -65,7 +65,7 @@ def get_queryset(self):
Q(parent_is_public__isnull=True), # Withdrawn or deleted parent, always exclude
).filter(
Q(user_is_contributor=True) |
(Q(parent_is_public=True) & Q(reviews_state=ApprovalStates.APPROVED.db_name)),
(Q(parent_is_public=True) & Q(reviews_state=SanctionsStates.APPROVED.db_name)),
).annotate(
is_pending_current_user_approval=annotations.is_pending_current_user_approval(user),
is_original_response=annotations.IS_ORIGINAL_RESPONSE,
Expand Down
22 changes: 11 additions & 11 deletions api_tests/actions/views/test_schema_response_action_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.utils import timezone

from api.providers.workflows import Workflows as ModerationWorkflows
from osf.utils.workflows import ApprovalStates, SchemaResponseTriggers
from osf.utils.workflows import SanctionsStates, SchemaResponseTriggers
from osf_tests.factories import (
AuthUserFactory,
RegistrationFactory,
Expand All @@ -14,10 +14,10 @@

USER_ROLES = ['read', 'write', 'admin', 'moderator', 'non-contributor', 'unauthenticated']
UNAPPROVED_RESPONSE_STATES = [
state for state in ApprovalStates if state is not ApprovalStates.APPROVED
state for state in SanctionsStates if state is not SanctionsStates.APPROVED
]
DEFAULT_REVIEWS_WORKFLOW = ModerationWorkflows.PRE_MODERATION.value
DEFAULT_SCHEMA_RESPONSE_STATE = ApprovalStates.APPROVED
DEFAULT_SCHEMA_RESPONSE_STATE = SanctionsStates.APPROVED
DEFAULT_TRIGGER = SchemaResponseTriggers.SUBMIT


Expand Down Expand Up @@ -101,7 +101,7 @@ def get_status_code_for_preconditions(
return 403

# All users can GET APPROVED responses on public registrations
if registration_status == 'public' and schema_response_state is ApprovalStates.APPROVED:
if registration_status == 'public' and schema_response_state is SanctionsStates.APPROVED:
return 200

# unauthenticated users and non-contributors cannot see any other responses
Expand All @@ -113,7 +113,7 @@ def get_status_code_for_preconditions(
# Moderators can GET PENDING_MODERATION and APPROVED SchemaResponses on
# public or private registrations that are part of a moderated registry
if role == 'moderator':
moderator_visible_states = [ApprovalStates.PENDING_MODERATION, ApprovalStates.APPROVED]
moderator_visible_states = [SanctionsStates.PENDING_MODERATION, SanctionsStates.APPROVED]
if schema_response_state in moderator_visible_states and reviews_workflow is not None:
return 200
else:
Expand All @@ -127,7 +127,7 @@ def get_status_code_for_preconditions(
raise ValueError(f'Unrecognized role {role}')

@pytest.mark.parametrize('registration_status', ['public', 'private'])
@pytest.mark.parametrize('schema_response_state', ApprovalStates)
@pytest.mark.parametrize('schema_response_state', SanctionsStates)
@pytest.mark.parametrize('role', ['read', 'write', 'admin', 'non-contributor', 'unauthenticated'])
def test_GET_status_code__as_user(self, app, registration_status, schema_response_state, role):
auth, schema_response, _, _ = configure_test_preconditions(
Expand All @@ -146,7 +146,7 @@ def test_GET_status_code__as_user(self, app, registration_status, schema_respons
assert resp.status_code == expected_code

@pytest.mark.parametrize('registration_status', ['public', 'private'])
@pytest.mark.parametrize('schema_response_state', ApprovalStates)
@pytest.mark.parametrize('schema_response_state', SanctionsStates)
@pytest.mark.parametrize('reviews_workflow', [ModerationWorkflows.PRE_MODERATION.value, None])
def test_GET_status_code__as_moderator(
self, app, registration_status, schema_response_state, reviews_workflow):
Expand Down Expand Up @@ -217,8 +217,8 @@ def action(self, schema_response):
return schema_response.actions.create(
creator=schema_response.initiator,
trigger=SchemaResponseTriggers.SUBMIT.db_name,
from_state=ApprovalStates.IN_PROGRESS.db_name,
to_state=ApprovalStates.UNAPPROVED.db_name
from_state=SanctionsStates.IN_PROGRESS.db_name,
to_state=SanctionsStates.UNAPPROVED.db_name
)

@pytest.fixture()
Expand All @@ -233,8 +233,8 @@ def test_schema_response_action_detail(self, app, url, action, schema_response,
assert data['relationships']['creator']['data']['id'] == admin_user._id
assert data['relationships']['target']['data']['id'] == schema_response._id
assert data['attributes']['trigger'] == SchemaResponseTriggers.SUBMIT.db_name
assert data['attributes']['from_state'] == ApprovalStates.IN_PROGRESS.db_name
assert data['attributes']['to_state'] == ApprovalStates.UNAPPROVED.db_name
assert data['attributes']['from_state'] == SanctionsStates.IN_PROGRESS.db_name
assert data['attributes']['to_state'] == SanctionsStates.UNAPPROVED.db_name

@pytest.mark.django_db
class TestSchemaResponseActionDetailUnsupportedMethods:
Expand Down
Loading
Loading