Skip to content

Commit

Permalink
feat(organizations): update owner filtering on projects table TASK-13…
Browse files Browse the repository at this point in the history
…35 (#5362)

### 📣 Summary
Enable filtering by both the organization name and the owner's name when
selecting 'Owner' as a filter on the projects table.

## 💭 Notes 
Known issues (Olivier's notes from Notion task)

Because we are searching on both field at the same time (it would be too
difficult to do conditional search on whether the organization is MMO).
Returned results could be false positive.
Example: 
Tino sees two projects on in “My Project” list 

- Project 1 owns by olivierleger the user 
- Project 2 owns by jnm the user, but filled out the registration form
with “leger inc” as his the organization.

If Tino searches for “owner” which should contain “leger”, both projects
will appear, even if Project 2 shows “jnm” as the owner.

### 👀 Preview steps

Feature/no-change template:
1. ℹ️ have account (someuser) and several projects 
2. have user (kobouser) with organization name (Some Org) share a
project with your account
3. have user (anotheruser) who is part of an MMO (Kobo Inc) share a
project with your account
4. 🟡 notice that projects by **_someuser_** and **_kobouser_** have the
owner name as the owner label, but projects by **_anotheruser_** have
**_Kobo Inc_** as the owner label (not part of this pr but important)
5. ➡️  filter by "Owner" contains "user"
6. 🟢 notice that all projects are shown
7. ➡️  filter by "Owner" contains "kobo"
8. 🟢 notice that projects from **_kobouser_** and **_Kobo Inc_** are
shown
9. ➡️  filter by "Owner" contains "some"
10. 🟢 notice that projects from **_someuser_** and **_kobouser_** are
shown. (Even though **_kobouser_** is shown as the owner name, we are
filtering by the organization name as well, more on false positive in
Notes above).

---------

Co-authored-by: Olivier Leger <[email protected]>
  • Loading branch information
RuthShryock and noliveleger authored Dec 20, 2024
1 parent 507c28f commit 7d0c78f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions jsapp/js/projects/projectViews/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ export const PROJECT_FIELDS: ProjectFields = {
ownerUsername: {
name: 'ownerUsername',
label: t('Owner'),
apiFilteringName: 'owner__username',
apiOrderingName: 'owner__username',
apiFilteringName: 'search_field',
apiOrderingName: 'search_field',
availableConditions: [
'contains',
'doesNotContain',
Expand Down
22 changes: 16 additions & 6 deletions jsapp/js/projects/projectViews/utils.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,22 @@ describe('projectViewsUtils', () => {
out: 'settings__description__istartswith:"foo"',
},
{
in: {
fieldName: 'ownerUsername',
condition: 'doesNotContain',
value: 'foo',
},
out: 'NOT owner__username__icontains:"foo"',
in: {fieldName: 'ownerUsername', condition: 'contains', value: 'foo'},
out:
'(search_field__owner_username__icontains:"foo" ' +
'OR search_field__organization_name__icontains:"foo")',
},
{
in: {fieldName: 'ownerUsername', condition: 'is', value: 'foo'},
out:
'(search_field__owner_username__iexact:"foo" ' +
'OR search_field__organization_name__iexact:"foo")',
},
{
in: {fieldName: 'ownerUsername', condition: 'doesNotContain', value: 'foo'},
out:
'(NOT search_field__owner_username__icontains:"foo" ' +
'OR NOT search_field__organization_name__icontains:"foo")',
},
{
in: {fieldName: 'ownerFullName', condition: 'endsWith', value: 'foo'},
Expand Down
11 changes: 11 additions & 0 deletions jsapp/js/projects/projectViews/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ export function buildQueriesFromFilters(filters: ProjectsFilterDefinition[]) {
const fieldDefinition = PROJECT_FIELDS[filter.fieldName];
const conditionDefinition = FILTER_CONDITIONS[filter.condition];

// Filtering by `ownerUsername` should filter on both the owner and organization name
if (filter.fieldName === 'ownerUsername') {
const ownerNameQuery = conditionDefinition.filterQuery
.replace('<field>', 'search_field__owner_username')
.replace('<term>', `"${filter.value}"`);
const orgNameQuery = conditionDefinition.filterQuery
.replace('<field>', 'search_field__organization_name')
.replace('<term>', `"${filter.value}"`);
return `(${ownerNameQuery} OR ${orgNameQuery})`;
}

if (conditionDefinition.requiresValue && filter.value) {
return (
conditionDefinition.filterQuery
Expand Down

0 comments on commit 7d0c78f

Please sign in to comment.