소스 검색

fix behavior when prefix option is not specified

Yuki Takei 6 년 전
부모
커밋
81bda2d246
2개의 변경된 파일13개의 추가작업 그리고 5개의 파일을 삭제
  1. 0 1
      packages/growi-plugin-attachment-refs/README.md
  2. 13 4
      packages/growi-plugin-attachment-refs/src/server/routes/refs.js

+ 0 - 1
packages/growi-plugin-attachment-refs/README.md

@@ -125,7 +125,6 @@ $refsimg(/somewhere/page, regexp=/^.*\.png$/, max-width=200)
 TODO
 TODO
 -----
 -----
 
 
-- [ ] use `findOne` when `prefix` is not specified
 - [ ] `depth` option
 - [ ] `depth` option
 - [ ] `format` option
 - [ ] `format` option
 - [ ] `layout` option
 - [ ] `layout` option

+ 13 - 4
packages/growi-plugin-attachment-refs/src/server/routes/refs.js

@@ -101,10 +101,19 @@ module.exports = (crowi) => {
       }
       }
     }
     }
 
 
-    const builder = new PageQueryBuilder(Page.find());
-    builder.addConditionToListWithDescendants(prefix || pagePath)
-      .addConditionToExcludeTrashed()
-      .addConditionToExcludeRedirect();
+    let builder;
+
+    // builder to retrieve descendance
+    if (prefix != null) {
+      builder = new PageQueryBuilder(Page.find())
+        .addConditionToListWithDescendants(prefix)
+        .addConditionToExcludeTrashed()
+        .addConditionToExcludeRedirect();
+    }
+    // builder to get single page
+    else {
+      builder = new PageQueryBuilder(Page.find({ path: pagePath }));
+    }
 
 
     Page.addConditionToFilteringByViewerForList(builder, user, false);
     Page.addConditionToFilteringByViewerForList(builder, user, false);