summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/config.go17
-rw-r--r--model/message.go17
-rw-r--r--model/outgoing_webhook.go2
-rw-r--r--model/outgoing_webhook_test.go2
-rw-r--r--model/preference.go2
-rw-r--r--model/preference_test.go2
-rw-r--r--model/preferences.go2
-rw-r--r--model/utils.go12
-rw-r--r--model/utils_test.go9
9 files changed, 52 insertions, 13 deletions
diff --git a/model/config.go b/model/config.go
index 14ce444c5..a3ba812b0 100644
--- a/model/config.go
+++ b/model/config.go
@@ -164,6 +164,23 @@ func ConfigFromJson(data io.Reader) *Config {
}
func (o *Config) SetDefaults() {
+
+ if len(o.SqlSettings.AtRestEncryptKey) == 0 {
+ o.SqlSettings.AtRestEncryptKey = NewRandomString(32)
+ }
+
+ if len(o.FileSettings.PublicLinkSalt) == 0 {
+ o.FileSettings.PublicLinkSalt = NewRandomString(32)
+ }
+
+ if len(o.EmailSettings.InviteSalt) == 0 {
+ o.EmailSettings.InviteSalt = NewRandomString(32)
+ }
+
+ if len(o.EmailSettings.PasswordResetSalt) == 0 {
+ o.EmailSettings.PasswordResetSalt = NewRandomString(32)
+ }
+
if o.ServiceSettings.EnableSecurityFixAlert == nil {
o.ServiceSettings.EnableSecurityFixAlert = new(bool)
*o.ServiceSettings.EnableSecurityFixAlert = true
diff --git a/model/message.go b/model/message.go
index 2725353ac..1cb350bbf 100644
--- a/model/message.go
+++ b/model/message.go
@@ -9,14 +9,15 @@ import (
)
const (
- ACTION_TYPING = "typing"
- ACTION_POSTED = "posted"
- ACTION_POST_EDITED = "post_edited"
- ACTION_POST_DELETED = "post_deleted"
- ACTION_CHANNEL_VIEWED = "channel_viewed"
- ACTION_NEW_USER = "new_user"
- ACTION_USER_ADDED = "user_added"
- ACTION_USER_REMOVED = "user_removed"
+ ACTION_TYPING = "typing"
+ ACTION_POSTED = "posted"
+ ACTION_POST_EDITED = "post_edited"
+ ACTION_POST_DELETED = "post_deleted"
+ ACTION_CHANNEL_VIEWED = "channel_viewed"
+ ACTION_NEW_USER = "new_user"
+ ACTION_USER_ADDED = "user_added"
+ ACTION_USER_REMOVED = "user_removed"
+ ACTION_PREFERENCE_CHANGED = "preference_changed"
)
type Message struct {
diff --git a/model/outgoing_webhook.go b/model/outgoing_webhook.go
index 9a1b89a85..0b4fd6bbe 100644
--- a/model/outgoing_webhook.go
+++ b/model/outgoing_webhook.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
diff --git a/model/outgoing_webhook_test.go b/model/outgoing_webhook_test.go
index 0d1cd773e..665b85b6f 100644
--- a/model/outgoing_webhook_test.go
+++ b/model/outgoing_webhook_test.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
diff --git a/model/preference.go b/model/preference.go
index 4f2ba0099..a3230959c 100644
--- a/model/preference.go
+++ b/model/preference.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
diff --git a/model/preference_test.go b/model/preference_test.go
index 66b7ac50b..e29250bba 100644
--- a/model/preference_test.go
+++ b/model/preference_test.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
diff --git a/model/preferences.go b/model/preferences.go
index 1ef16151f..f11b5fd80 100644
--- a/model/preferences.go
+++ b/model/preferences.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
diff --git a/model/utils.go b/model/utils.go
index b49b4bb24..5596b06ff 100644
--- a/model/utils.go
+++ b/model/utils.go
@@ -5,6 +5,7 @@ package model
import (
"bytes"
+ "crypto/rand"
"encoding/base32"
"encoding/json"
"fmt"
@@ -81,6 +82,17 @@ func NewId() string {
return b.String()
}
+func NewRandomString(length int) string {
+ var b bytes.Buffer
+ str := make([]byte, length+8)
+ rand.Read(str)
+ encoder := base32.NewEncoder(encoding, &b)
+ encoder.Write(str)
+ encoder.Close()
+ b.Truncate(length) // removes the '==' padding
+ return b.String()
+}
+
// GetMillis is a convience method to get milliseconds since epoch.
func GetMillis() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
diff --git a/model/utils_test.go b/model/utils_test.go
index 7f14bcdf0..1f1e5f023 100644
--- a/model/utils_test.go
+++ b/model/utils_test.go
@@ -17,6 +17,15 @@ func TestNewId(t *testing.T) {
}
}
+func TestRandomString(t *testing.T) {
+ for i := 0; i < 1000; i++ {
+ r := NewRandomString(32)
+ if len(r) != 32 {
+ t.Fatal("should be 32 chars")
+ }
+ }
+}
+
func TestAppError(t *testing.T) {
err := NewAppError("TestAppError", "message", "")
json := err.ToJson()