From 60a81cd3939e9bf4a68331863690ee67a5549cc8 Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Wed, 27 Sep 2023 21:13:07 -0700 Subject: [PATCH] Using email instead of name in participant filter --- src/dispatch/database/service.py | 5 +- .../static/dispatch/src/router/utils.js | 48 ++++++++++++++++--- .../static/dispatch/src/search/utils.js | 9 +++- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/dispatch/database/service.py b/src/dispatch/database/service.py index 03a3c8c39d7a..ec0c091bae73 100644 --- a/src/dispatch/database/service.py +++ b/src/dispatch/database/service.py @@ -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) diff --git a/src/dispatch/static/dispatch/src/router/utils.js b/src/dispatch/static/dispatch/src/router/utils.js index 081d8b8f64e1..ccd5c72c20ef 100644 --- a/src/dispatch/static/dispatch/src/router/utils.js +++ b/src/dispatch/static/dispatch/src/router/utils.js @@ -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] + } } } }) @@ -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 }) diff --git a/src/dispatch/static/dispatch/src/search/utils.js b/src/dispatch/static/dispatch/src/search/utils.js index 760748808200..20438a2c5183 100644 --- a/src/dispatch/static/dispatch/src/search/utils.js +++ b/src/dispatch/static/dispatch/src/search/utils.js @@ -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",