summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/client4.go4
-rw-r--r--model/client4_test.go58
-rw-r--r--model/config.go21
-rw-r--r--model/config_test.go52
-rw-r--r--model/incoming_webhook.go9
-rw-r--r--model/license.go19
-rw-r--r--model/message_export.go1
-rw-r--r--model/post.go15
-rw-r--r--model/system.go23
9 files changed, 188 insertions, 14 deletions
diff --git a/model/client4.go b/model/client4.go
index 0694ecbdf..962b816bb 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -1729,7 +1729,7 @@ func (c *Client4) RemoveUserFromChannel(channelId, userId string) (bool, *Respon
// CreatePost creates a post based on the provided post struct.
func (c *Client4) CreatePost(post *Post) (*Post, *Response) {
- if r, err := c.DoApiPost(c.GetPostsRoute(), post.ToJson()); err != nil {
+ if r, err := c.DoApiPost(c.GetPostsRoute(), post.ToUnsanitizedJson()); err != nil {
return nil, BuildErrorResponse(r, err)
} else {
defer closeBody(r)
@@ -1739,7 +1739,7 @@ func (c *Client4) CreatePost(post *Post) (*Post, *Response) {
// UpdatePost updates a post based on the provided post struct.
func (c *Client4) UpdatePost(postId string, post *Post) (*Post, *Response) {
- if r, err := c.DoApiPut(c.GetPostRoute(postId), post.ToJson()); err != nil {
+ if r, err := c.DoApiPut(c.GetPostRoute(postId), post.ToUnsanitizedJson()); err != nil {
return nil, BuildErrorResponse(r, err)
} else {
defer closeBody(r)
diff --git a/model/client4_test.go b/model/client4_test.go
new file mode 100644
index 000000000..f7923fa8f
--- /dev/null
+++ b/model/client4_test.go
@@ -0,0 +1,58 @@
+// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+// https://github.com/mattermost/mattermost-server/issues/8205
+func TestClient4CreatePost(t *testing.T) {
+ post := &Post{
+ Props: map[string]interface{}{
+ "attachments": []*SlackAttachment{
+ &SlackAttachment{
+ Actions: []*PostAction{
+ &PostAction{
+ Integration: &PostActionIntegration{
+ Context: map[string]interface{}{
+ "foo": "bar",
+ },
+ URL: "http://foo.com",
+ },
+ Name: "Foo",
+ },
+ },
+ },
+ },
+ },
+ }
+
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ attachments := PostFromJson(r.Body).Attachments()
+ assert.Equal(t, []*SlackAttachment{
+ &SlackAttachment{
+ Actions: []*PostAction{
+ &PostAction{
+ Integration: &PostActionIntegration{
+ Context: map[string]interface{}{
+ "foo": "bar",
+ },
+ URL: "http://foo.com",
+ },
+ Name: "Foo",
+ },
+ },
+ },
+ }, attachments)
+ }))
+
+ client := NewAPIv4Client(server.URL)
+ _, resp := client.CreatePost(post)
+ assert.Equal(t, http.StatusOK, resp.StatusCode)
+}
diff --git a/model/config.go b/model/config.go
index 7390b4fd9..898099d12 100644
--- a/model/config.go
+++ b/model/config.go
@@ -158,6 +158,9 @@ const (
PLUGIN_SETTINGS_DEFAULT_DIRECTORY = "./plugins"
PLUGIN_SETTINGS_DEFAULT_CLIENT_DIRECTORY = "./client/plugins"
+
+ COMPLIANCE_EXPORT_TYPE_ACTIANCE = "actiance"
+ COMPLIANCE_EXPORT_TYPE_GLOBALRELAY = "globalrelay"
)
type ServiceSettings struct {
@@ -1623,9 +1626,13 @@ func (s *PluginSettings) SetDefaults() {
type MessageExportSettings struct {
EnableExport *bool
+ ExportFormat *string
DailyRunTime *string
ExportFromTimestamp *int64
BatchSize *int
+
+ // formatter-specific settings - these are only expected to be non-nil if ExportFormat is set to the associated format
+ GlobalRelayEmailAddress *string
}
func (s *MessageExportSettings) SetDefaults() {
@@ -1633,6 +1640,10 @@ func (s *MessageExportSettings) SetDefaults() {
s.EnableExport = NewBool(false)
}
+ if s.ExportFormat == nil {
+ s.ExportFormat = NewString(COMPLIANCE_EXPORT_TYPE_ACTIANCE)
+ }
+
if s.DailyRunTime == nil {
s.DailyRunTime = NewString("01:00")
}
@@ -2170,6 +2181,16 @@ func (mes *MessageExportSettings) isValid(fs FileSettings) *AppError {
return NewAppError("Config.IsValid", "model.config.is_valid.message_export.daily_runtime.app_error", nil, err.Error(), http.StatusBadRequest)
} else if mes.BatchSize == nil || *mes.BatchSize < 0 {
return NewAppError("Config.IsValid", "model.config.is_valid.message_export.batch_size.app_error", nil, "", http.StatusBadRequest)
+ } else if mes.ExportFormat == nil || (*mes.ExportFormat != COMPLIANCE_EXPORT_TYPE_ACTIANCE && *mes.ExportFormat != COMPLIANCE_EXPORT_TYPE_GLOBALRELAY) {
+ return NewAppError("Config.IsValid", "model.config.is_valid.message_export.export_type.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if *mes.ExportFormat == COMPLIANCE_EXPORT_TYPE_GLOBALRELAY {
+ // validating email addresses is hard - just make sure it contains an '@' sign
+ // see https://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address
+ if mes.GlobalRelayEmailAddress == nil || !strings.Contains(*mes.GlobalRelayEmailAddress, "@") {
+ return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay_email_address.app_error", nil, "", http.StatusBadRequest)
+ }
}
}
return nil
diff --git a/model/config_test.go b/model/config_test.go
index 5510c40d0..919f73fd7 100644
--- a/model/config_test.go
+++ b/model/config_test.go
@@ -136,7 +136,7 @@ func TestMessageExportSettingsIsValidBatchSizeInvalid(t *testing.T) {
require.Error(t, mes.isValid(*fs))
}
-func TestMessageExportSettingsIsValid(t *testing.T) {
+func TestMessageExportSettingsIsValidExportFormatInvalid(t *testing.T) {
fs := &FileSettings{
DriverName: NewString("foo"), // bypass file location check
}
@@ -147,6 +147,55 @@ func TestMessageExportSettingsIsValid(t *testing.T) {
BatchSize: NewInt(100),
}
+ // should fail fast because export format isn't set
+ require.Error(t, mes.isValid(*fs))
+}
+
+func TestMessageExportSettingsIsValidGlobalRelayEmailAddressInvalid(t *testing.T) {
+ fs := &FileSettings{
+ DriverName: NewString("foo"), // bypass file location check
+ }
+ mes := &MessageExportSettings{
+ EnableExport: NewBool(true),
+ ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
+ ExportFromTimestamp: NewInt64(0),
+ DailyRunTime: NewString("15:04"),
+ BatchSize: NewInt(100),
+ }
+
+ // should fail fast because global relay email address isn't set
+ require.Error(t, mes.isValid(*fs))
+}
+
+func TestMessageExportSettingsIsValidActiance(t *testing.T) {
+ fs := &FileSettings{
+ DriverName: NewString("foo"), // bypass file location check
+ }
+ mes := &MessageExportSettings{
+ EnableExport: NewBool(true),
+ ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_ACTIANCE),
+ ExportFromTimestamp: NewInt64(0),
+ DailyRunTime: NewString("15:04"),
+ BatchSize: NewInt(100),
+ }
+
+ // should pass because everything is valid
+ require.Nil(t, mes.isValid(*fs))
+}
+
+func TestMessageExportSettingsIsValidGlobalRelay(t *testing.T) {
+ fs := &FileSettings{
+ DriverName: NewString("foo"), // bypass file location check
+ }
+ mes := &MessageExportSettings{
+ EnableExport: NewBool(true),
+ ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
+ ExportFromTimestamp: NewInt64(0),
+ DailyRunTime: NewString("15:04"),
+ BatchSize: NewInt(100),
+ GlobalRelayEmailAddress: NewString("test@mattermost.com"),
+ }
+
// should pass because everything is valid
require.Nil(t, mes.isValid(*fs))
}
@@ -159,6 +208,7 @@ func TestMessageExportSetDefaults(t *testing.T) {
require.Equal(t, "01:00", *mes.DailyRunTime)
require.Equal(t, int64(0), *mes.ExportFromTimestamp)
require.Equal(t, 10000, *mes.BatchSize)
+ require.Equal(t, COMPLIANCE_EXPORT_TYPE_ACTIANCE, *mes.ExportFormat)
}
func TestMessageExportSetDefaultsExportEnabledExportFromTimestampNil(t *testing.T) {
diff --git a/model/incoming_webhook.go b/model/incoming_webhook.go
index b38cfeec0..ca9bd116d 100644
--- a/model/incoming_webhook.go
+++ b/model/incoming_webhook.go
@@ -204,3 +204,12 @@ func IncomingWebhookRequestFromJson(data io.Reader) (*IncomingWebhookRequest, *A
return o, nil
}
+
+func (o *IncomingWebhookRequest) ToJson() string {
+ b, err := json.Marshal(o)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
diff --git a/model/license.go b/model/license.go
index f96cba06c..942a18d55 100644
--- a/model/license.go
+++ b/model/license.go
@@ -173,6 +173,25 @@ func (l *License) ToJson() string {
return string(b)
}
+// NewTestLicense returns a license that expires in the future and has the given features.
+func NewTestLicense(features ...string) *License {
+ ret := &License{
+ ExpiresAt: GetMillis() + 90*24*60*60*1000,
+ Customer: &Customer{},
+ Features: &Features{},
+ }
+ ret.Features.SetDefaults()
+
+ featureMap := map[string]bool{}
+ for _, feature := range features {
+ featureMap[feature] = true
+ }
+ featureJson, _ := json.Marshal(featureMap)
+ json.Unmarshal(featureJson, &ret.Features)
+
+ return ret
+}
+
func LicenseFromJson(data io.Reader) *License {
var o *License
json.NewDecoder(data).Decode(&o)
diff --git a/model/message_export.go b/model/message_export.go
index b59b114d4..22641deee 100644
--- a/model/message_export.go
+++ b/model/message_export.go
@@ -9,6 +9,7 @@ type MessageExport struct {
UserId *string
UserEmail *string
+ Username *string
PostId *string
PostCreateAt *int64
diff --git a/model/post.go b/model/post.go
index 391b948f4..4a774b5d4 100644
--- a/model/post.go
+++ b/model/post.go
@@ -28,6 +28,7 @@ const (
POST_ADD_REMOVE = "system_add_remove" // Deprecated, use POST_ADD_TO_CHANNEL or POST_REMOVE_FROM_CHANNEL instead
POST_ADD_TO_CHANNEL = "system_add_to_channel"
POST_REMOVE_FROM_CHANNEL = "system_remove_from_channel"
+ POST_MOVE_CHANNEL = "system_move_channel"
POST_ADD_TO_TEAM = "system_add_to_team"
POST_REMOVE_FROM_TEAM = "system_remove_from_team"
POST_HEADER_CHANGE = "system_header_change"
@@ -121,12 +122,13 @@ type PostActionIntegrationResponse struct {
func (o *Post) ToJson() string {
copy := *o
copy.StripActionIntegrations()
- b, err := json.Marshal(&copy)
- if err != nil {
- return ""
- } else {
- return string(b)
- }
+ b, _ := json.Marshal(&copy)
+ return string(b)
+}
+
+func (o *Post) ToUnsanitizedJson() string {
+ b, _ := json.Marshal(o)
+ return string(b)
}
func PostFromJson(data io.Reader) *Post {
@@ -196,6 +198,7 @@ func (o *Post) IsValid() *AppError {
POST_LEAVE_TEAM,
POST_ADD_TO_CHANNEL,
POST_REMOVE_FROM_CHANNEL,
+ POST_MOVE_CHANNEL,
POST_ADD_TO_TEAM,
POST_REMOVE_FROM_TEAM,
POST_SLACK_ATTACHMENT,
diff --git a/model/system.go b/model/system.go
index 020c50858..2a636b14f 100644
--- a/model/system.go
+++ b/model/system.go
@@ -6,14 +6,16 @@ package model
import (
"encoding/json"
"io"
+ "math/big"
)
const (
- SYSTEM_DIAGNOSTIC_ID = "DiagnosticId"
- SYSTEM_RAN_UNIT_TESTS = "RanUnitTests"
- SYSTEM_LAST_SECURITY_TIME = "LastSecurityTime"
- SYSTEM_ACTIVE_LICENSE_ID = "ActiveLicenseId"
- SYSTEM_LAST_COMPLIANCE_TIME = "LastComplianceTime"
+ SYSTEM_DIAGNOSTIC_ID = "DiagnosticId"
+ SYSTEM_RAN_UNIT_TESTS = "RanUnitTests"
+ SYSTEM_LAST_SECURITY_TIME = "LastSecurityTime"
+ SYSTEM_ACTIVE_LICENSE_ID = "ActiveLicenseId"
+ SYSTEM_LAST_COMPLIANCE_TIME = "LastComplianceTime"
+ SYSTEM_ASYMMETRIC_SIGNING_KEY = "AsymmetricSigningKey"
)
type System struct {
@@ -31,3 +33,14 @@ func SystemFromJson(data io.Reader) *System {
json.NewDecoder(data).Decode(&o)
return o
}
+
+type SystemAsymmetricSigningKey struct {
+ ECDSAKey *SystemECDSAKey `json:"ecdsa_key,omitempty"`
+}
+
+type SystemECDSAKey struct {
+ Curve string `json:"curve"`
+ X *big.Int `json:"x"`
+ Y *big.Int `json:"y"`
+ D *big.Int `json:"d,omitempty"`
+}