• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CenterForOpenScience / SHARE / 13726922278

07 Mar 2025 06:27PM UTC coverage: 82.817% (-8.9%) from 91.752%
13726922278

Pull #848

github

web-flow
Merge fc29eb2c8 into cf198c88f
Pull Request #848: [chore] update github actions workflow

16498 of 19921 relevant lines covered (82.82%)

1.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.19
/api/views/workflow.py
1
import jsonschema
2✔
2

3
from django.db import transaction
2✔
4

5
from rest_framework import views, status
2✔
6
from rest_framework.exceptions import ParseError
2✔
7
from rest_framework.parsers import JSONParser
2✔
8
from rest_framework.renderers import JSONRenderer
2✔
9
from rest_framework.response import Response
2✔
10

11
from trove import digestive_tract
2✔
12

13
from api import v1_schemas
2✔
14
from api.authentication import APIV1TokenBackPortAuthentication
2✔
15
from api.deprecation import deprecate
2✔
16
from api.permissions import ReadOnlyOrTokenHasScopeOrIsAuthenticated
2✔
17
from api.normalizeddata.serializers import BasicNormalizedDataSerializer
2✔
18

19

20
__all__ = ('V1DataView', )
2✔
21

22

23
@deprecate(pls_hide=False)
2✔
24
class V1DataView(views.APIView):
2✔
25
    """View allowing sources to post SHARE v1 formatted metadata directly to the SHARE Dataset.
26

27
    ## Submit Data in SHARE v1 Format
28
    Please note that this endpoint is to ease the transition from SHARE v1 to SHARE v2 and sources
29
    are encouraged to transition to submitting metadata in the SHARE v2 format.
30

31
    Submitting data through the normalizeddata endpoint is strongly preferred as support for
32
    the v1 format will not be continued.
33

34
    v1 Format
35

36
        For the full format please see https://github.com/erinspace/shareregistration/blob/master/push_endpoint/schemas.py
37

38
        Required Fields: [
39
            "title",
40
            "contributors",
41
            "uris",
42
            "providerUpdatedDateTime"
43
        ],
44

45
    Create
46

47
        Method:        POST
48
        Body (JSON): {
49
                        {
50
                            "jsonData": {
51
                                "publisher":{
52
                                    "name": <publisher name>,
53
                                    "uri": <publisher uri>
54
                                },
55
                                "description": <description>,
56
                                "contributors":[
57
                                    {
58
                                        "name":<contributor name>,
59
                                        "email": <email>,
60
                                        "sameAs": <uri>
61
                                    },
62
                                    {
63
                                        "name":<contributor name>
64
                                    }
65
                                ],
66
                                "title": <title>,
67
                                "tags":[
68
                                    <tag>,
69
                                    <tag>
70
                                ],
71
                                "languages":[
72
                                    <language>
73
                                ],
74
                                "providerUpdatedDateTime": <time submitted>,
75
                                "uris": {
76
                                    "canonicalUri": <uri>,
77
                                    "providerUris":[
78
                                        <uri>
79
                                    ]
80
                                }
81
                            }
82
                        }
83
                    }
84
        Success:       200 OK
85
    """
86
    authentication_classes = (APIV1TokenBackPortAuthentication, )
2✔
87
    permission_classes = (ReadOnlyOrTokenHasScopeOrIsAuthenticated, )
2✔
88
    serializer_class = BasicNormalizedDataSerializer
2✔
89
    renderer_classes = (JSONRenderer, )
2✔
90
    parser_classes = (JSONParser,)
2✔
91

92
    def post(self, request, *args, **kwargs):
2✔
93

94
        try:
2✔
95
            jsonschema.validate(request.data, v1_schemas.v1_push_schema)
2✔
96
        except (jsonschema.exceptions.ValidationError) as error:
2✔
97
            raise ParseError(detail=error.message)
2✔
98

99
        try:
2✔
100
            prelim_data = request.data['jsonData']
2✔
101
        except ParseError as error:
×
102
            return Response(
×
103
                'Invalid JSON - {0}'.format(error.message),
104
                status=status.HTTP_400_BAD_REQUEST
105
            )
106

107
        # store raw data, assuming you can only submit one at a time
108
        with transaction.atomic():
2✔
109
            try:
2✔
110
                doc_id = prelim_data['uris']['canonicalUri']
2✔
111
            except KeyError:
×
112
                return Response({'errors': 'Canonical URI not found in uris.', 'data': prelim_data}, status=status.HTTP_400_BAD_REQUEST)
×
113

114
            _task_id = digestive_tract.swallow__sharev2_legacy(
2✔
115
                from_user=request.user,
116
                record=prelim_data,
117
                record_identifier=doc_id,
118
                transformer_key='v1_push',
119
                urgent=True,
120
            )
121
            return Response({
2✔
122
                'task_id': _task_id,
123
            }, status=status.HTTP_202_ACCEPTED)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc