summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-02-07 18:05:23 +0100
committerJesús Espino <jespinog@gmail.com>2018-02-07 18:05:23 +0100
commita04b02081a77497ecfc7a5ae9ffb0ca28404dd0e (patch)
tree985cb699d278f68522b08b60b1e7b84e0bd243fc /model
parent7941c30117efe1b957ac0458c2f0479e3824196d (diff)
parent7bd298ceaa24c0721e0acd65692cb2d1ca4983f3 (diff)
downloadchat-a04b02081a77497ecfc7a5ae9ffb0ca28404dd0e.tar.gz
chat-a04b02081a77497ecfc7a5ae9ffb0ca28404dd0e.tar.bz2
chat-a04b02081a77497ecfc7a5ae9ffb0ca28404dd0e.zip
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-1
Diffstat (limited to 'model')
-rw-r--r--model/channel_member_history.go5
-rw-r--r--model/config.go39
-rw-r--r--model/config_test.go84
-rw-r--r--model/message_export.go1
-rw-r--r--model/post.go2
5 files changed, 127 insertions, 4 deletions
diff --git a/model/channel_member_history.go b/model/channel_member_history.go
index bc71b580a..47c59d54e 100644
--- a/model/channel_member_history.go
+++ b/model/channel_member_history.go
@@ -6,7 +6,10 @@ package model
type ChannelMemberHistory struct {
ChannelId string
UserId string
- UserEmail string `db:"Email"`
JoinTime int64
LeaveTime *int64
+
+ // these two fields are never set in the database - when we SELECT, we join on Users to get them
+ UserEmail string `db:"Email"`
+ Username string
}
diff --git a/model/config.go b/model/config.go
index b7888ab13..9010eaeae 100644
--- a/model/config.go
+++ b/model/config.go
@@ -69,6 +69,10 @@ const (
ALLOW_EDIT_POST_NEVER = "never"
ALLOW_EDIT_POST_TIME_LIMIT = "time_limit"
+ GROUP_UNREAD_CHANNELS_DISABLED = "disabled"
+ GROUP_UNREAD_CHANNELS_DEFAULT_ON = "default_on"
+ GROUP_UNREAD_CHANNELS_DEFAULT_OFF = "default_off"
+
EMAIL_BATCHING_BUFFER_SIZE = 256
EMAIL_BATCHING_INTERVAL = 30
@@ -154,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 {
@@ -214,7 +221,7 @@ type ServiceSettings struct {
EnablePreviewFeatures *bool
EnableTutorial *bool
ExperimentalEnableDefaultChannelLeaveJoinMessages *bool
- ExperimentalGroupUnreadChannels *bool
+ ExperimentalGroupUnreadChannels *string
ImageProxyType *string
ImageProxyURL *string
ImageProxyOptions *string
@@ -424,7 +431,11 @@ func (s *ServiceSettings) SetDefaults() {
}
if s.ExperimentalGroupUnreadChannels == nil {
- s.ExperimentalGroupUnreadChannels = NewBool(false)
+ s.ExperimentalGroupUnreadChannels = NewString(GROUP_UNREAD_CHANNELS_DISABLED)
+ } else if *s.ExperimentalGroupUnreadChannels == "0" {
+ s.ExperimentalGroupUnreadChannels = NewString(GROUP_UNREAD_CHANNELS_DISABLED)
+ } else if *s.ExperimentalGroupUnreadChannels == "1" {
+ s.ExperimentalGroupUnreadChannels = NewString(GROUP_UNREAD_CHANNELS_DEFAULT_ON)
}
if s.ImageProxyType == nil {
@@ -1615,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() {
@@ -1625,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")
}
@@ -2070,6 +2089,12 @@ func (ss *ServiceSettings) isValid() *AppError {
return NewAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "", http.StatusBadRequest)
}
+ if *ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DISABLED &&
+ *ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DEFAULT_ON &&
+ *ss.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DEFAULT_OFF {
+ return NewAppError("Config.IsValid", "model.config.is_valid.group_unread_channels.app_error", nil, "", http.StatusBadRequest)
+ }
+
switch *ss.ImageProxyType {
case "", "willnorris/imageproxy":
case "atmos/camo":
@@ -2156,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 ceede6be4..919f73fd7 100644
--- a/model/config_test.go
+++ b/model/config_test.go
@@ -36,6 +36,38 @@ func TestConfigDefaultFileSettingsS3SSE(t *testing.T) {
}
}
+func TestConfigDefaultServiceSettingsExperimentalGroupUnreadChannels(t *testing.T) {
+ c1 := Config{}
+ c1.SetDefaults()
+
+ if *c1.ServiceSettings.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DISABLED {
+ t.Fatal("ServiceSettings.ExperimentalGroupUnreadChannels should default to 'disabled'")
+ }
+
+ // This setting was briefly a boolean, so ensure that those values still work as expected
+ c1 = Config{
+ ServiceSettings: ServiceSettings{
+ ExperimentalGroupUnreadChannels: NewString("1"),
+ },
+ }
+ c1.SetDefaults()
+
+ if *c1.ServiceSettings.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DEFAULT_ON {
+ t.Fatal("ServiceSettings.ExperimentalGroupUnreadChannels should set true to 'default on'")
+ }
+
+ c1 = Config{
+ ServiceSettings: ServiceSettings{
+ ExperimentalGroupUnreadChannels: NewString("0"),
+ },
+ }
+ c1.SetDefaults()
+
+ if *c1.ServiceSettings.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DISABLED {
+ t.Fatal("ServiceSettings.ExperimentalGroupUnreadChannels should set false to 'disabled'")
+ }
+}
+
func TestMessageExportSettingsIsValidEnableExportNotSet(t *testing.T) {
fs := &FileSettings{}
mes := &MessageExportSettings{}
@@ -104,12 +136,44 @@ 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
+ }
+ mes := &MessageExportSettings{
+ EnableExport: NewBool(true),
+ ExportFromTimestamp: NewInt64(0),
+ DailyRunTime: NewString("15:04"),
+ 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),
@@ -119,6 +183,23 @@ func TestMessageExportSettingsIsValid(t *testing.T) {
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))
+}
+
func TestMessageExportSetDefaults(t *testing.T) {
mes := &MessageExportSettings{}
mes.SetDefaults()
@@ -127,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/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..7cf0f1b35 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"
@@ -196,6 +197,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,