예제 #1
0
 def load_fixtures(self):
     self.private_coll = Collection.create({
         'foreign_id': 'test_private',
         'label': "Private Collection",
         'category': 'grey'
     })
     self._banana = Entity.create(
         {
             'schema': 'Person',
             'properties': {
                 'name': ['Banana'],
             }
         }, self.private_coll)
     user = Role.by_foreign_id(Role.SYSTEM_USER)
     Permission.grant(self.private_coll, user, True, False)
     self.public_coll = Collection.create({
         'foreign_id': 'test_public',
         'label': "Public Collection",
         'category': 'news'
     })
     self._kwazulu = Entity.create(
         {
             'schema': 'Company',
             'properties': {
                 'name': ['KwaZulu'],
                 'alias': ['kwazulu']
             }
         }, self.public_coll)
     visitor = Role.by_foreign_id(Role.SYSTEM_GUEST)
     Permission.grant(self.public_coll, visitor, True, False)
     db.session.commit()
     samples = read_entities(self.get_fixture_path('samples.ijson'))
     index_entities(self.private_coll, samples)
     process_collection(self.public_coll, ingest=False, reset=True)
     process_collection(self.private_coll, ingest=False, reset=True)
예제 #2
0
def bulk_load(config):
    """Bulk load entities from a CSV file or SQL database.

    This is done by mapping the rows in the source data to entities and links
    which can be understood by the entity index.
    """
    for foreign_id, data in config.items():
        collection = Collection.by_foreign_id(foreign_id)
        if collection is None:
            collection = Collection.create({
                'foreign_id': foreign_id,
                'managed': True,
                'label': data.get('label') or foreign_id,
                'summary': data.get('summary'),
                'category': data.get('category'),
            })

        for role_fk in dict_list(data, 'roles', 'role'):
            role = Role.by_foreign_id(role_fk)
            if role is not None:
                Permission.grant(collection, role, True, False)
            else:
                log.warning("Could not find role: %s", role_fk)

        db.session.commit()
        update_collection(collection)

        for query in dict_list(data, 'queries', 'query'):
            load_query(collection, query)
예제 #3
0
파일: util.py 프로젝트: djoffrey/aleph
    def load_fixtures(self):
        self.admin = self.create_user(foreign_id='admin', is_admin=True)
        self.private_coll = self.create_collection(
            foreign_id='test_private',
            label="Private Collection",
            category='grey',
            creator=self.admin
        )
        self._banana = self.create_entity({
            'schema': 'Person',
            'properties': {
                'name': ['Banana'],
                'birthDate': '1970-08-21'
            }
        }, self.private_coll)
        self._banana2 = self.create_entity({
            'schema': 'Person',
            'properties': {
                'name': ['Banana'],
                'birthDate': '1970-03-21'
            }
        }, self.private_coll)
        self._banana3 = self.create_entity({
            'schema': 'Person',
            'properties': {
                'name': ['Banana'],
                'birthDate': '1970-05-21'
            }
        }, self.private_coll)
        user = Role.by_foreign_id(Role.SYSTEM_USER)
        Permission.grant(self.private_coll, user, True, False)
        self.public_coll = self.create_collection(
            foreign_id='test_public',
            label="Public Collection",
            category='news',
            creator=self.admin
        )
        self._kwazulu = self.create_entity({
            'schema': 'Company',
            'properties': {
                'name': ['KwaZulu'],
                'alias': ['kwazulu']
            }
        }, self.public_coll)
        visitor = Role.by_foreign_id(Role.SYSTEM_GUEST)
        Permission.grant(self.public_coll, visitor, True, False)
        db.session.commit()

        aggregator = get_aggregator(self.public_coll)
        aggregator.delete()
        aggregator.close()
        reindex_collection(self.public_coll, sync=True)

        aggregator = get_aggregator(self.private_coll)
        aggregator.delete()
        for sample in read_entities(self.get_fixture_path('samples.ijson')):
            aggregator.put(sample, fragment='sample')
        aggregator.close()
        reindex_collection(self.private_coll, sync=True)
예제 #4
0
    def load_fixtures(self):
        self.admin = self.create_user(foreign_id='admin', is_admin=True)
        self.private_coll = self.create_collection(foreign_id='test_private',
                                                   label="Private Collection",
                                                   category='grey',
                                                   casefile=False,
                                                   creator=self.admin)
        self._banana = Entity.create(
            {
                'schema': 'Person',
                'properties': {
                    'name': ['Banana'],
                }
            }, self.private_coll)
        user = Role.by_foreign_id(Role.SYSTEM_USER)
        Permission.grant(self.private_coll, user, True, False)
        self.public_coll = self.create_collection(foreign_id='test_public',
                                                  label="Public Collection",
                                                  category='news',
                                                  casefile=False,
                                                  creator=self.admin)
        self._kwazulu = Entity.create(
            {
                'schema': 'Company',
                'properties': {
                    'name': ['KwaZulu'],
                    'alias': ['kwazulu']
                }
            }, self.public_coll)
        visitor = Role.by_foreign_id(Role.SYSTEM_GUEST)
        Permission.grant(self.public_coll, visitor, True, False)
        db.session.commit()

        drop_aggregator(self.public_coll)
        stage = get_stage(self.public_coll, OP_PROCESS)
        process_collection(stage, self.public_coll, ingest=False, sync=True)

        aggregator = get_aggregator(self.private_coll)
        aggregator.delete()
        stage = get_stage(self.private_coll, OP_PROCESS)
        for sample in read_entities(self.get_fixture_path('samples.ijson')):
            aggregator.put(sample, fragment='sample')
            index_aggregate(stage,
                            self.private_coll,
                            entity_id=sample.id,
                            sync=True)
        aggregator.close()
        process_collection(stage, self.private_coll, ingest=False, sync=True)
