summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/gitlab.go7
-rw-r--r--model/post.go15
-rw-r--r--model/post_test.go15
3 files changed, 33 insertions, 4 deletions
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 5578514b5..2c90d8b7b 100644
--- a/model/post.go
+++ b/model/post.go
@@ -10,9 +10,10 @@ 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"
)
type Post struct {
@@ -112,6 +113,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
}
@@ -155,3 +160,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")
+ }
+}