Skip to content

Commit

Permalink
fix(Search): project search
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeaturner committed Feb 8, 2024
1 parent 6fbff72 commit cc17df1
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions server/api/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function _generateProjectMatchObj({
}

// If project classification is not 'any', add it to the filters
if (projClassification !== "any") {
if (projClassification && projClassification !== "any") {
projectFilters.push({ classification: projClassification });
}

Expand All @@ -342,23 +342,28 @@ function _generateProjectMatchObj({

// Generate visibility query
let visibilityQuery = {};
if (!isSuperAdmin && userUUID) {
const teamMemberQuery =
projectAPI.constructProjectTeamMemberQuery(userUUID);

const privateProjectQuery = {
$and: [{ visibility: "private" }, { $or: teamMemberQuery }],
};

visibilityQuery = {
...privateProjectQuery,
};
} else {
visibilityQuery = { visibility: "public" };
}
if (!isSuperAdmin) {
// If user is not a super admin, add visibility query
if (userUUID) {
const teamMemberQuery =
projectAPI.constructProjectTeamMemberQuery(userUUID);

// If userUUID is provided, add query for private projects that the user is a member of
const privateProjectQuery = {
$and: [{ visibility: "private" }, { $or: teamMemberQuery }],
};

visibilityQuery = {
$or: [privateProjectQuery, { visibility: "public" }],
};
} else {
// If userUUID is not provided, only show public projects
visibilityQuery = { visibility: "public" };
}

if (Object.keys(visibilityQuery).length > 0) {
projectFilters.push(visibilityQuery);
if (Object.keys(visibilityQuery).length > 0) {
projectFilters.push(visibilityQuery);
}
}

// If multiple filters, use $and, otherwise just use the filter
Expand Down

0 comments on commit cc17df1

Please sign in to comment.