Exemple #1
0
def test_propertyvalue_acl_get_record_match_acl(app, db, es, es_acl_prepare,
                                                test_users):
    pid, record = create_record(
        {
            '$schema': RECORD_SCHEMA,
            'keywords': ['blah'],
            'title': 'Hello world'
        },
        clz=SchemaEnforcingRecord)
    pid1, record1 = create_record(
        {
            '$schema': RECORD_SCHEMA,
            'keywords': ['test'],
            'title': 'Goodbye world'
        },
        clz=SchemaEnforcingRecord)

    with db.session.begin_nested():
        acl = PropertyValueACL(name='test',
                               schemas=[RECORD_SCHEMA],
                               priority=0,
                               operation='get',
                               originator=test_users.u1)
        propval = PropertyValue(name='title',
                                value='hello',
                                acl=acl,
                                originator=test_users.u1,
                                match_operation=MatchOperation.match)

        db.session.add(acl)
        db.session.add(propval)

        acl2 = PropertyValueACL(name='test 2',
                                schemas=[RECORD_SCHEMA],
                                priority=0,
                                operation='get',
                                originator=test_users.u1)
        propval2 = PropertyValue(name='title',
                                 value='goodbye',
                                 acl=acl2,
                                 originator=test_users.u1,
                                 match_operation=MatchOperation.match)
        db.session.add(acl2)
        db.session.add(propval2)

    acl.update()
    acl2.update()

    acls = list(PropertyValueACL.get_record_acls(record))
    assert len(acls) == 1
    assert isinstance(acls[0], PropertyValueACL)
    assert acls[0].id == acl.id

    acls = list(PropertyValueACL.get_record_acls(record1))
    assert len(acls) == 1
    assert isinstance(acls[0], PropertyValueACL)
    assert acls[0].id == acl2.id
Exemple #2
0
def test_propertyvalue_acl_delete(app, db, es, es_acl_prepare, test_users):
    # should pass as it does nothing
    with db.session.begin_nested():
        acl = PropertyValueACL(name='test',
                               schemas=[RECORD_SCHEMA],
                               priority=0,
                               operation='get',
                               originator=test_users.u1)
        propval = PropertyValue(name='keywords',
                                value='test',
                                acl=acl,
                                originator=test_users.u1)

        db.session.add(acl)
        db.session.add(propval)

    acl.update()
    idx = acl.get_acl_index_name(schema_to_index(RECORD_SCHEMA)[0])
    acl_md = current_search_client.get(
        index=idx,
        doc_type=current_app.config['INVENIO_EXPLICIT_ACLS_DOCTYPE_NAME'],
        id=acl.id)
    # ES7 returns extra:
    acl_md.pop('_seq_no', None)
    acl_md.pop('_primary_term', None)
    assert acl_md == {
        '_id': acl.id,
        '_index': 'invenio_explicit_acls-acl-v1.0.0-records-record-v1.0.0',
        '_source': {
            '__acl_record_selector': {
                'bool': {
                    'must': [{
                        'term': {
                            'keywords': 'test'
                        }
                    }]
                }
            },
            '__acl_record_type': 'propertyvalue'
        },
        '_type': '_doc',
        '_version': 1,
        'found': True
    }
    acl.delete()
    with pytest.raises(elasticsearch.exceptions.NotFoundError):
        current_search_client.get(
            index=idx,
            doc_type=current_app.config['INVENIO_EXPLICIT_ACLS_DOCTYPE_NAME'],
            id=acl.id)