Parcourir la source

null check for 'user' when searching

Yuki Takei il y a 7 ans
Parent
commit
4a82a9533d
1 fichiers modifiés avec 12 ajouts et 6 suppressions
  1. 12 6
      src/server/util/search.js

+ 12 - 6
src/server/util/search.js

@@ -541,14 +541,20 @@ SearchClient.prototype.filterPagesByViewer = async function(query, user, userGro
 
 
   const grantConditions = [
   const grantConditions = [
     { term: { grant: GRANT_PUBLIC } },
     { term: { grant: GRANT_PUBLIC } },
-    { bool: {
-      must: [
-        { term: { grant: GRANT_RESTRICTED } },
-        { term: { granted_users: user._id.toString() } }
-      ]
-    } },
   ];
   ];
 
 
+  // ensure to hit to GRANT_RESTRICTED pages that the user specified at own
+  if (user != null) {
+    grantConditions.push(
+      { bool: {
+        must: [
+          { term: { grant: GRANT_RESTRICTED } },
+          { term: { granted_users: user._id.toString() } }
+        ]
+      } }
+    );
+  }
+
   if (showPagesRestrictedByOwner) {
   if (showPagesRestrictedByOwner) {
     grantConditions.push(
     grantConditions.push(
       { term: { grant: GRANT_SPECIFIED } },
       { term: { grant: GRANT_SPECIFIED } },