summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/channel_member.go58
-rw-r--r--model/channel_member_test.go18
-rw-r--r--model/client.go4
-rw-r--r--model/config.go107
-rw-r--r--model/post.go5
-rw-r--r--model/post_test.go13
-rw-r--r--model/session.go1
-rw-r--r--model/utils.go1
-rw-r--r--model/version.go4
9 files changed, 182 insertions, 29 deletions
diff --git a/model/channel_member.go b/model/channel_member.go
index 50f51304b..3ae612700 100644
--- a/model/channel_member.go
+++ b/model/channel_member.go
@@ -10,22 +10,24 @@ import (
)
const (
- CHANNEL_ROLE_ADMIN = "admin"
- CHANNEL_NOTIFY_ALL = "all"
- CHANNEL_NOTIFY_MENTION = "mention"
- CHANNEL_NOTIFY_NONE = "none"
- CHANNEL_NOTIFY_QUIET = "quiet"
+ CHANNEL_ROLE_ADMIN = "admin"
+ CHANNEL_NOTIFY_DEFAULT = "default"
+ CHANNEL_NOTIFY_ALL = "all"
+ CHANNEL_NOTIFY_MENTION = "mention"
+ CHANNEL_NOTIFY_NONE = "none"
+ CHANNEL_MARK_UNREAD_ALL = "all"
+ CHANNEL_MARK_UNREAD_MENTION = "mention"
)
type ChannelMember struct {
- ChannelId string `json:"channel_id"`
- UserId string `json:"user_id"`
- Roles string `json:"roles"`
- LastViewedAt int64 `json:"last_viewed_at"`
- MsgCount int64 `json:"msg_count"`
- MentionCount int64 `json:"mention_count"`
- NotifyLevel string `json:"notify_level"`
- LastUpdateAt int64 `json:"last_update_at"`
+ ChannelId string `json:"channel_id"`
+ UserId string `json:"user_id"`
+ Roles string `json:"roles"`
+ LastViewedAt int64 `json:"last_viewed_at"`
+ MsgCount int64 `json:"msg_count"`
+ MentionCount int64 `json:"mention_count"`
+ NotifyProps StringMap `json:"notify_props"`
+ LastUpdateAt int64 `json:"last_update_at"`
}
func (o *ChannelMember) ToJson() string {
@@ -64,8 +66,14 @@ func (o *ChannelMember) IsValid() *AppError {
}
}
- if len(o.NotifyLevel) > 20 || !IsChannelNotifyLevelValid(o.NotifyLevel) {
- return NewAppError("ChannelMember.IsValid", "Invalid notify level", "notify_level="+o.NotifyLevel)
+ notifyLevel := o.NotifyProps["desktop"]
+ if len(notifyLevel) > 20 || !IsChannelNotifyLevelValid(notifyLevel) {
+ return NewAppError("ChannelMember.IsValid", "Invalid notify level", "notify_level="+notifyLevel)
+ }
+
+ markUnreadLevel := o.NotifyProps["mark_unread"]
+ if len(markUnreadLevel) > 20 || !IsChannelMarkUnreadLevelValid(markUnreadLevel) {
+ return NewAppError("ChannelMember.IsValid", "Invalid mark unread level", "mark_unread_level="+markUnreadLevel)
}
return nil
@@ -75,6 +83,24 @@ func (o *ChannelMember) PreSave() {
o.LastUpdateAt = GetMillis()
}
+func (o *ChannelMember) PreUpdate() {
+ o.LastUpdateAt = GetMillis()
+}
+
func IsChannelNotifyLevelValid(notifyLevel string) bool {
- return notifyLevel == CHANNEL_NOTIFY_ALL || notifyLevel == CHANNEL_NOTIFY_MENTION || notifyLevel == CHANNEL_NOTIFY_NONE || notifyLevel == CHANNEL_NOTIFY_QUIET
+ return notifyLevel == CHANNEL_NOTIFY_DEFAULT ||
+ notifyLevel == CHANNEL_NOTIFY_ALL ||
+ notifyLevel == CHANNEL_NOTIFY_MENTION ||
+ notifyLevel == CHANNEL_NOTIFY_NONE
+}
+
+func IsChannelMarkUnreadLevelValid(markUnreadLevel string) bool {
+ return markUnreadLevel == CHANNEL_MARK_UNREAD_ALL || markUnreadLevel == CHANNEL_MARK_UNREAD_MENTION
+}
+
+func GetDefaultChannelNotifyProps() StringMap {
+ return StringMap{
+ "desktop": CHANNEL_NOTIFY_DEFAULT,
+ "mark_unread": CHANNEL_MARK_UNREAD_ALL,
+ }
}
diff --git a/model/channel_member_test.go b/model/channel_member_test.go
index 3b64ffbf7..edbb46e9b 100644
--- a/model/channel_member_test.go
+++ b/model/channel_member_test.go
@@ -31,24 +31,34 @@ func TestChannelMemberIsValid(t *testing.T) {
}
o.Roles = "missing"
- o.NotifyLevel = CHANNEL_NOTIFY_ALL
+ o.NotifyProps = GetDefaultChannelNotifyProps()
o.UserId = NewId()
if err := o.IsValid(); err == nil {
t.Fatal("should be invalid")
}
o.Roles = CHANNEL_ROLE_ADMIN
- o.NotifyLevel = "junk"
+ o.NotifyProps["desktop"] = "junk"
if err := o.IsValid(); err == nil {
t.Fatal("should be invalid")
}
- o.NotifyLevel = "123456789012345678901"
+ o.NotifyProps["desktop"] = "123456789012345678901"
if err := o.IsValid(); err == nil {
t.Fatal("should be invalid")
}
- o.NotifyLevel = CHANNEL_NOTIFY_ALL
+ o.NotifyProps["desktop"] = CHANNEL_NOTIFY_ALL
+ if err := o.IsValid(); err != nil {
+ t.Fatal(err)
+ }
+
+ o.NotifyProps["mark_unread"] = "123456789012345678901"
+ if err := o.IsValid(); err == nil {
+ t.Fatal("should be invalid")
+ }
+
+ o.NotifyProps["mark_unread"] = CHANNEL_MARK_UNREAD_ALL
if err := o.IsValid(); err != nil {
t.Fatal(err)
}
diff --git a/model/client.go b/model/client.go
index 26e00864d..a291cc4f2 100644
--- a/model/client.go
+++ b/model/client.go
@@ -450,8 +450,8 @@ func (c *Client) UpdateChannelDesc(data map[string]string) (*Result, *AppError)
}
}
-func (c *Client) UpdateNotifyLevel(data map[string]string) (*Result, *AppError) {
- if r, err := c.DoApiPost("/channels/update_notify_level", MapToJson(data)); err != nil {
+func (c *Client) UpdateNotifyProps(data map[string]string) (*Result, *AppError) {
+ if r, err := c.DoApiPost("/channels/update_notify_props", MapToJson(data)); err != nil {
return nil, err
} else {
return &Result{r.Header.Get(HEADER_REQUEST_ID),
diff --git a/model/config.go b/model/config.go
index 31c2b16dc..c67b36063 100644
--- a/model/config.go
+++ b/model/config.go
@@ -16,6 +16,9 @@ const (
IMAGE_DRIVER_LOCAL = "local"
IMAGE_DRIVER_S3 = "amazons3"
+ DATABASE_DRIVER_MYSQL = "mysql"
+ DATABASE_DRIVER_POSTGRES = "postgres"
+
SERVICE_GITLAB = "gitlab"
)
@@ -26,6 +29,8 @@ type ServiceSettings struct {
GoogleDeveloperKey string
EnableOAuthServiceProvider bool
EnableIncomingWebhooks bool
+ EnablePostUsernameOverride bool
+ EnablePostIconOverride bool
EnableTesting bool
}
@@ -63,12 +68,12 @@ type FileSettings struct {
Directory string
EnablePublicLink bool
PublicLinkSalt string
- ThumbnailWidth uint
- ThumbnailHeight uint
- PreviewWidth uint
- PreviewHeight uint
- ProfileWidth uint
- ProfileHeight uint
+ ThumbnailWidth int
+ ThumbnailHeight int
+ PreviewWidth int
+ PreviewHeight int
+ ProfileWidth int
+ ProfileHeight int
InitialFont string
AmazonS3AccessKeyId string
AmazonS3SecretAccessKey string
@@ -107,6 +112,7 @@ type RateLimitSettings struct {
type PrivacySettings struct {
ShowEmailAddress bool
ShowFullName bool
+ EnableDiagnostic bool
}
type TeamSettings struct {
@@ -156,3 +162,92 @@ func ConfigFromJson(data io.Reader) *Config {
return nil
}
}
+
+func (o *Config) IsValid() *AppError {
+
+ if o.ServiceSettings.MaximumLoginAttempts <= 0 {
+ return NewAppError("Config.IsValid", "Invalid maximum login attempts for service settings. Must be a positive number.", "")
+ }
+
+ if len(o.ServiceSettings.ListenAddress) == 0 {
+ return NewAppError("Config.IsValid", "Invalid listen address for service settings Must be set.", "")
+ }
+
+ if o.TeamSettings.MaxUsersPerTeam <= 0 {
+ return NewAppError("Config.IsValid", "Invalid maximum users per team for team settings. Must be a positive number.", "")
+ }
+
+ if len(o.SqlSettings.AtRestEncryptKey) != 32 {
+ return NewAppError("Config.IsValid", "Invalid at rest encrypt key for SQL settings. Must be 32 chars.", "")
+ }
+
+ if !(o.SqlSettings.DriverName == DATABASE_DRIVER_MYSQL || o.SqlSettings.DriverName == DATABASE_DRIVER_POSTGRES) {
+ return NewAppError("Config.IsValid", "Invalid driver name for SQL settings. Must be 'mysql' or 'postgres'", "")
+ }
+
+ if o.SqlSettings.MaxIdleConns <= 0 {
+ return NewAppError("Config.IsValid", "Invalid maximum idle connection for SQL settings. Must be a positive number.", "")
+ }
+
+ if len(o.SqlSettings.DataSource) == 0 {
+ return NewAppError("Config.IsValid", "Invalid data source for SQL settings. Must be set.", "")
+ }
+
+ if o.SqlSettings.MaxOpenConns <= 0 {
+ return NewAppError("Config.IsValid", "Invalid maximum open connection for SQL settings. Must be a positive number.", "")
+ }
+
+ if !(o.FileSettings.DriverName == IMAGE_DRIVER_LOCAL || o.FileSettings.DriverName == IMAGE_DRIVER_S3) {
+ return NewAppError("Config.IsValid", "Invalid driver name for file settings. Must be 'local' or 'amazons3'", "")
+ }
+
+ if o.FileSettings.PreviewHeight < 0 {
+ return NewAppError("Config.IsValid", "Invalid preview height for file settings. Must be a zero or positive number.", "")
+ }
+
+ if o.FileSettings.PreviewWidth <= 0 {
+ return NewAppError("Config.IsValid", "Invalid preview width for file settings. Must be a positive number.", "")
+ }
+
+ if o.FileSettings.ProfileHeight <= 0 {
+ return NewAppError("Config.IsValid", "Invalid profile height for file settings. Must be a positive number.", "")
+ }
+
+ if o.FileSettings.ProfileWidth <= 0 {
+ return NewAppError("Config.IsValid", "Invalid profile width for file settings. Must be a positive number.", "")
+ }
+
+ if o.FileSettings.ThumbnailHeight <= 0 {
+ return NewAppError("Config.IsValid", "Invalid thumbnail height for file settings. Must be a positive number.", "")
+ }
+
+ if o.FileSettings.ThumbnailHeight <= 0 {
+ return NewAppError("Config.IsValid", "Invalid thumbnail width for file settings. Must be a positive number.", "")
+ }
+
+ if len(o.FileSettings.PublicLinkSalt) != 32 {
+ return NewAppError("Config.IsValid", "Invalid public link salt for file settings. Must be 32 chars.", "")
+ }
+
+ if !(o.EmailSettings.ConnectionSecurity == CONN_SECURITY_NONE || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_TLS || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_STARTTLS) {
+ return NewAppError("Config.IsValid", "Invalid connection security for email settings. Must be '', 'TLS', or 'STARTTLS'", "")
+ }
+
+ if len(o.EmailSettings.InviteSalt) != 32 {
+ return NewAppError("Config.IsValid", "Invalid invite salt for email settings. Must be 32 chars.", "")
+ }
+
+ if len(o.EmailSettings.PasswordResetSalt) != 32 {
+ return NewAppError("Config.IsValid", "Invalid password reset salt for email settings. Must be 32 chars.", "")
+ }
+
+ if o.RateLimitSettings.MemoryStoreSize <= 0 {
+ return NewAppError("Config.IsValid", "Invalid memory store size for rate limit settings. Must be a positive number", "")
+ }
+
+ if o.RateLimitSettings.PerSec <= 0 {
+ return NewAppError("Config.IsValid", "Invalid per sec for rate limit settings. Must be a positive number", "")
+ }
+
+ return nil
+}
diff --git a/model/post.go b/model/post.go
index e78469940..1fc5963c3 100644
--- a/model/post.go
+++ b/model/post.go
@@ -120,7 +120,10 @@ func (o *Post) PreSave() {
o.OriginalId = ""
- o.CreateAt = GetMillis()
+ if o.CreateAt == 0 {
+ o.CreateAt = GetMillis()
+ }
+
o.UpdateAt = o.CreateAt
if o.Props == nil {
diff --git a/model/post_test.go b/model/post_test.go
index 38f4b4c98..a6b880fa0 100644
--- a/model/post_test.go
+++ b/model/post_test.go
@@ -83,5 +83,18 @@ func TestPostIsValid(t *testing.T) {
func TestPostPreSave(t *testing.T) {
o := Post{Message: "test"}
o.PreSave()
+
+ if o.CreateAt == 0 {
+ t.Fatal("should be set")
+ }
+
+ past := GetMillis() - 1
+ o = Post{Message: "test", CreateAt: past}
+ o.PreSave()
+
+ if o.CreateAt > past {
+ t.Fatal("should not be updated")
+ }
+
o.Etag()
}
diff --git a/model/session.go b/model/session.go
index 3c7c75eb4..bb4d987a7 100644
--- a/model/session.go
+++ b/model/session.go
@@ -10,6 +10,7 @@ import (
const (
SESSION_TOKEN = "MMSID"
+ MULTI_SESSION_TOKEN = "MMSIDMU"
SESSION_TIME_WEB_IN_DAYS = 30
SESSION_TIME_WEB_IN_SECS = 60 * 60 * 24 * SESSION_TIME_WEB_IN_DAYS
SESSION_TIME_MOBILE_IN_DAYS = 30
diff --git a/model/utils.go b/model/utils.go
index e19cceba5..93b8c4512 100644
--- a/model/utils.go
+++ b/model/utils.go
@@ -163,6 +163,7 @@ var reservedName = []string{
"post",
"cluster",
"api",
+ "oauth",
}
var wwwStart = regexp.MustCompile(`^www`)
diff --git a/model/version.go b/model/version.go
index 233fc3747..efa1697db 100644
--- a/model/version.go
+++ b/model/version.go
@@ -67,6 +67,10 @@ func GetPreviousVersion(currentVersion string) (int64, int64) {
return 0, 0
}
+func IsOfficalBuild() bool {
+ return BuildNumber != "_BUILD_NUMBER_"
+}
+
func IsCurrentVersion(versionToCheck string) bool {
currentMajor, currentMinor, _ := SplitVersion(CurrentVersion)
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)