From 74505a11c5128dc6c4ea18abfe523746199c5bd2 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 5 Oct 2022 17:57:01 +0200 Subject: [PATCH] filter posts for group visibility on search posts --- backend/src/schema/resolvers/searches.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/schema/resolvers/searches.js b/backend/src/schema/resolvers/searches.js index 60fd4318f..aba89fd4c 100644 --- a/backend/src/schema/resolvers/searches.js +++ b/backend/src/schema/resolvers/searches.js @@ -23,12 +23,15 @@ const postWhereClause = `WHERE score >= 0.0 AND NOT ( author.deleted = true OR author.disabled = true OR resource.deleted = true OR resource.disabled = true - OR (:User {id: $userId})-[:MUTED]->(author) - )` + ) AND block IS NULL AND restriction IS NULL` const searchPostsSetup = { fulltextIndex: 'post_fulltext_search', - match: 'MATCH (resource:Post)<-[:WROTE]-(author:User)', + match: `MATCH (resource:Post)<-[:WROTE]-(author:User) + MATCH (user:User {id: $userId}) + OPTIONAL MATCH (user)-[block:MUTED]->(author) + OPTIONAL MATCH (user)-[restriction:CANNOT_SEE]->(resource) + WITH user, resource, author, block, restriction`, whereClause: postWhereClause, withClause: `WITH resource, author, [(resource)<-[:COMMENTS]-(comment:Comment) | comment] AS comments, @@ -117,7 +120,6 @@ export default { searchPosts: async (_parent, args, context, _resolveInfo) => { const { query, postsOffset, firstPosts } = args const { id: userId } = context.user - return { postCount: getSearchResults( context,