Exemplo n.º 1
0
 def setUp(self):
     super(EntitiesApiTestCase, self).setUp()
     self.coll = Collection()
     self.coll.title = "Test Collection"
     session.add(self.coll)
     session.flush()
     permission = Permission()
     permission.role_id = Role.SYSTEM_USER
     permission.read = True
     permission.write = True
     permission.resource_id = self.coll.id
     permission.resource_type = Permission.COLLECTION
     session.add(permission)
     self.schema_uri = 'https://schema.occrp.org/generic/organization.json#'
     self.entity = {'id': 'foo', 'name': 'Foobar'}
     self.config.entities.save(self.schema_uri, self.entity,
                               collection_id=self.coll.id)
     cs = CollectionSubject(self.coll, self.entity['id'])
     session.add(cs)
     entity = {'id': 'test', 'name': 'Testing'}
     self.config.entities.save(self.schema_uri, entity,
                               collection_id=self.coll.id)
     cs = CollectionSubject(self.coll, entity['id'])
     session.add(cs)
     session.commit()
Exemplo n.º 2
0
def load_ba_fixtures(config):
    # This is messy. Would be cool to do it more cleanly, but how?
    if not len(BA_FIXTURES['entities']):
        with open(os.path.join(FIXTURES, 'ba.mapping.yaml'), 'rb') as fh:
            mapping = yaml.load(fh)
        mapper = Mapper(mapping, config.resolver, scope=config.base_uri)
        with open(os.path.join(FIXTURES, 'ba.csv'), 'rb') as csvfh:
            reader = unicodecsv.DictReader(csvfh)
            for row in reader:
                _, data = mapper.apply(row)
                BA_FIXTURES['entities'].append(data)

    source = Source.ensure({
        'slug': BA_SOURCE,
        'title': 'BiH Parliament',
        'url': 'http://foo.ba/'
    })
    permission = Permission()
    permission.role_id = Role.SYSTEM_USER
    permission.read = True
    permission.write = False
    permission.resource_id = source.id
    permission.resource_type = Permission.SOURCE
    session.add(permission)
    session.commit()
    for entity in BA_FIXTURES['entities']:
        config.entities.save(entity['$schema'], entity, source_id=source.id)
    get_loom_indexer().index(source=BA_SOURCE)
Exemplo n.º 3
0
def create_or_update(collection=None, source=None):
    if collection is not None:
        authz.require(authz.collection(authz.WRITE, collection))
    if source is not None:
        authz.require(authz.source(authz.WRITE, source))

    resource_type = Permission.COLLECTION if collection else Permission.SOURCE
    resource_id = collection or source
    data = request_data()
    validate(data, permissions_schema)

    # check that the role exists.
    rq = session.query(Role).filter(Role.id == data['role'])
    if rq.first() is None:
        raise BadRequest()

    q = session.query(Permission)
    q = q.filter(Permission.role_id == data['role'])
    q = q.filter(Permission.resource_type == resource_type)
    q = q.filter(Permission.resource_id == resource_id)
    permission = q.first()
    if permission is None:
        permission = Permission()
        permission.role_id = data['role']
        permission.resource_type = resource_type
        permission.resource_id = resource_id
    permission.read = data['read']
    permission.write = data['write']
    session.add(permission)
    session.commit()
    return jsonify({
        'status': 'ok',
        'updated': permission
    })
Exemplo n.º 4
0
 def setUp(self):
     super(EntitiesApiTestCase, self).setUp()
     self.coll = Collection()
     self.coll.title = "Test Collection"
     session.add(self.coll)
     session.flush()
     permission = Permission()
     permission.role_id = Role.SYSTEM_USER
     permission.read = True
     permission.write = True
     permission.resource_id = self.coll.id
     permission.resource_type = Permission.COLLECTION
     session.add(permission)
     self.schema_uri = 'https://schema.occrp.org/generic/organization.json#'
     self.entity = {'id': 'foo', 'name': 'Foobar'}
     self.config.entities.save(self.schema_uri,
                               self.entity,
                               collection_id=self.coll.id)
     cs = CollectionSubject(self.coll, self.entity['id'])
     session.add(cs)
     entity = {'id': 'test', 'name': 'Testing'}
     self.config.entities.save(self.schema_uri,
                               entity,
                               collection_id=self.coll.id)
     cs = CollectionSubject(self.coll, entity['id'])
     session.add(cs)
     session.commit()
