summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-11-27 17:23:35 -0500
committerGitHub <noreply@github.com>2017-11-27 17:23:35 -0500
commit6176bcff6977bda71f4fde10a52dde6d7d7ceb9a (patch)
treeb4a4a22879f4b88ffc4fb59f46ca69d441569ddd /model
parente85ec3830164ffdfbe8fd5696ab99446b38a01ef (diff)
downloadchat-6176bcff6977bda71f4fde10a52dde6d7d7ceb9a.tar.gz
chat-6176bcff6977bda71f4fde10a52dde6d7d7ceb9a.tar.bz2
chat-6176bcff6977bda71f4fde10a52dde6d7d7ceb9a.zip
PLT-8131 (part2) Add plugin key value store support (#7902)
* Add plugin key value store support * Add localization strings * Updates per feedback
Diffstat (limited to 'model')
-rw-r--r--model/plugin_key_value.go26
-rw-r--r--model/plugin_key_value_test.go22
2 files changed, 48 insertions, 0 deletions
diff --git a/model/plugin_key_value.go b/model/plugin_key_value.go
new file mode 100644
index 000000000..b25b4c170
--- /dev/null
+++ b/model/plugin_key_value.go
@@ -0,0 +1,26 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "net/http"
+)
+
+type PluginKeyValue struct {
+ PluginId string `json:"plugin_id"`
+ Key string `json:"key" db:"PKey"`
+ Value []byte `json:"value" db:"PValue"`
+}
+
+func (kv *PluginKeyValue) IsValid() *AppError {
+ if len(kv.PluginId) == 0 {
+ return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.plugin_id.app_error", nil, "key="+kv.Key, http.StatusBadRequest)
+ }
+
+ if len(kv.Key) == 0 {
+ return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.key.app_error", nil, "key="+kv.Key, http.StatusBadRequest)
+ }
+
+ return nil
+}
diff --git a/model/plugin_key_value_test.go b/model/plugin_key_value_test.go
new file mode 100644
index 000000000..82dd7d561
--- /dev/null
+++ b/model/plugin_key_value_test.go
@@ -0,0 +1,22 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestPluginKeyIsValid(t *testing.T) {
+ kv := PluginKeyValue{PluginId: "someid", Key: "somekey", Value: []byte("somevalue")}
+ assert.Nil(t, kv.IsValid())
+
+ kv.PluginId = ""
+ assert.NotNil(t, kv.IsValid())
+
+ kv.PluginId = "someid"
+ kv.Key = ""
+ assert.NotNil(t, kv.IsValid())
+}