github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/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 TeamId string `json:"team_id"` 18 NotInTeamId string `json:"not_in_team_id"` 19 InChannelId string `json:"in_channel_id"` 20 NotInChannelId string `json:"not_in_channel_id"` 21 InGroupId string `json:"in_group_id"` 22 GroupConstrained bool `json:"group_constrained"` 23 AllowInactive bool `json:"allow_inactive"` 24 WithoutTeam bool `json:"without_team"` 25 Limit int `json:"limit"` 26 Role string `json:"role"` 27 Roles []string `json:"roles"` 28 ChannelRoles []string `json:"channel_roles"` 29 TeamRoles []string `json:"team_roles"` 30 } 31 32 // ToJson convert a User to a json string 33 func (u *UserSearch) ToJson() []byte { 34 b, _ := json.Marshal(u) 35 return b 36 } 37 38 // UserSearchFromJson will decode the input and return a User 39 func UserSearchFromJson(data io.Reader) *UserSearch { 40 us := UserSearch{} 41 json.NewDecoder(data).Decode(&us) 42 43 if us.Limit == 0 { 44 us.Limit = USER_SEARCH_DEFAULT_LIMIT 45 } 46 47 return &us 48 } 49 50 // UserSearchOptions captures internal parameters derived from the user's permissions and a 51 // UserSearch request. 52 type UserSearchOptions struct { 53 // IsAdmin tracks whether or not the search is being conducted by an administrator. 54 IsAdmin bool 55 // AllowEmails allows search to examine the emails of users. 56 AllowEmails bool 57 // AllowFullNames allows search to examine the full names of users, vs. just usernames and nicknames. 58 AllowFullNames bool 59 // AllowInactive configures whether or not to return inactive users in the search results. 60 AllowInactive bool 61 // Narrows the search to the group constrained users 62 GroupConstrained bool 63 // Limit limits the total number of results returned. 64 Limit int 65 // Filters for the given role 66 Role string 67 // Filters for users that have any of the given system roles 68 Roles []string 69 // Filters for users that have the given channel roles to be used when searching in a channel 70 ChannelRoles []string 71 // Filters for users that have the given team roles to be used when searching in a team 72 TeamRoles []string 73 // Restrict to search in a list of teams and channels 74 ViewRestrictions *ViewUsersRestrictions 75 // List of allowed channels 76 ListOfAllowedChannels []string 77 }