Skip to content

Commit

Permalink
Merge pull request #101 from MarkLark86/SDESK-3947-2
Browse files Browse the repository at this point in the history
[SDESK-3947](fix) Disabled users appearing in filters
  • Loading branch information
Mayur Dhamanwala authored May 2, 2019
2 parents 69c4732 + 929a4eb commit 1d0e1cf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions client/charts/tests/ChartConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,9 @@ describe('chartConfig', () => {
user1: 'first user',
user2: 'second user',
user3: 'last user',
user4: 'inactive',
user5: 'disabled',
user6: 'waiting',
},
},
});
Expand Down
8 changes: 7 additions & 1 deletion client/search/directives/SourceFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,13 @@ export function SourceFilters(
exclude: false,
enabled: false,
fetch: () => userList.getAll(),
receive: (data) => _.get(data, 'users') || [],
receive: (data) => (_.get(data, 'users') || []).filter(
(user) => (
_.get(user, 'is_active') &&
_.get(user, 'is_enabled') &&
!_.get(user, 'needs_activation')
)
),
minLength: 1,
},
[SOURCE_FILTERS.CATEGORIES]: {
Expand Down
10 changes: 5 additions & 5 deletions client/search/tests/sda-source-filters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,24 @@ describe('sda-source-filters', () => {
expect(userList.getAll).toHaveBeenCalled();
expect(element.html()).toContain('filters.users.label');
expect(isoScope.filters.users.items).toEqual([
{_id: 'user1', display_name: 'first user'},
{_id: 'user3', display_name: 'last user'},
{_id: 'user2', display_name: 'second user'},
{_id: 'user1', display_name: 'first user', is_active: true, is_enabled: true, needs_activation: false},
{_id: 'user3', display_name: 'last user', is_active: true, is_enabled: true, needs_activation: false},
{_id: 'user2', display_name: 'second user', is_active: true, is_enabled: true, needs_activation: false},
]);
expect(isoScope.filters.users.selected).toEqual([]);
expect(isoScope.filters.users.exclude).toBe(false);

params = {must: {users: ['user1']}};
compileElement();
expect(isoScope.filters.users.selected).toEqual([
{_id: 'user1', display_name: 'first user'},
{_id: 'user1', display_name: 'first user', is_active: true, is_enabled: true, needs_activation: false},
]);
expect(isoScope.filters.users.exclude).toBe(false);

params = {must_not: {users: ['user2']}};
compileElement();
expect(isoScope.filters.users.selected).toEqual([
{_id: 'user2', display_name: 'second user'},
{_id: 'user2', display_name: 'second user', is_active: true, is_enabled: true, needs_activation: false},
]);
expect(isoScope.filters.users.exclude).toBe(true);
});
Expand Down
9 changes: 6 additions & 3 deletions client/tests/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ export function mockUsers(userList, $q) {
// eslint-disable-next-line jasmine/no-unsafe-spy
spyOn(userList, 'getAll').and.returnValue(
$q.when([
{_id: 'user1', display_name: 'first user'},
{_id: 'user2', display_name: 'second user'},
{_id: 'user3', display_name: 'last user'},
{_id: 'user1', display_name: 'first user', is_active: true, is_enabled: true, needs_activation: false},
{_id: 'user2', display_name: 'second user', is_active: true, is_enabled: true, needs_activation: false},
{_id: 'user3', display_name: 'last user', is_active: true, is_enabled: true, needs_activation: false},
{_id: 'user4', display_name: 'inactive', is_active: false, is_enabled: true, needs_activation: false},
{_id: 'user5', display_name: 'disabled', is_active: true, is_enabled: false, needs_activation: false},
{_id: 'user6', display_name: 'waiting', is_active: true, is_enabled: true, needs_activation: true},
])
);
}
Expand Down

0 comments on commit 1d0e1cf

Please sign in to comment.