Skip to content

Fix issue 60 #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function searchChallenges (currentUser, criteria) {
if (criteria.tag) {
boolQuery.push({ match_phrase: { tags: criteria.tag } })
}
if (criteria.group) {
if (criteria.group && !_.isUndefined(currentUser)) {
boolQuery.push({ match_phrase: { groups: criteria.group } })
}
if (criteria.gitRepoURL) {
Expand Down Expand Up @@ -121,12 +121,18 @@ async function searchChallenges (currentUser, criteria) {

const mustQuery = []

let mustNotQuery

const accessQuery = []

if (!_.isUndefined(currentUser) && currentUser.handle) {
accessQuery.push({ match_phrase: { createdBy: currentUser.handle } })
}

if (_.isUndefined(currentUser)) {
mustNotQuery = { exists: { field: 'groups' } }
}

if (criteria.memberId) {
const ids = await helper.listChallengesByMember(criteria.memberId)
accessQuery.push({ terms: { _id: ids } })
Expand Down Expand Up @@ -154,9 +160,10 @@ async function searchChallenges (currentUser, criteria) {
size: criteria.perPage,
from: (criteria.page - 1) * criteria.perPage, // Es Index starts from 0
body: {
query: mustQuery.length > 0 ? {
query: mustQuery.length > 0 || !_.isUndefined(mustNotQuery) ? {
bool: {
must: mustQuery
must: mustQuery,
must_not: mustNotQuery
}
} : {
match_all: {}
Expand Down