generated from mattermost/mattermost-plugin-starter-template
/
debug_kv_edit.go
66 lines (58 loc) · 1.85 KB
/
debug_kv_edit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See License for license information.
package builtin
import (
"encoding/base64"
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/mattermost/mattermost-plugin-apps/apps"
"github.com/mattermost/mattermost-plugin-apps/server/incoming"
"github.com/mattermost/mattermost-plugin-apps/server/store"
)
func (a *builtinApp) debugKVEditCommandBinding(loc *i18n.Localizer) apps.Binding {
return apps.Binding{
Location: "edit",
Label: a.conf.I18N().LocalizeDefaultMessage(loc, &i18n.Message{
ID: "command.debug.kv.edit.label",
Other: "edit",
}),
Description: a.conf.I18N().LocalizeDefaultMessage(loc, &i18n.Message{
ID: "command.debug.kv.edit.description",
Other: "View or edit specific KV keys of an app.",
}),
Hint: a.conf.I18N().LocalizeDefaultMessage(loc, &i18n.Message{
ID: "command.debug.kv.edit.hint",
Other: "[ AppID keyspec ]",
}),
Form: &apps.Form{
Submit: newUserCall(pDebugKVEdit),
Fields: []apps.Field{
a.appIDField(LookupInstalledApps, 1, true, loc),
a.namespaceField(0, false, loc),
a.debugBase64KeyField(loc),
a.debugIDField(loc),
},
},
}
}
func (a *builtinApp) debugKVEdit(r *incoming.Request, creq apps.CallRequest) apps.CallResponse {
appID := apps.AppID(creq.GetValue(FieldAppID, ""))
base64Key := creq.GetValue(fBase64Key, "")
namespace := creq.GetValue(FieldNamespace, "")
id := creq.GetValue(fID, "")
key := ""
if base64Key != "" {
decoded, err := base64.URLEncoding.DecodeString(base64Key)
if err != nil {
return apps.NewErrorResponse(err)
}
key = string(decoded)
} else {
var err error
key, err = store.Hashkey(store.KVAppPrefix, appID, creq.Context.ActingUser.Id, namespace, id)
if err != nil {
return apps.NewErrorResponse(err)
}
}
creq.State = key
return a.debugKVEditModalForm(r, creq)
}