예제 #5
0
def update_permission(role, collection, read, write, editor_id=None):
    """Update a roles permission to access a given collection."""
    pre = Permission.by_collection_role(collection, role)
    post = Permission.grant(collection, role, read, write)
    db.session.commit()
    refresh_role(role)
    if post is None:
        return
    params = {"role": role, "collection": collection}
    if pre is None or not pre.read:
        if role.foreign_id == Role.SYSTEM_GUEST:
            publish(
                Events.PUBLISH_COLLECTION,
                actor_id=editor_id,
                params=params,
                channels=[GLOBAL],
            )
        else:
            publish(
                Events.GRANT_COLLECTION,
                actor_id=editor_id,
                params=params,
                channels=[role],
            )
    return post
예제 #6
0
def update_permission(role, collection, read, write):
    """Update a roles permission to access a given collection."""
    pre = Permission.by_collection_role(collection, role)
    post = Permission.grant(collection, role, read, write)
    db.session.commit()

    notify_role_template(role, collection.label, 'email/permission.html',
                         url=collection_url(collection.id),
                         pre=pre,
                         post=post,
                         collection=collection)
    return post
예제 #7
0
def update_permission(role, collection, read, write, editor_id=None):
    """Update a roles permission to access a given collection."""
    pre = Permission.by_collection_role(collection, role)
    post = Permission.grant(collection, role, read, write)

    params = {'role': role, 'collection': collection}
    if (pre is None or not pre.read) and post.read:
        if role.is_public:
            publish(Events.PUBLISH_COLLECTION,
                    actor_id=editor_id,
                    params=params,
                    channels=[Notification.GLOBAL])
        else:
            publish(Events.GRANT_COLLECTION, actor_id=editor_id, params=params)
    elif pre is not None and pre.read and not post.read:
        publish(Events.REVOKE_COLLECTION, actor_id=editor_id, params=params)
    db.session.commit()
    Authz.flush()
    return post
예제 #8
0
파일: permissions.py 프로젝트: we1l1n/aleph
def update_permission(role, collection, read, write, editor_id=None):
    """Update a roles permission to access a given collection."""
    pre = Permission.by_collection_role(collection, role)
    post = Permission.grant(collection, role, read, write)
    params = {'role': role, 'collection': collection}
    if (pre is None or not pre.read) and post.read:
        if role.foreign_id == Role.SYSTEM_GUEST:
            publish(Events.PUBLISH_COLLECTION,
                    actor_id=editor_id,
                    params=params,
                    channels=[Notification.GLOBAL])
        else:
            publish(Events.GRANT_COLLECTION,
                    actor_id=editor_id,
                    params=params,
                    channels=[role])
    db.session.commit()
    Authz.flush()
    refresh_role(role)
    return post
예제 #9
0
def update_permission(role, collection, read, write, editor=None):
    """Update a roles permission to access a given collection."""
    pre = Permission.by_collection_role(collection, role)
    post = Permission.grant(collection, role, read, write)
    params = {'role': role, 'collection': collection}
    granted = pre is None or (pre.read != post.read and post.read)
    revoked = pre is not None and (pre.read != post.read and pre.read)
    if granted:
        if role.is_public:
            publish(Events.PUBLISH_COLLECTION,
                    actor_id=editor.id,
                    params=params,
                    channels=[Notification.GLOBAL])
        else:
            publish(Events.GRANT_COLLECTION, actor_id=editor.id, params=params)
    elif revoked:
        publish(Events.REVOKE_COLLECTION, actor_id=editor.id, params=params)
        cchannel = channel(collection)
        Subscription.unsubscribe(role=role, channel=cchannel)
    db.session.commit()
    return post
예제 #10
0
파일: permissions.py 프로젝트: pudo/aleph
def update_permission(role, collection, read, write, editor_id=None):
    """Update a roles permission to access a given collection."""
    pre = Permission.by_collection_role(collection, role)
    post = Permission.grant(collection, role, read, write)

    params = {'role': role, 'collection': collection}
    if (pre is None or not pre.read) and post.read:
        if role.is_public:
            publish(Events.PUBLISH_COLLECTION,
                    actor_id=editor_id,
                    params=params,
                    channels=[Notification.GLOBAL])
        else:
            publish(Events.GRANT_COLLECTION,
                    actor_id=editor_id,
                    params=params)
    elif pre is not None and pre.read and not post.read:
        publish(Events.REVOKE_COLLECTION,
                actor_id=editor_id,
                params=params)
    db.session.commit()
    Authz.flush()
    refresh_role(role)
    return post
