async def get_by_path( self, container, path, depth=-1, query=None, doc_type=None, size=10, scroll=None, index=None): if query is None: query = {} if not isinstance(path, str): path = get_content_path(path) if path is not None and path != '/': path_query = { 'query': { 'bool': { 'must': [{ 'match': {'path': path} }] } } } if depth > -1: query['query']['bool']['must'].append({ 'range': {'depth': {'gte': depth}} }) query = merge_dicts(query, path_query) # We need the local roles return await self.query(container, query, doc_type, size=size, scroll=scroll, index=index)
async def _build_security_query( self, container, query, doc_type=None, size=10, request=None, scroll=None): if query is None: query = {} q = {} # The users who has plone.AccessContent permission by prinperm # The roles who has plone.AccessContent permission by roleperm users = [] roles = [] if request is None: request = get_current_request() interaction = IInteraction(request) for user in interaction.participations: # pylint: disable=E1133 users.append(user.principal.id) users.extend(user.principal.groups) roles_dict = interaction.global_principal_roles( user.principal.id, user.principal.groups) roles.extend([key for key, value in roles_dict.items() if value]) # We got all users and roles # users: users and groups should_list = [{'match': {'access_roles': x}} for x in roles] should_list.extend([{'match': {'access_users': x}} for x in users]) permission_query = { 'query': { 'bool': { 'filter': { 'bool': { 'should': should_list, 'minimum_should_match': 1 } } } } } query = merge_dicts(query, permission_query) # query.update(permission_query) q['body'] = query q['size'] = size if scroll: q['scroll'] = scroll logger.debug(q) return q
def _update_from_pytest_markers(settings, pytest_node): if not pytest_node: return settings # Update test app settings from pytest markers for mark in pytest_node.iter_markers(name="app_settings"): to_update = mark.args[0] settings = merge_dicts(settings, to_update) return settings
def test_merge_dicts(): result = utils.merge_dicts({"foo": { "foo": 2 }}, { "bar": 5, "foo": { "bar": 3 } }) assert result["foo"]["foo"] == 2 assert result["foo"]["bar"] == 3
def test_merge_dicts(): result = utils.merge_dicts({'foo': { 'foo': 2 }}, { 'bar': 5, 'foo': { 'bar': 3 } }) assert result['foo']['foo'] == 2 assert result['foo']['bar'] == 3
def test_merge_dicts(): result = utils.merge_dicts({ 'foo': { 'foo': 2 } }, { 'bar': 5, 'foo': { 'bar': 3 } }) assert result['foo']['foo'] == 2 assert result['foo']['bar'] == 3
async def _build_security_query(self, container, query, size=10, scroll=None): if query is None: query = {} build_security_query = resolve_dotted_name( app_settings["elasticsearch"]["security_query_builder"]) permission_query = await build_security_query(container) result = {"body": merge_dicts(query, permission_query), "size": size} if scroll: result["scroll"] = scroll logger.debug(result) return result
def _update_from_pytest_markers(settings, pytest_node): if not pytest_node: return settings # Update test app settings from pytest markers marks = [] try: marks.extend([mark for mark in pytest_node.iter_markers(name="app_settings")]) except AttributeError: # Older pytest versions mark = pytest_node.get_marker("app_settings") if mark is not None: marks.append(mark) for mark in marks: to_update = mark.args[0] settings = merge_dicts(settings, to_update) return settings
async def get_by_path( self, container, path, depth=-1, query=None, doc_type=None, size=10, scroll=None, index=None, ): if query is None: query = {} if not isinstance(path, str): path = get_content_path(path) path_query = self._get_type_query(doc_type) if path is not None and path != "/": path_query["query"]["bool"]["must"].append( {"match": { "path": path }}) if depth > -1: query["query"]["bool"]["must"].append( {"range": { "depth": { "gte": depth } }}) query = merge_dicts(query, path_query) return await self.query(container, query, size=size, scroll=scroll, index=index)
async def _build_security_query( self, container, query, doc_type=None, size=10, request=None, scroll=None): if query is None: query = {} build_security_query = resolve_dotted_name( app_settings['elasticsearch']['security_query_builder']) permission_query = await build_security_query(container, request) result = { 'body': merge_dicts(query, permission_query), 'size': size } if scroll: result['scroll'] = scroll logger.debug(result) return result
async def get_by_type(self, container, doc_type, query=None, size=10): type_query = self._get_type_query(doc_type) if query is not None: type_query = merge_dicts(query, type_query) return await self.query(container, type_query, size=size)