Skip to content

Commit

Permalink
[form-builder] Made sure drafts are filtered out also for multi-type-…
Browse files Browse the repository at this point in the history
…reference fields (#550)

Reference fields that supported more than one type would allow referencing unpublished documents which create problems later when the document is to be published. This scopes the reference search properly so that drafts are never visible.
  • Loading branch information
simen committed Feb 1, 2018
1 parent 06581c5 commit 076642f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -34,7 +34,7 @@ export function search(textTerm, referenceType) {
const terms = textTerm.split(/\s+/)
const typeConstraints = referenceType.to.map(type => buildConstraintFromType(type, terms))

const query = `*[!(_id in path('drafts.**')) && ${typeConstraints.map(wrapInParens).join('||')}]`
const query = `*[!(_id in path('drafts.**')) && (${typeConstraints.map(wrapInParens).join('||')})]`

return client.observable.fetch(query, {term: `${textTerm}*`})
}
6 changes: 6 additions & 0 deletions packages/test-studio/schemas/references.js
Expand Up @@ -20,6 +20,12 @@ export default {
weak: true,
to: {type: 'author'}
},
{
title: 'Reference to book or author',
name: 'multiTypeRef',
type: 'reference',
to: [{type: 'book'}, {type: 'author'}]
},
{
name: 'array',
type: 'array',
Expand Down

0 comments on commit 076642f

Please sign in to comment.