generated from mattermost/mattermost-plugin-starter-template
/
uninstall.go
58 lines (52 loc) · 1.68 KB
/
uninstall.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
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See License for license information.
package builtin
import (
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/mattermost/mattermost-plugin-apps/apps"
"github.com/mattermost/mattermost-plugin-apps/server/incoming"
)
func (a *builtinApp) uninstallCommandBinding(loc *i18n.Localizer) apps.Binding {
return apps.Binding{
Label: a.conf.I18N().LocalizeDefaultMessage(loc, &i18n.Message{
ID: "command.uninstall.label",
Other: "uninstall",
}),
Location: "uninstall",
Hint: a.conf.I18N().LocalizeDefaultMessage(loc, &i18n.Message{
ID: "command.uninstall.hint",
Other: "[ App ID ]",
}),
Description: a.conf.I18N().LocalizeDefaultMessage(loc, &i18n.Message{
ID: "command.uninstall.description",
Other: "Uninstall an App",
}),
Form: &apps.Form{
Submit: newUserCall(pUninstall),
Fields: []apps.Field{
a.appIDField(LookupInstalledApps, 1, true, loc),
{
Name: fForce,
Type: apps.FieldTypeBool,
Description: a.conf.I18N().LocalizeDefaultMessage(loc, &i18n.Message{
ID: "field.force.description",
Other: "Forcefully uninstall the app, even if there is an error",
}),
Label: a.conf.I18N().LocalizeDefaultMessage(loc, &i18n.Message{
ID: "field.foce.label",
Other: "force",
}),
},
},
},
}
}
func (a *builtinApp) uninstall(r *incoming.Request, creq apps.CallRequest) apps.CallResponse {
appID := apps.AppID(creq.GetValue(FieldAppID, ""))
force := creq.BoolValue(fForce)
out, err := a.proxy.UninstallApp(r, creq.Context, appID, force)
if err != nil {
return apps.NewErrorResponse(err)
}
return apps.NewTextResponse(out)
}