github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/model/user_search.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package model 5 6 import ( 7 "encoding/json" 8 "io" 9 ) 10 11 const USER_SEARCH_MAX_LIMIT = 1000 12 const USER_SEARCH_DEFAULT_LIMIT = 100 13 14 // UserSearch captures the parameters provided by a client for initiating a user search. 15 type UserSearch struct { 16 Term string `json:"term"` 17 BranchId string `json:"branch_id"` 18 NotInBranchId string `json:"not_in_branch_id"` 19 InClassId string `json:"in_class_id"` 20 NotInClassId string `json:"not_in_class_id"` 21 GroupConstrained bool `json:"group_constrained"` 22 AllowInactive bool `json:"allow_inactive"` 23 WithoutBranch bool `json:"without_branch"` 24 Limit int `json:"limit"` 25 Role string `json:"role"` 26 } 27 28 // ToJson convert a User to a json string 29 func (u *UserSearch) ToJson() []byte { 30 b, _ := json.Marshal(u) 31 return b 32 } 33 34 // UserSearchFromJson will decode the input and return a User 35 func UserSearchFromJson(data io.Reader) *UserSearch { 36 us := UserSearch{} 37 json.NewDecoder(data).Decode(&us) 38 39 if us.Limit == 0 { 40 us.Limit = USER_SEARCH_DEFAULT_LIMIT 41 } 42 43 return &us 44 } 45 46 // UserSearchOptions captures internal parameters derived from the user's permissions and a 47 // UserSearch request. 48 type UserSearchOptions struct { 49 // IsAdmin tracks whether or not the search is being conducted by an administrator. 50 IsAdmin bool 51 // AllowEmails allows search to examine the emails of users. 52 AllowEmails bool 53 // AllowFullNames allows search to examine the full names of users, vs. just usernames and nicknames. 54 AllowFullNames bool 55 // AllowInactive configures whether or not to return inactive users in the search results. 56 AllowInactive bool 57 // Narrows the search to the group constrained users 58 GroupConstrained bool 59 // Limit limits the total number of results returned. 60 Limit int 61 // Filters for the given role 62 Role string 63 // Restrict to search in a list of branches and classes 64 ViewRestrictions *ViewUsersRestrictions 65 // List of allowed classes 66 ListOfAllowedClasses []string 67 }