Exemplo n.º 5
0
def load_ba_fixtures(config):
    # This is messy. Would be cool to do it more cleanly, but how?
    if not len(BA_FIXTURES['entities']):
        with open(os.path.join(FIXTURES, 'ba.mapping.yaml'), 'rb') as fh:
            mapping = yaml.load(fh)
        mapper = Mapper(mapping, config.resolver, scope=config.base_uri)
        with open(os.path.join(FIXTURES, 'ba.csv'), 'rb') as csvfh:
            reader = unicodecsv.DictReader(csvfh)
            for row in reader:
                _, data = mapper.apply(row)
                BA_FIXTURES['entities'].append(data)

    source = Source.ensure({
        'slug': BA_SOURCE,
        'title': 'BiH Parliament',
        'url': 'http://foo.ba/'
    })
    permission = Permission()
    permission.role_id = Role.SYSTEM_USER
    permission.read = True
    permission.write = False
    permission.resource_id = source.id
    permission.resource_type = Permission.SOURCE
    session.add(permission)
    session.commit()
    for entity in BA_FIXTURES['entities']:
        config.entities.save(entity['$schema'], entity, source_id=source.id)
    get_loom_indexer().index(source=BA_SOURCE)
 def setUp(self):
     super(PermissionsApiTestCase, self).setUp()
     self.coll = Collection()
     self.coll.title = "Test Collection"
     session.add(self.coll)
     session.flush()
     permission = Permission()
     permission.role_id = Role.SYSTEM_USER
     permission.read = True
     permission.write = True
     permission.resource_id = self.coll.id
     permission.resource_type = Permission.COLLECTION
     session.add(permission)
     session.flush()
     session.commit()
Exemplo n.º 7
0
 def setUp(self):
     super(PermissionsApiTestCase, self).setUp()
     self.coll = Collection()
     self.coll.title = "Test Collection"
     session.add(self.coll)
     session.flush()
     permission = Permission()
     permission.role_id = Role.SYSTEM_USER
     permission.read = True
     permission.write = True
     permission.resource_id = self.coll.id
     permission.resource_type = Permission.COLLECTION
     session.add(permission)
     session.flush()
     session.commit()
Exemplo n.º 8
0
 def setUp(self):
     super(SourcesApiTestCase, self).setUp()
     self.source = Source()
     self.source.slug = "test"
     self.source.title = "Test Collection"
     self.source.url = "http://test.com/"
     session.add(self.source)
     session.flush()
     permission = Permission()
     permission.role_id = Role.SYSTEM_USER
     permission.read = True
     permission.write = True
     permission.resource_id = self.source.id
     permission.resource_type = Permission.SOURCE
     session.add(permission)
     session.commit()
Exemplo n.º 9
0
 def setUp(self):
     super(SourcesApiTestCase, self).setUp()
     self.source = Source()
     self.source.slug = "test"
     self.source.title = "Test Collection"
     self.source.url = "http://test.com/"
     session.add(self.source)
     session.flush()
     permission = Permission()
     permission.role_id = Role.SYSTEM_USER
     permission.read = True
     permission.write = True
     permission.resource_id = self.source.id
     permission.resource_type = Permission.SOURCE
     session.add(permission)
     session.commit()
Exemplo n.º 10
0
def create():
    authz.require(authz.logged_in())
    data = request_data()
    validate(data, collections_schema)
    collection = Collection()
    collection.title = data.get('title')
    session.add(collection)
    update_subjects(collection, data)
    session.flush()
    permission = Permission()
    permission.resource_id = collection.id
    permission.resource_type = Permission.COLLECTION
    permission.read = True
    permission.write = True
    permission.role_id = request.auth_user
    session.add(permission)
    session.commit()
    return jsonify({'status': 'ok', 'data': collection}, status=201)