Esempio n. 1
0
def test_multi_propertyvalue_acl_get_matching_resources(
        app, db, es, es_acl_prepare, test_users):
    pid, record = create_record(
        {
            '$schema': RECORD_SCHEMA,
            'title': 'foo',
            'keywords': ['blah']
        },
        clz=SchemaEnforcingRecord)
    pid1, record1 = create_record(
        {
            '$schema': RECORD_SCHEMA,
            'title': 'bar',
            'keywords': ['blah']
        },
        clz=SchemaEnforcingRecord)
    pid2, record2 = create_record(
        {
            '$schema': RECORD_SCHEMA,
            'title': 'bar',
            'keywords': ['blah', 'test']
        },
        clz=SchemaEnforcingRecord)
    RecordIndexer().index(record)
    RecordIndexer().index(record1)
    RecordIndexer().index(record2)
    current_search_client.indices.refresh()
    current_search_client.indices.flush()

    with db.session.begin_nested():
        aclAND = PropertyValueACL(name='TestAND',
                                  schemas=[RECORD_SCHEMA],
                                  priority=0,
                                  operation='get',
                                  originator=test_users.u1)
        propval1 = PropertyValue(name='keywords',
                                 value='blah',
                                 acl=aclAND,
                                 originator=test_users.u1,
                                 bool_operation=BoolOperation.must)
        propval2 = PropertyValue(name='title',
                                 value='foo',
                                 acl=aclAND,
                                 originator=test_users.u1,
                                 bool_operation=BoolOperation.must)

        db.session.add(aclAND)
        db.session.add(propval1)
        db.session.add(propval2)

        aclANDnot = PropertyValueACL(name='TestAND+NOT',
                                     schemas=[RECORD_SCHEMA],
                                     priority=0,
                                     operation='get',
                                     originator=test_users.u1)
        propval3 = PropertyValue(name='title',
                                 value='bar',
                                 acl=aclANDnot,
                                 originator=test_users.u1,
                                 bool_operation=BoolOperation.must)
        propval4 = PropertyValue(name='keywords',
                                 value='blah',
                                 acl=aclANDnot,
                                 originator=test_users.u1,
                                 bool_operation=BoolOperation.must)
        propval5 = PropertyValue(name='keywords',
                                 value='test',
                                 acl=aclANDnot,
                                 originator=test_users.u1,
                                 bool_operation=BoolOperation.mustNot)

        db.session.add(aclANDnot)
        db.session.add(propval3)
        db.session.add(propval4)
        db.session.add(propval5)

    ids = list(aclAND.get_matching_resources())
    assert len(ids) == 1
    assert ids[0] == str(pid.object_uuid)

    ids = list(aclANDnot.get_matching_resources())
    assert len(ids) == 1
    assert ids[0] == str(pid1.object_uuid)