Search archived documents (#932)

* POC

* Improved styling

* Test
This commit is contained in:
Tom Moor
2019-04-09 09:20:30 -07:00
committed by GitHub
parent 57e051d62b
commit c1256c61aa
6 changed files with 89 additions and 34 deletions

View File

@@ -367,12 +367,13 @@ router.post('documents.restore', auth(), async ctx => {
});
router.post('documents.search', auth(), pagination(), async ctx => {
const { query } = ctx.body;
const { query, includeArchived } = ctx.body;
const { offset, limit } = ctx.state.pagination;
ctx.assertPresent(query, 'query is required');
const user = ctx.state.user;
const results = await Document.searchForUser(user, query, {
includeArchived: includeArchived === 'true',
offset,
limit,
});

View File

@@ -464,6 +464,29 @@ describe('#documents.search', async () => {
expect(body.data.length).toEqual(0);
});
it('should return archived documents if chosen', async () => {
const { user } = await seed();
const document = await buildDocument({
title: 'search term',
text: 'search term',
teamId: user.teamId,
});
await document.archive(user.id);
const res = await server.post('/api/documents.search', {
body: {
token: user.getJwtToken(),
query: 'search term',
includeArchived: 'true',
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
expect(body.data[0].document.text).toEqual('search term');
});
it('should not return documents in private collections not a member of', async () => {
const { user } = await seed();
const collection = await buildCollection({ private: true });

View File

@@ -224,7 +224,7 @@ Document.searchForUser = async (
FROM documents
WHERE "searchVector" @@ to_tsquery('english', :query) AND
"collectionId" IN(:collectionIds) AND
"archivedAt" IS NULL AND
${options.includeArchived ? '' : '"archivedAt" IS NULL AND'}
"deletedAt" IS NULL AND
("publishedAt" IS NOT NULL OR "createdById" = '${user.id}')
ORDER BY

View File

@@ -250,11 +250,13 @@ export default function Pricing() {
<Method method="documents.search" label="Search documents">
<Description>
This methods allows you to search all of your documents with
keywords.
This methods allows you to search your teams documents with
keywords. Search results will be restricted to those accessible by
the current access token.
</Description>
<Arguments>
<Argument id="query" description="Search query" required />
<Argument id="includeArchived" description="Boolean" />
</Arguments>
</Method>