This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
filter_users.js
47 lines (42 loc) · 1.88 KB
/
filter_users.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {UserSearchOptions, UserListOptions, UserFilters} from 'utils/constants';
const NEVER = 0;
// userSelectorOptionsFromFilter will convert a string UI filter to an options object
// for selecting users out of redux state
// Note: this is currently the same as getUserOptionsFromFilter but wrapped to be clear
// that there are separate purposes (this can be used with both getProfiles and searchProfiles
// selectors)
export function userSelectorOptionsFromFilter(filter) {
return getUserOptionsFromFilter(filter);
}
// getUserOptionsFromFilter will convert a string UI filter to an options objects
// for an API request to the get users endpoint
export function getUserOptionsFromFilter(filter) {
const options = {};
if (filter === UserFilters.SYSTEM_ADMIN) {
options[UserListOptions.ROLE] = UserFilters.SYSTEM_ADMIN;
} else if (filter === UserFilters.SYSTEM_GUEST) {
options[UserListOptions.ROLE] = UserFilters.SYSTEM_GUEST;
} else if (filter === UserFilters.INACTIVE) {
options[UserListOptions.INACTIVE] = true;
}
return options;
}
// searchUserOptionsFromFilter will convert a string UI filter to an options objects
// for an API request to the search users endpoint
export function searchUserOptionsFromFilter(filter) {
const options = {};
if (filter === UserFilters.SYSTEM_ADMIN) {
options[UserSearchOptions.ROLE] = UserFilters.SYSTEM_ADMIN;
} else if (filter === UserFilters.SYSTEM_GUEST) {
options[UserSearchOptions.ROLE] = UserFilters.SYSTEM_GUEST;
} else if (filter === UserFilters.INACTIVE) {
options[UserSearchOptions.ALLOW_INACTIVE] = true;
}
return options;
}
// isActive returns whether a user is active or not.
export function isActive(user) {
return user.delete_at === NEVER;
}