Пример #1
0
    def test_you_cannot_change_an_annotations_references(self, pyramid_request):
        schema = schemas.UpdateAnnotationSchema(pyramid_request, '', '')

        appstruct = schema.validate({'references': ['new_parent']})

        assert 'references' not in appstruct
        assert 'references' not in appstruct.get('extra', {})
Пример #2
0
    def test_you_cannot_change_an_annotations_userid(self, pyramid_request):
        schema = schemas.UpdateAnnotationSchema(pyramid_request, '', '')

        appstruct = schema.validate({'userid': 'new_userid'})

        assert 'userid' not in appstruct
        assert 'userid' not in appstruct.get('extra', {})
Пример #3
0
def update_annotation_schema_validate(request,
                                      data,
                                      existing_target_uri='',
                                      groupid=''):
    schema = schemas.UpdateAnnotationSchema(request, existing_target_uri,
                                            groupid)
    return schema.validate(data)
Пример #4
0
    def test_it_replaces_private_permissions_with_shared_False(self, pyramid_request):
        schema = schemas.UpdateAnnotationSchema(pyramid_request, '', '')

        appstruct = schema.validate({
            'permissions': {'read': ['acct:[email protected]']}
        })

        assert appstruct['shared'] is False
        assert 'permissions' not in appstruct
        assert 'permissions' not in appstruct.get('extras', {})
Пример #5
0
    def test_it_replaces_shared_permissions_with_shared_True(self, pyramid_request):
        schema = schemas.UpdateAnnotationSchema(pyramid_request,
                                                '',
                                                '__world__')

        appstruct = schema.validate({
            'permissions': {'read': ['group:__world__']}
        })

        assert appstruct['shared'] is True
        assert 'permissions' not in appstruct
        assert 'permissions' not in appstruct.get('extras', {})
Пример #6
0
def update(annotation, request):
    """Update the specified annotation with data from the PUT payload."""
    schema = schemas.UpdateAnnotationSchema(request, annotation.target_uri,
                                            annotation.groupid)
    appstruct = schema.validate(_json_payload(request))

    annotation = storage.update_annotation(request.db, annotation.id,
                                           appstruct)

    _publish_annotation_event(request, annotation, 'update')

    links_service = request.find_service(name='links')
    presenter = AnnotationJSONPresenter(annotation, links_service)
    return presenter.asdict()
Пример #7
0
    def test_it_passes_existing_target_uri_to_document_metas_from_data(
            self, parse_document_claims, pyramid_request):
        """
        If no 'uri' is given it should use the existing target_uri.

        If no 'uri' is given in the update request then
        document_metas_from_data() should be called with the existing
        target_uri of the annotation in the database.

        """
        document_data = {'foo': 'bar'}
        schema = schemas.UpdateAnnotationSchema(pyramid_request,
                                                mock.sentinel.target_uri, '')

        schema.validate({'document': document_data})

        parse_document_claims.document_metas_from_data.assert_called_once_with(
            document_data, claimant=mock.sentinel.target_uri)
Пример #8
0
def update(context, request):
    """Update the specified annotation with data from the PATCH payload."""
    if request.method == 'PUT' and hasattr(request, 'stats'):
        request.stats.incr('memex.api.deprecated.put_update_annotation')

    schema = schemas.UpdateAnnotationSchema(request,
                                            context.annotation.target_uri,
                                            context.annotation.groupid)
    appstruct = schema.validate(_json_payload(request))

    annotation = storage.update_annotation(request.db, context.annotation.id,
                                           appstruct)

    _publish_annotation_event(request, annotation, 'update')

    links_service = request.find_service(name='links')
    group_service = request.find_service(IGroupService)
    resource = AnnotationResource(annotation, group_service, links_service)
    presenter = AnnotationJSONPresenter(resource)
    return presenter.asdict()