def get_record_acls(clz, record: Record) -> Iterable['ACL']: """ Returns a list of ACL objects applicable for the given record. :param record: Invenio record :return: """ # run percolate query on the index record's index query = clz._get_percolate_query(record) if logger.isEnabledFor(logging.DEBUG) <= logging.DEBUG: logger.debug('get_material_acls: query %s', json.dumps(query, indent=4, ensure_ascii=False)) index, _doc_type = current_record_to_index(record) try: for r in current_search_client.search( index=clz.get_acl_index_name(index), **add_doc_type(current_app.config['INVENIO_EXPLICIT_ACLS_DOCTYPE_NAME']), body=query )['hits']['hits']: yield clz.query.get(r['_id']) except elasticsearch.TransportError as e: logger.error('Error running ACL query on index %s, doctype %s, query %s', clz.get_acl_index_name(index), current_app.config['INVENIO_EXPLICIT_ACLS_DOCTYPE_NAME'], query) if e.status_code == 404: raise RuntimeError('Explicit ACLs were not prepared for the given schema. ' 'Please run invenio explicit-acls prepare %s' % record.get('$schema', '')) else: # pragma: no cover raise