Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLT-4535/PLT-4503 Fix inactive users in searches and add option funct…
…ionality to DB user search (#4413) * Add options to user database search * Fix inactive users showing up incorrectly in some user searches * Read JSON for searchUsers API into anonymous struct * Move anonymous struct to be a normal struct in model directory and upadte client to use it * Added clarification comment about slightly odd query condition in search
- Loading branch information
Showing
14 changed files
with
279 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
package model | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
) | ||
|
||
type UserSearch struct { | ||
Term string `json:"term"` | ||
TeamId string `json:"team_id"` | ||
InChannelId string `json:"in_channel_id"` | ||
NotInChannelId string `json:"not_in_channel_id"` | ||
AllowInactive bool `json:"allow_inactive"` | ||
} | ||
|
||
// ToJson convert a User to a json string | ||
func (u *UserSearch) ToJson() string { | ||
b, err := json.Marshal(u) | ||
if err != nil { | ||
return "" | ||
} else { | ||
return string(b) | ||
} | ||
} | ||
|
||
// UserSearchFromJson will decode the input and return a User | ||
func UserSearchFromJson(data io.Reader) *UserSearch { | ||
decoder := json.NewDecoder(data) | ||
var us UserSearch | ||
err := decoder.Decode(&us) | ||
if err == nil { | ||
return &us | ||
} else { | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
package model | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestUserSearchJson(t *testing.T) { | ||
userSearch := UserSearch{Term: NewId(), TeamId: NewId()} | ||
json := userSearch.ToJson() | ||
ruserSearch := UserSearchFromJson(strings.NewReader(json)) | ||
|
||
if userSearch.Term != ruserSearch.Term { | ||
t.Fatal("Terms do not match") | ||
} | ||
} |
Oops, something went wrong.