diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/access.go | 2 | ||||
-rw-r--r-- | model/client.go | 62 | ||||
-rw-r--r-- | model/command.go | 3 | ||||
-rw-r--r-- | model/config.go | 23 | ||||
-rw-r--r-- | model/incoming_webhook.go (renamed from model/webhook.go) | 5 | ||||
-rw-r--r-- | model/incoming_webhook_test.go (renamed from model/webhook_test.go) | 0 | ||||
-rw-r--r-- | model/message.go | 16 | ||||
-rw-r--r-- | model/outgoing_webhook.go | 135 | ||||
-rw-r--r-- | model/outgoing_webhook_test.go | 97 | ||||
-rw-r--r-- | model/search_params.go | 130 | ||||
-rw-r--r-- | model/search_params_test.go | 70 | ||||
-rw-r--r-- | model/session.go | 3 | ||||
-rw-r--r-- | model/team.go | 4 | ||||
-rw-r--r-- | model/team_test.go | 16 | ||||
-rw-r--r-- | model/utils.go | 4 |
15 files changed, 526 insertions, 44 deletions
diff --git a/model/access.go b/model/access.go index 89a1271c1..6c9254004 100644 --- a/model/access.go +++ b/model/access.go @@ -16,7 +16,7 @@ const ( type AccessData struct { AuthCode string `json:"auth_code"` - Token string `json"token"` + Token string `json:"token"` RefreshToken string `json:"refresh_token"` RedirectUri string `json:"redirect_uri"` } diff --git a/model/client.go b/model/client.go index eea65c50e..48a560838 100644 --- a/model/client.go +++ b/model/client.go @@ -16,17 +16,19 @@ import ( ) const ( - HEADER_REQUEST_ID = "X-Request-ID" - HEADER_VERSION_ID = "X-Version-ID" - HEADER_ETAG_SERVER = "ETag" - HEADER_ETAG_CLIENT = "If-None-Match" - HEADER_FORWARDED = "X-Forwarded-For" - HEADER_REAL_IP = "X-Real-IP" - HEADER_FORWARDED_PROTO = "X-Forwarded-Proto" - HEADER_TOKEN = "token" - HEADER_BEARER = "BEARER" - HEADER_AUTH = "Authorization" - API_URL_SUFFIX = "/api/v1" + HEADER_REQUEST_ID = "X-Request-ID" + HEADER_VERSION_ID = "X-Version-ID" + HEADER_ETAG_SERVER = "ETag" + HEADER_ETAG_CLIENT = "If-None-Match" + HEADER_FORWARDED = "X-Forwarded-For" + HEADER_REAL_IP = "X-Real-IP" + HEADER_FORWARDED_PROTO = "X-Forwarded-Proto" + HEADER_TOKEN = "token" + HEADER_BEARER = "BEARER" + HEADER_AUTH = "Authorization" + HEADER_MM_SESSION_TOKEN_INDEX = "X-MM-TokenIndex" + SESSION_TOKEN_INDEX = "session_token_index" + API_URL_SUFFIX = "/api/v1" ) type Result struct { @@ -293,7 +295,7 @@ func (c *Client) login(m map[string]string) (*Result, *AppError) { } else { c.AuthToken = r.Header.Get(HEADER_TOKEN) c.AuthType = HEADER_BEARER - sessionToken := getCookie(SESSION_TOKEN, r) + sessionToken := getCookie(SESSION_COOKIE_TOKEN, r) if c.AuthToken != sessionToken.Value { NewAppError("/users/login", "Authentication tokens didn't match", "") @@ -879,6 +881,42 @@ func (c *Client) GetPreferenceCategory(category string) (*Result, *AppError) { } } +func (c *Client) CreateOutgoingWebhook(hook *OutgoingWebhook) (*Result, *AppError) { + if r, err := c.DoApiPost("/hooks/outgoing/create", hook.ToJson()); err != nil { + return nil, err + } else { + return &Result{r.Header.Get(HEADER_REQUEST_ID), + r.Header.Get(HEADER_ETAG_SERVER), OutgoingWebhookFromJson(r.Body)}, nil + } +} + +func (c *Client) DeleteOutgoingWebhook(data map[string]string) (*Result, *AppError) { + if r, err := c.DoApiPost("/hooks/outgoing/delete", MapToJson(data)); err != nil { + return nil, err + } else { + return &Result{r.Header.Get(HEADER_REQUEST_ID), + r.Header.Get(HEADER_ETAG_SERVER), MapFromJson(r.Body)}, nil + } +} + +func (c *Client) ListOutgoingWebhooks() (*Result, *AppError) { + if r, err := c.DoApiGet("/hooks/outgoing/list", "", ""); err != nil { + return nil, err + } else { + return &Result{r.Header.Get(HEADER_REQUEST_ID), + r.Header.Get(HEADER_ETAG_SERVER), OutgoingWebhookListFromJson(r.Body)}, nil + } +} + +func (c *Client) RegenOutgoingWebhookToken(data map[string]string) (*Result, *AppError) { + if r, err := c.DoApiPost("/hooks/outgoing/regen_token", MapToJson(data)); err != nil { + return nil, err + } else { + return &Result{r.Header.Get(HEADER_REQUEST_ID), + r.Header.Get(HEADER_ETAG_SERVER), OutgoingWebhookFromJson(r.Body)}, nil + } +} + func (c *Client) MockSession(sessionToken string) { c.AuthToken = sessionToken c.AuthType = HEADER_BEARER diff --git a/model/command.go b/model/command.go index 2b26aad1c..5aec5f534 100644 --- a/model/command.go +++ b/model/command.go @@ -9,7 +9,8 @@ import ( ) const ( - RESP_EXECUTED = "executed" + RESP_EXECUTED = "executed" + RESP_NOT_IMPLEMENTED = "not implemented" ) type Command struct { diff --git a/model/config.go b/model/config.go index 8a11b7bb7..216b1de86 100644 --- a/model/config.go +++ b/model/config.go @@ -29,6 +29,7 @@ type ServiceSettings struct { GoogleDeveloperKey string EnableOAuthServiceProvider bool EnableIncomingWebhooks bool + EnableOutgoingWebhooks bool EnablePostUsernameOverride bool EnablePostIconOverride bool EnableTesting bool @@ -121,6 +122,7 @@ type TeamSettings struct { EnableTeamCreation bool EnableUserCreation bool RestrictCreationToDomains string + RestrictTeamNames *bool } type Config struct { @@ -168,6 +170,11 @@ func (o *Config) SetDefaults() { o.ServiceSettings.EnableSecurityFixAlert = new(bool) *o.ServiceSettings.EnableSecurityFixAlert = true } + + if o.TeamSettings.RestrictTeamNames == nil { + o.TeamSettings.RestrictTeamNames = new(bool) + *o.TeamSettings.RestrictTeamNames = true + } } func (o *Config) IsValid() *AppError { @@ -184,8 +191,8 @@ func (o *Config) IsValid() *AppError { 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 len(o.SqlSettings.AtRestEncryptKey) < 32 { + return NewAppError("Config.IsValid", "Invalid at rest encrypt key for SQL settings. Must be 32 chars or more.", "") } if !(o.SqlSettings.DriverName == DATABASE_DRIVER_MYSQL || o.SqlSettings.DriverName == DATABASE_DRIVER_POSTGRES) { @@ -232,20 +239,20 @@ func (o *Config) IsValid() *AppError { 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 len(o.FileSettings.PublicLinkSalt) < 32 { + return NewAppError("Config.IsValid", "Invalid public link salt for file settings. Must be 32 chars or more.", "") } 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.InviteSalt) < 32 { + return NewAppError("Config.IsValid", "Invalid invite salt for email settings. Must be 32 chars or more.", "") } - if len(o.EmailSettings.PasswordResetSalt) != 32 { - return NewAppError("Config.IsValid", "Invalid password reset 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 or more.", "") } if o.RateLimitSettings.MemoryStoreSize <= 0 { diff --git a/model/webhook.go b/model/incoming_webhook.go index 3bf034908..9b9969b96 100644 --- a/model/webhook.go +++ b/model/incoming_webhook.go @@ -8,6 +8,11 @@ import ( "io" ) +const ( + DEFAULT_WEBHOOK_USERNAME = "webhook" + DEFAULT_WEBHOOK_ICON = "/static/images/webhook_icon.jpg" +) + type IncomingWebhook struct { Id string `json:"id"` CreateAt int64 `json:"create_at"` diff --git a/model/webhook_test.go b/model/incoming_webhook_test.go index 5297d7d90..5297d7d90 100644 --- a/model/webhook_test.go +++ b/model/incoming_webhook_test.go diff --git a/model/message.go b/model/message.go index 122af4d9c..2725353ac 100644 --- a/model/message.go +++ b/model/message.go @@ -9,14 +9,14 @@ import ( ) const ( - ACTION_TYPING = "typing" - ACTION_POSTED = "posted" - ACTION_POST_EDITED = "post_edited" - ACTION_POST_DELETED = "post_deleted" - ACTION_VIEWED = "viewed" - ACTION_NEW_USER = "new_user" - ACTION_USER_ADDED = "user_added" - ACTION_USER_REMOVED = "user_removed" + ACTION_TYPING = "typing" + ACTION_POSTED = "posted" + ACTION_POST_EDITED = "post_edited" + ACTION_POST_DELETED = "post_deleted" + ACTION_CHANNEL_VIEWED = "channel_viewed" + ACTION_NEW_USER = "new_user" + ACTION_USER_ADDED = "user_added" + ACTION_USER_REMOVED = "user_removed" ) type Message struct { diff --git a/model/outgoing_webhook.go b/model/outgoing_webhook.go new file mode 100644 index 000000000..8958dd5b0 --- /dev/null +++ b/model/outgoing_webhook.go @@ -0,0 +1,135 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "encoding/json" + "fmt" + "io" +) + +type OutgoingWebhook struct { + Id string `json:"id"` + Token string `json:"token"` + CreateAt int64 `json:"create_at"` + UpdateAt int64 `json:"update_at"` + DeleteAt int64 `json:"delete_at"` + CreatorId string `json:"creator_id"` + ChannelId string `json:"channel_id"` + TeamId string `json:"team_id"` + TriggerWords StringArray `json:"trigger_words"` + CallbackURLs StringArray `json:"callback_urls"` +} + +func (o *OutgoingWebhook) ToJson() string { + b, err := json.Marshal(o) + if err != nil { + return "" + } else { + return string(b) + } +} + +func OutgoingWebhookFromJson(data io.Reader) *OutgoingWebhook { + decoder := json.NewDecoder(data) + var o OutgoingWebhook + err := decoder.Decode(&o) + if err == nil { + return &o + } else { + return nil + } +} + +func OutgoingWebhookListToJson(l []*OutgoingWebhook) string { + b, err := json.Marshal(l) + if err != nil { + return "" + } else { + return string(b) + } +} + +func OutgoingWebhookListFromJson(data io.Reader) []*OutgoingWebhook { + decoder := json.NewDecoder(data) + var o []*OutgoingWebhook + err := decoder.Decode(&o) + if err == nil { + return o + } else { + return nil + } +} + +func (o *OutgoingWebhook) IsValid() *AppError { + + if len(o.Id) != 26 { + return NewAppError("OutgoingWebhook.IsValid", "Invalid Id", "") + } + + if len(o.Token) != 26 { + return NewAppError("OutgoingWebhook.IsValid", "Invalid token", "") + } + + if o.CreateAt == 0 { + return NewAppError("OutgoingWebhook.IsValid", "Create at must be a valid time", "id="+o.Id) + } + + if o.UpdateAt == 0 { + return NewAppError("OutgoingWebhook.IsValid", "Update at must be a valid time", "id="+o.Id) + } + + if len(o.CreatorId) != 26 { + return NewAppError("OutgoingWebhook.IsValid", "Invalid user id", "") + } + + if len(o.ChannelId) != 0 && len(o.ChannelId) != 26 { + return NewAppError("OutgoingWebhook.IsValid", "Invalid channel id", "") + } + + if len(o.TeamId) != 26 { + return NewAppError("OutgoingWebhook.IsValid", "Invalid team id", "") + } + + if len(fmt.Sprintf("%s", o.TriggerWords)) > 1024 { + return NewAppError("OutgoingWebhook.IsValid", "Invalid trigger words", "") + } + + if len(o.CallbackURLs) == 0 || len(fmt.Sprintf("%s", o.CallbackURLs)) > 1024 { + return NewAppError("OutgoingWebhook.IsValid", "Invalid callback urls", "") + } + + return nil +} + +func (o *OutgoingWebhook) PreSave() { + if o.Id == "" { + o.Id = NewId() + } + + if o.Token == "" { + o.Token = NewId() + } + + o.CreateAt = GetMillis() + o.UpdateAt = o.CreateAt +} + +func (o *OutgoingWebhook) PreUpdate() { + o.UpdateAt = GetMillis() +} + +func (o *OutgoingWebhook) HasTriggerWord(word string) bool { + if len(o.TriggerWords) == 0 || len(word) == 0 { + return false + } + + for _, trigger := range o.TriggerWords { + if trigger == word { + return true + } + } + + return false +} diff --git a/model/outgoing_webhook_test.go b/model/outgoing_webhook_test.go new file mode 100644 index 000000000..2ca48c291 --- /dev/null +++ b/model/outgoing_webhook_test.go @@ -0,0 +1,97 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "strings" + "testing" +) + +func TestOutgoingWebhookJson(t *testing.T) { + o := OutgoingWebhook{Id: NewId()} + json := o.ToJson() + ro := OutgoingWebhookFromJson(strings.NewReader(json)) + + if o.Id != ro.Id { + t.Fatal("Ids do not match") + } +} + +func TestOutgoingWebhookIsValid(t *testing.T) { + o := OutgoingWebhook{} + + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.Id = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.CreateAt = GetMillis() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.UpdateAt = GetMillis() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.CreatorId = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.CreatorId = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.Token = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.Token = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.ChannelId = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.ChannelId = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.TeamId = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.TeamId = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.CallbackURLs = []string{"http://nowhere.com/"} + if err := o.IsValid(); err != nil { + t.Fatal(err) + } +} + +func TestOutgoingWebhookPreSave(t *testing.T) { + o := OutgoingWebhook{} + o.PreSave() +} + +func TestOutgoingWebhookPreUpdate(t *testing.T) { + o := OutgoingWebhook{} + o.PreUpdate() +} diff --git a/model/search_params.go b/model/search_params.go new file mode 100644 index 000000000..7eeeed10f --- /dev/null +++ b/model/search_params.go @@ -0,0 +1,130 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "strings" +) + +type SearchParams struct { + Terms string + IsHashtag bool + InChannel string + FromUser string +} + +var searchFlags = [...]string{"from", "channel", "in"} + +func splitWords(text string) []string { + words := []string{} + + for _, word := range strings.Fields(text) { + word = puncStart.ReplaceAllString(word, "") + word = puncEnd.ReplaceAllString(word, "") + + if len(word) != 0 { + words = append(words, word) + } + } + + return words +} + +func parseSearchFlags(input []string) ([]string, map[string]string) { + words := []string{} + flags := make(map[string]string) + + skipNextWord := false + for i, word := range input { + if skipNextWord { + skipNextWord = false + continue + } + + isFlag := false + + if colon := strings.Index(word, ":"); colon != -1 { + flag := word[:colon] + value := word[colon+1:] + + for _, searchFlag := range searchFlags { + // check for case insensitive equality + if strings.EqualFold(flag, searchFlag) { + if value != "" { + flags[searchFlag] = value + isFlag = true + } else if i < len(input)-1 { + flags[searchFlag] = input[i+1] + skipNextWord = true + isFlag = true + } + + if isFlag { + break + } + } + } + } + + if !isFlag { + words = append(words, word) + } + } + + return words, flags +} + +func ParseSearchParams(text string) (*SearchParams, *SearchParams) { + words, flags := parseSearchFlags(splitWords(text)) + + hashtagTerms := []string{} + plainTerms := []string{} + + for _, word := range words { + if validHashtag.MatchString(word) { + hashtagTerms = append(hashtagTerms, word) + } else { + plainTerms = append(plainTerms, word) + } + } + + inChannel := flags["channel"] + if inChannel == "" { + inChannel = flags["in"] + } + + fromUser := flags["from"] + + var plainParams *SearchParams + if len(plainTerms) > 0 { + plainParams = &SearchParams{ + Terms: strings.Join(plainTerms, " "), + IsHashtag: false, + InChannel: inChannel, + FromUser: fromUser, + } + } + + var hashtagParams *SearchParams + if len(hashtagTerms) > 0 { + hashtagParams = &SearchParams{ + Terms: strings.Join(hashtagTerms, " "), + IsHashtag: true, + InChannel: inChannel, + FromUser: fromUser, + } + } + + // special case for when no terms are specified but we still have a filter + if plainParams == nil && hashtagParams == nil && (inChannel != "" || fromUser != "") { + plainParams = &SearchParams{ + Terms: "", + IsHashtag: false, + InChannel: inChannel, + FromUser: fromUser, + } + } + + return plainParams, hashtagParams +} diff --git a/model/search_params_test.go b/model/search_params_test.go new file mode 100644 index 000000000..2eba20f4c --- /dev/null +++ b/model/search_params_test.go @@ -0,0 +1,70 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "testing" +) + +func TestParseSearchFlags(t *testing.T) { + if words, flags := parseSearchFlags(splitWords("")); len(words) != 0 { + t.Fatal("got words from empty input") + } else if len(flags) != 0 { + t.Fatal("got flags from empty input") + } + + if words, flags := parseSearchFlags(splitWords("word")); len(words) != 1 || words[0] != "word" { + t.Fatalf("got incorrect words %v", words) + } else if len(flags) != 0 { + t.Fatalf("got incorrect flags %v", flags) + } + + if words, flags := parseSearchFlags(splitWords("apple banana cherry")); len(words) != 3 || words[0] != "apple" || words[1] != "banana" || words[2] != "cherry" { + t.Fatalf("got incorrect words %v", words) + } else if len(flags) != 0 { + t.Fatalf("got incorrect flags %v", flags) + } + + if words, flags := parseSearchFlags(splitWords("apple banana from:chan")); len(words) != 2 || words[0] != "apple" || words[1] != "banana" { + t.Fatalf("got incorrect words %v", words) + } else if len(flags) != 1 || flags["from"] != "chan" { + t.Fatalf("got incorrect flags %v", flags) + } + + if words, flags := parseSearchFlags(splitWords("apple banana from: chan")); len(words) != 2 || words[0] != "apple" || words[1] != "banana" { + t.Fatalf("got incorrect words %v", words) + } else if len(flags) != 1 || flags["from"] != "chan" { + t.Fatalf("got incorrect flags %v", flags) + } + + if words, flags := parseSearchFlags(splitWords("apple banana in: chan")); len(words) != 2 || words[0] != "apple" || words[1] != "banana" { + t.Fatalf("got incorrect words %v", words) + } else if len(flags) != 1 || flags["in"] != "chan" { + t.Fatalf("got incorrect flags %v", flags) + } + + if words, flags := parseSearchFlags(splitWords("apple banana channel:chan")); len(words) != 2 || words[0] != "apple" || words[1] != "banana" { + t.Fatalf("got incorrect words %v", words) + } else if len(flags) != 1 || flags["channel"] != "chan" { + t.Fatalf("got incorrect flags %v", flags) + } + + if words, flags := parseSearchFlags(splitWords("fruit: cherry")); len(words) != 2 || words[0] != "fruit:" || words[1] != "cherry" { + t.Fatalf("got incorrect words %v", words) + } else if len(flags) != 0 { + t.Fatalf("got incorrect flags %v", flags) + } + + if words, flags := parseSearchFlags(splitWords("channel:")); len(words) != 1 || words[0] != "channel:" { + t.Fatalf("got incorrect words %v", words) + } else if len(flags) != 0 { + t.Fatalf("got incorrect flags %v", flags) + } + + if words, flags := parseSearchFlags(splitWords("channel: first in: second from:")); len(words) != 1 || words[0] != "from:" { + t.Fatalf("got incorrect words %v", words) + } else if len(flags) != 2 || flags["channel"] != "first" || flags["in"] != "second" { + t.Fatalf("got incorrect flags %v", flags) + } +} diff --git a/model/session.go b/model/session.go index e2c1d4c55..5fe74a161 100644 --- a/model/session.go +++ b/model/session.go @@ -9,8 +9,7 @@ import ( ) const ( - SESSION_TOKEN = "MMSID" - MULTI_SESSION_TOKEN = "MMSIDMU" + SESSION_COOKIE_TOKEN = "MMTOKEN" 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/team.go b/model/team.go index 584c78f8d..9da2cd5b2 100644 --- a/model/team.go +++ b/model/team.go @@ -97,7 +97,7 @@ func (o *Team) Etag() string { return Etag(o.Id, o.UpdateAt) } -func (o *Team) IsValid() *AppError { +func (o *Team) IsValid(restrictTeamNames bool) *AppError { if len(o.Id) != 26 { return NewAppError("Team.IsValid", "Invalid Id", "") @@ -127,7 +127,7 @@ func (o *Team) IsValid() *AppError { return NewAppError("Team.IsValid", "Invalid URL Identifier", "id="+o.Id) } - if IsReservedTeamName(o.Name) { + if restrictTeamNames && IsReservedTeamName(o.Name) { return NewAppError("Team.IsValid", "This URL is unavailable. Please try another.", "id="+o.Id) } diff --git a/model/team_test.go b/model/team_test.go index fd2428f03..112d48a9d 100644 --- a/model/team_test.go +++ b/model/team_test.go @@ -21,45 +21,45 @@ func TestTeamJson(t *testing.T) { func TestTeamIsValid(t *testing.T) { o := Team{} - if err := o.IsValid(); err == nil { + if err := o.IsValid(true); err == nil { t.Fatal("should be invalid") } o.Id = NewId() - if err := o.IsValid(); err == nil { + if err := o.IsValid(true); err == nil { t.Fatal("should be invalid") } o.CreateAt = GetMillis() - if err := o.IsValid(); err == nil { + if err := o.IsValid(true); err == nil { t.Fatal("should be invalid") } o.UpdateAt = GetMillis() - if err := o.IsValid(); err == nil { + if err := o.IsValid(true); err == nil { t.Fatal("should be invalid") } o.Email = strings.Repeat("01234567890", 20) - if err := o.IsValid(); err == nil { + if err := o.IsValid(true); err == nil { t.Fatal("should be invalid") } o.Email = "corey@hulen.com" o.DisplayName = strings.Repeat("01234567890", 20) - if err := o.IsValid(); err == nil { + if err := o.IsValid(true); err == nil { t.Fatal("should be invalid") } o.DisplayName = "1234" o.Name = "ZZZZZZZ" - if err := o.IsValid(); err == nil { + if err := o.IsValid(true); err == nil { t.Fatal("should be invalid") } o.Name = "zzzzz" o.Type = TEAM_OPEN - if err := o.IsValid(); err != nil { + if err := o.IsValid(true); err != nil { t.Fatal(err) } } diff --git a/model/utils.go b/model/utils.go index 269144afc..bb0669df7 100644 --- a/model/utils.go +++ b/model/utils.go @@ -242,10 +242,10 @@ func Etag(parts ...interface{}) string { var validHashtag = regexp.MustCompile(`^(#[A-Za-z]+[A-Za-z0-9_\-]*[A-Za-z0-9])$`) var puncStart = regexp.MustCompile(`^[.,()&$!\[\]{}"':;\\]+`) -var puncEnd = regexp.MustCompile(`[.,()&$#!\[\]{}"':;\\]+$`) +var puncEnd = regexp.MustCompile(`[.,()&$#!\[\]{}"';\\]+$`) func ParseHashtags(text string) (string, string) { - words := strings.Split(strings.Replace(text, "\n", " ", -1), " ") + words := strings.Fields(text) hashtagString := "" plainString := "" |