Skip to content

Commit

Permalink
Using email instead of name in participant filter
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 committed Sep 28, 2023
1 parent ca60aa7 commit 60a81cd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/dispatch/database/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,15 @@ def search_filter_sort_paginate(
sort = False if sort_by else True
query = search(query_str=query_str, query=query, model=model, sort=sort)

query = apply_model_specific_filters(model_cls, query, current_user, role)
query_restricted = apply_model_specific_filters(model_cls, query, current_user, role)
query = query.distinct()

if filter_spec:
query = apply_filter_specific_joins(model_cls, filter_spec, query)
query = apply_filters(query, filter_spec, model_cls)

query = query.intersect(query_restricted)

if sort_by:
sort_spec = create_sort_spec(model, sort_by, descending)
query = apply_sort(query, sort_spec)
Expand Down
48 changes: 41 additions & 7 deletions src/dispatch/static/dispatch/src/router/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,33 @@ export default {
return
}
each(value, function (item) {
if (has(flatFilters, key)) {
if (typeof item === "string" || item instanceof String) {
flatFilters[key].push(item)
if (["commander", "participant"].includes(key)) {
if (has(flatFilters, key)) {
if (typeof item === "string" || item instanceof String) {
flatFilters[key].push(item)
} else {
flatFilters[key].push(item.email)
}
} else {
flatFilters[key].push(item.name)
if (typeof item === "string" || item instanceof String) {
flatFilters[key] = [item]
} else {
flatFilters[key] = [item.email]
}
}
} else {
if (typeof item === "string" || item instanceof String) {
flatFilters[key] = [item]
if (has(flatFilters, key)) {
if (typeof item === "string" || item instanceof String) {
flatFilters[key].push(item)
} else {
flatFilters[key].push(item.name)
}
} else {
flatFilters[key] = [item.name]
if (typeof item === "string" || item instanceof String) {
flatFilters[key] = [item]
} else {
flatFilters[key] = [item.name]
}
}
}
})
Expand Down Expand Up @@ -69,6 +85,24 @@ export default {
}
return
}
if (["commander", "participant"].includes(key)) {
if (typeof value === "string" || value instanceof String) {
if (has(filters, key)) {
filters[key].push({ email: value })
} else {
filters[key] = [{ email: value }]
}
} else {
each(value, function (item) {
if (has(filters, key)) {
filters[key].push({ email: item })
} else {
filters[key] = [{ email: item }]
}
})
}
return
}
if (typeof value === "string" || value instanceof String) {
if (has(filters, key)) {
filters[key].push({ name: value })
Expand Down
9 changes: 8 additions & 1 deletion src/dispatch/static/dispatch/src/search/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ export default {
if (!value) {
return
}
if (!["commander", "participant"].includes(key) && has(value, "id")) {
if (["commander", "participant"].includes(key) && has(value, "email")) {
subFilter.push({
model: toPascalCase(key),
field: "email",
op: "==",
value: value.email,
})
} else if (has(value, "id")) {
subFilter.push({
model: toPascalCase(key),
field: "id",
Expand Down

0 comments on commit 60a81cd

Please sign in to comment.