def update_collection(collection, roles=False): """Create or update a collection.""" if collection.deleted_at is not None: index_delete(collection.id) return collection.updated_at = datetime.utcnow() db.session.add(collection) db.session.commit() log.info("Updating: %r", collection) index_collection(collection) if roles: update_roles(collection) flush_index()
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() update_roles(collection) index_collection(collection) notify_role_template(role, collection.label, 'email/permission.html', url='%scollections/%s' % (app_url, collection.id), pre=pre, post=post, collection=collection) return post
def update_collection(collection, roles=False): """Create or update a collection.""" if collection.deleted_at is not None: index_delete(collection.id) return collection.updated_at = datetime.utcnow() db.session.add(collection) db.session.commit() log.info("Updating: %r", collection) index_collection(collection) if roles: update_roles(collection) if not collection.managed: xref_collection.apply_async([collection.id], priority=2) eq = db.session.query(Entity.id) eq = eq.filter(Entity.collection_id == collection.id) for entity in eq.all(): update_entity_full.apply_async([entity.id], priority=2) flush_index()