예제 #1
0
def test_propertyvalue_acl_get_matching_resources(app, db, es, es_acl_prepare,
                                                  test_users):
    pid, record = create_record(
        {
            '$schema': RECORD_SCHEMA,
            'keywords': ['blah']
        },
        clz=SchemaEnforcingRecord)
    pid1, record1 = create_record(
        {
            '$schema': RECORD_SCHEMA,
            'keywords': ['test']
        },
        clz=SchemaEnforcingRecord)
    RecordIndexer().index(record)
    RecordIndexer().index(record1)
    current_search_client.indices.refresh()
    current_search_client.indices.flush()

    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='blah',
                                acl=acl,
                                originator=test_users.u1)

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

        acl1 = PropertyValueACL(name='test',
                                schemas=[RECORD_SCHEMA],
                                priority=0,
                                operation='get',
                                originator=test_users.u1)
        propval2 = PropertyValue(name='keywords',
                                 value='test',
                                 acl=acl1,
                                 originator=test_users.u1)

        db.session.add(acl1)
        db.session.add(propval2)

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

    ids = list(acl1.get_matching_resources())
    assert len(ids) == 1
    assert ids[0] == str(pid1.object_uuid)
예제 #2
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.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)