예제 #11
0
파일: util.py 프로젝트: mustafaascha/aleph
 def grant(self, collection, role, read, write):
     Permission.grant(collection, role, read, write)
     db.session.commit()
     update_collection(collection)
     self.flush_index()
예제 #12
0
파일: util.py 프로젝트: rmallof/aleph
    def load_fixtures(self):
        self.admin = self.create_user(foreign_id="admin", is_admin=True)
        self.private_coll = self.create_collection(
            foreign_id="test_private",
            label="Private Collection",
            category="grey",
            creator=self.admin,
        )
        self._banana = self.create_entity(
            {
                "schema": "Person",
                "properties": {
                    "name": ["Banana"],
                    "birthDate": "1970-08-21"
                },
            },
            self.private_coll,
        )
        self._banana2 = self.create_entity(
            {
                "schema": "Person",
                "properties": {
                    "name": ["Banana"],
                    "birthDate": "1970-03-21"
                },
            },
            self.private_coll,
        )
        self._banana3 = self.create_entity(
            {
                "schema": "Person",
                "properties": {
                    "name": ["Banana ba Nana"],
                    "birthDate": "1969-05-21",
                    "deathDate": "1972-04-23",
                },
            },
            self.private_coll,
        )
        user = Role.by_foreign_id(Role.SYSTEM_USER)
        Permission.grant(self.private_coll, user, True, False)
        self.public_coll = self.create_collection(
            foreign_id="test_public",
            label="Public Collection",
            category="news",
            creator=self.admin,
        )
        self._kwazulu = self.create_entity(
            {
                "schema": "Company",
                "properties": {
                    "name": ["KwaZulu"],
                    "alias": ["kwazulu"]
                },
            },
            self.public_coll,
        )
        visitor = Role.by_foreign_id(Role.SYSTEM_GUEST)
        Permission.grant(self.public_coll, visitor, True, False)
        db.session.commit()

        aggregator = get_aggregator(self.public_coll)
        aggregator.delete()
        aggregator.close()
        reindex_collection(self.public_coll, sync=True)

        aggregator = get_aggregator(self.private_coll)
        aggregator.delete()
        for sample in read_entities(self.get_fixture_path("samples.ijson")):
            aggregator.put(sample, fragment="sample")
        aggregator.close()
        reindex_collection(self.private_coll, sync=True)
예제 #13
0
파일: util.py 프로젝트: pudo/aleph
 def grant(self, collection, role, read, write):
     Permission.grant(collection, role, read, write)
     db.session.commit()
     update_collection(collection)
예제 #14
0
    def setUp(self):
        super(XrefApiTestCase, self).setUp()
        self.creator = self.create_user(foreign_id='creator')
        self.outsider = self.create_user(foreign_id='outsider')
        self.guest = self.create_user(foreign_id=Role.SYSTEM_GUEST)

        # First public collection and entities
        self.residents = Collection.create(
            {
                'label': 'Residents of Habitat Ring',
                'foreign_id': 'test_residents'
            },
            role=self.creator)
        db.session.add(self.residents)
        db.session.flush()
        Permission.grant(self.residents, self.guest, True, False)

        self.ent = Entity.create({
            'schema': 'Person',
            'name': 'Elim Garak',
        }, self.residents)
        db.session.add(self.ent)

        self.ent2 = Entity.create({
            'schema': 'Person',
            'name': 'Leeta',
        }, self.residents)
        db.session.add(self.ent2)

        # Second public collection and entities
        self.dabo = Collection.create(
            {
                'label': 'Dabo Girls',
                'foreign_id': 'test_dabo'
            },
            role=self.creator)
        db.session.add(self.dabo)
        db.session.flush()
        Permission.grant(self.dabo, self.guest, True, False)

        self.ent3 = Entity.create({
            'schema': 'Person',
            'name': 'MPella',
        }, self.dabo)
        db.session.add(self.ent3)

        self.ent4 = Entity.create({
            'schema': 'Person',
            'name': 'Leeta',
        }, self.dabo)
        db.session.add(self.ent4)

        self.ent5 = Entity.create({
            'schema': 'Person',
            'name': 'Mardah',
        }, self.dabo)
        db.session.add(self.ent5)

        # Private collection and entities
        self.obsidian = Collection.create(
            {
                'label': 'Obsidian Order',
                'foreign_id': 'test_obsidian',
                'category': 'leak'
            },
            role=self.creator)
        db.session.add(self.obsidian)
        db.session.flush()

        self.ent6 = Entity.create({
            'schema': 'Person',
            'name': 'Elim Garack',
        }, self.obsidian)
        db.session.add(self.ent6)

        self.ent7 = Entity.create(
            {
                'schema': 'Person',
                'name': 'Enabran Tain',
            }, self.obsidian)
        db.session.add(self.ent7)

        db.session.commit()
        index_entity(self.ent)
        index_entity(self.ent2)
        index_entity(self.ent3)
        index_entity(self.ent4)
        index_entity(self.ent5)
        index_entity(self.ent6)
        index_entity(self.ent7)
        flush_index()