summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2016-01-08 12:41:26 -0600
committer=Corey Hulen <corey@hulen.com>2016-01-08 12:41:26 -0600
commit3fba8e42b140c1189bf3c06882cce5e2231e63da (patch)
tree7a0721cecf6624fc9c1fd71449628472b941ddeb /model
parent001a4448ca5fb0018eeb442915b473b121c04bf3 (diff)
downloadchat-3fba8e42b140c1189bf3c06882cce5e2231e63da.tar.gz
chat-3fba8e42b140c1189bf3c06882cce5e2231e63da.tar.bz2
chat-3fba8e42b140c1189bf3c06882cce5e2231e63da.zip
partial fix for UI
Diffstat (limited to 'model')
-rw-r--r--model/client.go20
-rw-r--r--model/command_response.go40
-rw-r--r--model/command_response_test.go19
-rw-r--r--model/config.go44
-rw-r--r--model/version.go10
5 files changed, 111 insertions, 22 deletions
diff --git a/model/client.go b/model/client.go
index f1773f3c7..83d1d316c 100644
--- a/model/client.go
+++ b/model/client.go
@@ -372,7 +372,25 @@ func (c *Client) Command(channelId string, command string, suggest bool) (*Resul
m["command"] = command
m["channelId"] = channelId
m["suggest"] = strconv.FormatBool(suggest)
- if r, err := c.DoApiPost("/command", MapToJson(m)); err != nil {
+ if r, err := c.DoApiPost("/commands/execute", MapToJson(m)); err != nil {
+ return nil, err
+ } else {
+ return &Result{r.Header.Get(HEADER_REQUEST_ID),
+ r.Header.Get(HEADER_ETAG_SERVER), CommandResponseFromJson(r.Body)}, nil
+ }
+}
+
+func (c *Client) ListCommands() (*Result, *AppError) {
+ if r, err := c.DoApiPost("/commands/list", ""); err != nil {
+ return nil, err
+ } else {
+ return &Result{r.Header.Get(HEADER_REQUEST_ID),
+ r.Header.Get(HEADER_ETAG_SERVER), CommandListFromJson(r.Body)}, nil
+ }
+}
+
+func (c *Client) CreateCommand(cmd *Command) (*Result, *AppError) {
+ if r, err := c.DoApiPost("/commands/create", cmd.ToJson()); err != nil {
return nil, err
} else {
return &Result{r.Header.Get(HEADER_REQUEST_ID),
diff --git a/model/command_response.go b/model/command_response.go
new file mode 100644
index 000000000..001384864
--- /dev/null
+++ b/model/command_response.go
@@ -0,0 +1,40 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "encoding/json"
+ "io"
+)
+
+const (
+ COMMAND_RESPONSE_TYPE_IN_CHANNEL = "in_channel"
+ COMMAND_RESPONSE_TYPE_EPHEMERAL = "ephemeral"
+)
+
+type CommandResponse struct {
+ ResponseType string `json:"response_type"`
+ Text string `json:"text"`
+ Attachments interface{} `json:"attachments"`
+}
+
+func (o *CommandResponse) ToJson() string {
+ b, err := json.Marshal(o)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+func CommandResponseFromJson(data io.Reader) *CommandResponse {
+ decoder := json.NewDecoder(data)
+ var o CommandResponse
+ err := decoder.Decode(&o)
+ if err == nil {
+ return &o
+ } else {
+ return nil
+ }
+}
diff --git a/model/command_response_test.go b/model/command_response_test.go
new file mode 100644
index 000000000..7aa3e984b
--- /dev/null
+++ b/model/command_response_test.go
@@ -0,0 +1,19 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestCommandResponseJson(t *testing.T) {
+ o := CommandResponse{Text: "test"}
+ json := o.ToJson()
+ ro := CommandResponseFromJson(strings.NewReader(json))
+
+ if o.Text != ro.Text {
+ t.Fatal("Ids do not match")
+ }
+}
diff --git a/model/config.go b/model/config.go
index ed56ed0c7..7d9ff41f1 100644
--- a/model/config.go
+++ b/model/config.go
@@ -24,22 +24,24 @@ const (
)
type ServiceSettings struct {
- ListenAddress string
- MaximumLoginAttempts int
- SegmentDeveloperKey string
- GoogleDeveloperKey string
- EnableOAuthServiceProvider bool
- EnableIncomingWebhooks bool
- EnableOutgoingWebhooks bool
- EnablePostUsernameOverride bool
- EnablePostIconOverride bool
- EnableTesting bool
- EnableDeveloper *bool
- EnableSecurityFixAlert *bool
- SessionLengthWebInDays *int
- SessionLengthMobileInDays *int
- SessionLengthSSOInDays *int
- SessionCacheInMinutes *int
+ ListenAddress string
+ MaximumLoginAttempts int
+ SegmentDeveloperKey string
+ GoogleDeveloperKey string
+ EnableOAuthServiceProvider bool
+ EnableIncomingWebhooks bool
+ EnableOutgoingWebhooks bool
+ EnableCommands *bool
+ EnableOnlyAdminIntegrations *bool
+ EnablePostUsernameOverride bool
+ EnablePostIconOverride bool
+ EnableTesting bool
+ EnableDeveloper *bool
+ EnableSecurityFixAlert *bool
+ SessionLengthWebInDays *int
+ SessionLengthMobileInDays *int
+ SessionLengthSSOInDays *int
+ SessionCacheInMinutes *int
}
type SSOSettings struct {
@@ -330,6 +332,16 @@ func (o *Config) SetDefaults() {
o.ServiceSettings.SessionCacheInMinutes = new(int)
*o.ServiceSettings.SessionCacheInMinutes = 10
}
+
+ if o.ServiceSettings.EnableCommands == nil {
+ o.ServiceSettings.EnableCommands = new(bool)
+ *o.ServiceSettings.EnableCommands = false
+ }
+
+ if o.ServiceSettings.EnableOnlyAdminIntegrations == nil {
+ o.ServiceSettings.EnableOnlyAdminIntegrations = new(bool)
+ *o.ServiceSettings.EnableOnlyAdminIntegrations = true
+ }
}
func (o *Config) IsValid() *AppError {
diff --git a/model/version.go b/model/version.go
index 142ddb371..e6faf137c 100644
--- a/model/version.go
+++ b/model/version.go
@@ -24,10 +24,10 @@ var versions = []string{
}
var CurrentVersion string = versions[0]
-var BuildNumber = "_BUILD_NUMBER_"
-var BuildDate = "_BUILD_DATE_"
-var BuildHash = "_BUILD_HASH_"
-var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_"
+var BuildNumber = "dev"
+var BuildDate = "Fri Jan 8 14:19:26 UTC 2016"
+var BuildHash = "001a4448ca5fb0018eeb442915b473b121c04bf3"
+var BuildEnterpriseReady = "false"
func SplitVersion(version string) (int64, int64, int64) {
parts := strings.Split(version, ".")
@@ -73,7 +73,7 @@ func GetPreviousVersion(currentVersion string) (int64, int64) {
}
func IsOfficalBuild() bool {
- return BuildNumber != "_BUILD_NUMBER_"
+ return BuildNumber != "dev"
}
func IsCurrentVersion(versionToCheck string) bool {