Skip to content

Commit

Permalink
Added ability to disable searching from the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyhulen committed Apr 7, 2017
1 parent 1282169 commit 0c9e7de
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/config.json
Expand Up @@ -40,6 +40,7 @@
"AllowEditPost": "always",
"PostEditTimeLimit": 300,
"TimeBetweenUserTypingUpdatesMilliseconds": 5000,
"EnablePostSearch": true,
"EnableUserTypingMessages": true,
"ClusterLogTimeoutMilliseconds": 2000
},
Expand Down
6 changes: 6 additions & 0 deletions model/config.go
Expand Up @@ -150,6 +150,7 @@ type ServiceSettings struct {
AllowEditPost *string
PostEditTimeLimit *int
TimeBetweenUserTypingUpdatesMilliseconds *int64
EnablePostSearch *bool
EnableUserTypingMessages *bool
ClusterLogTimeoutMilliseconds *int
}
Expand Down Expand Up @@ -1131,6 +1132,11 @@ func (o *Config) SetDefaults() {
*o.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds = 5000
}

if o.ServiceSettings.EnablePostSearch == nil {
o.ServiceSettings.EnablePostSearch = new(bool)
*o.ServiceSettings.EnablePostSearch = true
}

if o.ServiceSettings.EnableUserTypingMessages == nil {
o.ServiceSettings.EnableUserTypingMessages = new(bool)
*o.ServiceSettings.EnableUserTypingMessages = true
Expand Down
10 changes: 10 additions & 0 deletions model/search_params.go
Expand Up @@ -4,6 +4,7 @@
package model

import (
"encoding/json"
"regexp"
"strings"
)
Expand All @@ -19,6 +20,15 @@ type SearchParams struct {
OrTerms bool
}

func (o *SearchParams) ToJson() string {
b, err := json.Marshal(o)
if err != nil {
return ""
} else {
return string(b)
}
}

var searchFlags = [...]string{"from", "channel", "in"}

func splitWordsNoQuotes(text string) []string {
Expand Down
11 changes: 11 additions & 0 deletions store/sql_post_store.go
Expand Up @@ -819,6 +819,16 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
go func() {
result := StoreResult{}

if !*utils.Cfg.ServiceSettings.EnablePostSearch {
list := &model.PostList{}
list.MakeNonNil()
result.Data = list
result.Err = model.NewLocAppError("SqlPostStore.Search", "Searching has been disabled on this server. Please contact your System Administrator.", nil, fmt.Sprintf("teamId=%v userId=%v params=%v", teamId, userId, params.ToJson()))
storeChannel <- result
close(storeChannel)
return
}

queryParams := map[string]interface{}{
"TeamId": teamId,
"UserId": userId,
Expand All @@ -830,6 +840,7 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
if terms == "" && len(params.InChannels) == 0 && len(params.FromUsers) == 0 {
result.Data = []*model.Post{}
storeChannel <- result
close(storeChannel)
return
}

Expand Down

0 comments on commit 0c9e7de

Please sign in to comment.