diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/channel_extra.go | 5 | ||||
-rw-r--r-- | model/config.go | 43 | ||||
-rw-r--r-- | model/gitlab.go | 7 | ||||
-rw-r--r-- | model/post.go | 19 | ||||
-rw-r--r-- | model/post_test.go | 15 | ||||
-rw-r--r-- | model/preference.go | 1 | ||||
-rw-r--r-- | model/push_notification.go | 45 | ||||
-rw-r--r-- | model/push_notification_test.go | 19 | ||||
-rw-r--r-- | model/user.go | 53 | ||||
-rw-r--r-- | model/utils.go | 16 | ||||
-rw-r--r-- | model/utils_test.go | 9 | ||||
-rw-r--r-- | model/version.go | 1 |
12 files changed, 197 insertions, 36 deletions
diff --git a/model/channel_extra.go b/model/channel_extra.go index c6f0ca192..55da588af 100644 --- a/model/channel_extra.go +++ b/model/channel_extra.go @@ -23,8 +23,9 @@ func (o *ExtraMember) Sanitize(options map[string]bool) { } type ChannelExtra struct { - Id string `json:"id"` - Members []ExtraMember `json:"members"` + Id string `json:"id"` + Members []ExtraMember `json:"members"` + MemberCount int64 `json:"member_count"` } func (o *ChannelExtra) ToJson() string { diff --git a/model/config.go b/model/config.go index 50a8dc133..a3ba812b0 100644 --- a/model/config.go +++ b/model/config.go @@ -96,11 +96,8 @@ type EmailSettings struct { ConnectionSecurity string InviteSalt string PasswordResetSalt string - - // For Future Use - ApplePushServer string - ApplePushCertPublic string - ApplePushCertPrivate string + SendPushNotifications *bool + PushNotificationServer *string } type RateLimitSettings struct { @@ -167,6 +164,23 @@ func ConfigFromJson(data io.Reader) *Config { } func (o *Config) SetDefaults() { + + if len(o.SqlSettings.AtRestEncryptKey) == 0 { + o.SqlSettings.AtRestEncryptKey = NewRandomString(32) + } + + if len(o.FileSettings.PublicLinkSalt) == 0 { + o.FileSettings.PublicLinkSalt = NewRandomString(32) + } + + if len(o.EmailSettings.InviteSalt) == 0 { + o.EmailSettings.InviteSalt = NewRandomString(32) + } + + if len(o.EmailSettings.PasswordResetSalt) == 0 { + o.EmailSettings.PasswordResetSalt = NewRandomString(32) + } + if o.ServiceSettings.EnableSecurityFixAlert == nil { o.ServiceSettings.EnableSecurityFixAlert = new(bool) *o.ServiceSettings.EnableSecurityFixAlert = true @@ -181,6 +195,17 @@ func (o *Config) SetDefaults() { o.TeamSettings.EnableTeamListing = new(bool) *o.TeamSettings.EnableTeamListing = false } + + if o.EmailSettings.SendPushNotifications == nil { + o.EmailSettings.SendPushNotifications = new(bool) + *o.EmailSettings.SendPushNotifications = false + } + + if o.EmailSettings.PushNotificationServer == nil { + o.EmailSettings.PushNotificationServer = new(string) + *o.EmailSettings.PushNotificationServer = "" + } + } func (o *Config) IsValid() *AppError { @@ -271,3 +296,11 @@ func (o *Config) IsValid() *AppError { return nil } + +func (me *Config) GetSanitizeOptions() map[string]bool { + options := map[string]bool{} + options["fullname"] = me.PrivacySettings.ShowFullName + options["email"] = me.PrivacySettings.ShowEmailAddress + + return options +} diff --git a/model/gitlab.go b/model/gitlab.go index 9f86c7b72..2a8756807 100644 --- a/model/gitlab.go +++ b/model/gitlab.go @@ -17,13 +17,18 @@ const ( type GitLabUser struct { Id int64 `json:"id"` Username string `json:"username"` + Login string `json:"login"` Email string `json:"email"` Name string `json:"name"` } func UserFromGitLabUser(glu *GitLabUser) *User { user := &User{} - user.Username = CleanUsername(glu.Username) + username := glu.Username + if username == "" { + username = glu.Login + } + user.Username = CleanUsername(username) splitName := strings.Split(glu.Name, " ") if len(splitName) == 2 { user.FirstName = splitName[0] diff --git a/model/post.go b/model/post.go index 248d40321..5c86ce70d 100644 --- a/model/post.go +++ b/model/post.go @@ -10,9 +10,11 @@ import ( ) const ( - POST_DEFAULT = "" - POST_SLACK_ATTACHMENT = "slack_attachment" - POST_JOIN_LEAVE = "join_leave" + POST_SYSTEM_MESSAGE_PREFIX = "system_" + POST_DEFAULT = "" + POST_SLACK_ATTACHMENT = "slack_attachment" + POST_JOIN_LEAVE = "system_join_leave" + POST_HEADER_CHANGE = "system_header_change" ) type Post struct { @@ -26,7 +28,6 @@ type Post struct { ParentId string `json:"parent_id"` OriginalId string `json:"original_id"` Message string `json:"message"` - ImgCount int64 `json:"img_count"` Type string `json:"type"` Props StringInterface `json:"props"` Hashtags string `json:"hashtags"` @@ -105,7 +106,7 @@ func (o *Post) IsValid() *AppError { } // should be removed once more message types are supported - if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_SLACK_ATTACHMENT) { + if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_SLACK_ATTACHMENT || o.Type == POST_HEADER_CHANGE) { return NewAppError("Post.IsValid", "Invalid type", "id="+o.Type) } @@ -113,6 +114,10 @@ func (o *Post) IsValid() *AppError { return NewAppError("Post.IsValid", "Invalid filenames", "id="+o.Id) } + if utf8.RuneCountInString(StringInterfaceToJson(o.Props)) > 8000 { + return NewAppError("Post.IsValid", "Invalid props", "id="+o.Id) + } + return nil } @@ -156,3 +161,7 @@ func (o *Post) AddProp(key string, value interface{}) { func (o *Post) PreExport() { } + +func (o *Post) IsSystemMessage() bool { + return len(o.Type) >= len(POST_SYSTEM_MESSAGE_PREFIX) && o.Type[:len(POST_SYSTEM_MESSAGE_PREFIX)] == POST_SYSTEM_MESSAGE_PREFIX +} diff --git a/model/post_test.go b/model/post_test.go index f498c83e6..cbd323fab 100644 --- a/model/post_test.go +++ b/model/post_test.go @@ -98,3 +98,18 @@ func TestPostPreSave(t *testing.T) { o.Etag() } + +func TestPostIsSystemMessage(t *testing.T) { + post1 := Post{Message: "test_1"} + post1.PreSave() + + if post1.IsSystemMessage() { + t.Fatalf("TestPostIsSystemMessage failed, expected post1.IsSystemMessage() to be false") + } + + post2 := Post{Message: "test_2", Type: POST_JOIN_LEAVE} + post2.PreSave() + if !post2.IsSystemMessage() { + t.Fatalf("TestPostIsSystemMessage failed, expected post2.IsSystemMessage() to be true") + } +} diff --git a/model/preference.go b/model/preference.go index 892ae82aa..4f2ba0099 100644 --- a/model/preference.go +++ b/model/preference.go @@ -12,6 +12,7 @@ import ( const ( PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW = "direct_channel_show" PREFERENCE_CATEGORY_TUTORIAL_STEPS = "tutorial_step" + PREFERENCE_CATEGORY_ADVANCED_SETTINGS = "advanced_settings" ) type Preference struct { diff --git a/model/push_notification.go b/model/push_notification.go new file mode 100644 index 000000000..76f5bd125 --- /dev/null +++ b/model/push_notification.go @@ -0,0 +1,45 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "encoding/json" + "io" +) + +const ( + PUSH_NOTIFY_APPLE = "apple" + PUSH_NOTIFY_ANDROID = "android" +) + +type PushNotification struct { + Platform string `json:"platform"` + ServerId string `json:"server_id"` + DeviceId string `json:"device_id"` + Category string `json:"category"` + Sound string `json:"sound"` + Message string `json:"message"` + Badge int `json:"badge"` + ContentAvailable int `json:"cont_ava"` +} + +func (me *PushNotification) ToJson() string { + b, err := json.Marshal(me) + if err != nil { + return "" + } else { + return string(b) + } +} + +func PushNotificationFromJson(data io.Reader) *PushNotification { + decoder := json.NewDecoder(data) + var me PushNotification + err := decoder.Decode(&me) + if err == nil { + return &me + } else { + return nil + } +} diff --git a/model/push_notification_test.go b/model/push_notification_test.go new file mode 100644 index 000000000..94329f389 --- /dev/null +++ b/model/push_notification_test.go @@ -0,0 +1,19 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "strings" + "testing" +) + +func TestPushNotification(t *testing.T) { + msg := PushNotification{Platform: "test"} + json := msg.ToJson() + result := PushNotificationFromJson(strings.NewReader(json)) + + if msg.Platform != result.Platform { + t.Fatal("Ids do not match") + } +} diff --git a/model/user.go b/model/user.go index 4365f47d2..4ba35c6c4 100644 --- a/model/user.go +++ b/model/user.go @@ -4,9 +4,9 @@ package model import ( - "code.google.com/p/go.crypto/bcrypt" "encoding/json" "fmt" + "golang.org/x/crypto/bcrypt" "io" "regexp" "strings" @@ -28,29 +28,29 @@ const ( type User struct { Id string `json:"id"` - CreateAt int64 `json:"create_at"` - UpdateAt int64 `json:"update_at"` + CreateAt int64 `json:"create_at,omitempty"` + UpdateAt int64 `json:"update_at,omitempty"` DeleteAt int64 `json:"delete_at"` TeamId string `json:"team_id"` Username string `json:"username"` - Password string `json:"password"` - AuthData string `json:"auth_data"` + Password string `json:"password,omitempty"` + AuthData string `json:"auth_data,omitempty"` AuthService string `json:"auth_service"` Email string `json:"email"` - EmailVerified bool `json:"email_verified"` + EmailVerified bool `json:"email_verified,omitempty"` Nickname string `json:"nickname"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Roles string `json:"roles"` - LastActivityAt int64 `json:"last_activity_at"` - LastPingAt int64 `json:"last_ping_at"` - AllowMarketing bool `json:"allow_marketing"` - Props StringMap `json:"props"` - NotifyProps StringMap `json:"notify_props"` - ThemeProps StringMap `json:"theme_props"` - LastPasswordUpdate int64 `json:"last_password_update"` - LastPictureUpdate int64 `json:"last_picture_update"` - FailedAttempts int `json:"failed_attempts"` + LastActivityAt int64 `json:"last_activity_at,omitempty"` + LastPingAt int64 `json:"last_ping_at,omitempty"` + AllowMarketing bool `json:"allow_marketing,omitempty"` + Props StringMap `json:"props,omitempty"` + NotifyProps StringMap `json:"notify_props,omitempty"` + ThemeProps StringMap `json:"theme_props,omitempty"` + LastPasswordUpdate int64 `json:"last_password_update,omitempty"` + LastPictureUpdate int64 `json:"last_picture_update,omitempty"` + FailedAttempts int `json:"failed_attempts,omitempty"` } // IsValid validates the user and returns an error if it isn't configured @@ -221,17 +221,28 @@ func (u *User) Sanitize(options map[string]bool) { u.FirstName = "" u.LastName = "" } - if len(options) != 0 && !options["skypeid"] { - // TODO - fill in when SkypeId is added to user model - } - if len(options) != 0 && !options["phonenumber"] { - // TODO - fill in when PhoneNumber is added to user model - } if len(options) != 0 && !options["passwordupdate"] { u.LastPasswordUpdate = 0 } } +func (u *User) ClearNonProfileFields() { + u.CreateAt = 0 + u.UpdateAt = 0 + u.Password = "" + u.AuthData = "" + u.AuthService = "" + u.EmailVerified = false + u.LastPingAt = 0 + u.AllowMarketing = false + u.Props = StringMap{} + u.NotifyProps = StringMap{} + u.ThemeProps = StringMap{} + u.LastPasswordUpdate = 0 + u.LastPictureUpdate = 0 + u.FailedAttempts = 0 +} + func (u *User) MakeNonNil() { if u.Props == nil { u.Props = make(map[string]string) diff --git a/model/utils.go b/model/utils.go index 6d6eb452d..5596b06ff 100644 --- a/model/utils.go +++ b/model/utils.go @@ -5,10 +5,11 @@ package model import ( "bytes" - "code.google.com/p/go-uuid/uuid" + "crypto/rand" "encoding/base32" "encoding/json" "fmt" + "github.com/pborman/uuid" "io" "net/mail" "net/url" @@ -53,7 +54,7 @@ func AppErrorFromJson(data io.Reader) *AppError { if err == nil { return &er } else { - return nil + return NewAppError("AppErrorFromJson", "could not decode", err.Error()) } } @@ -81,6 +82,17 @@ func NewId() string { return b.String() } +func NewRandomString(length int) string { + var b bytes.Buffer + str := make([]byte, length+8) + rand.Read(str) + encoder := base32.NewEncoder(encoding, &b) + encoder.Write(str) + encoder.Close() + b.Truncate(length) // removes the '==' padding + return b.String() +} + // GetMillis is a convience method to get milliseconds since epoch. func GetMillis() int64 { return time.Now().UnixNano() / int64(time.Millisecond) diff --git a/model/utils_test.go b/model/utils_test.go index 7f14bcdf0..1f1e5f023 100644 --- a/model/utils_test.go +++ b/model/utils_test.go @@ -17,6 +17,15 @@ func TestNewId(t *testing.T) { } } +func TestRandomString(t *testing.T) { + for i := 0; i < 1000; i++ { + r := NewRandomString(32) + if len(r) != 32 { + t.Fatal("should be 32 chars") + } + } +} + func TestAppError(t *testing.T) { err := NewAppError("TestAppError", "message", "") json := err.ToJson() diff --git a/model/version.go b/model/version.go index af99717cd..5e41a28d1 100644 --- a/model/version.go +++ b/model/version.go @@ -12,6 +12,7 @@ import ( // It should be maitained in chronological order with most current // release at the front of the list. var versions = []string{ + "1.3.0", "1.2.1", "1.2.0", "1.1.0", |