Этот коммит содержится в:
=Corey Hulen
2016-02-01 14:44:17 -08:00
родитель ea71731f83 f28486c455
Коммит b4ec690051
201 изменённых файлов: 12609 добавлений и 2308 удалений

Просмотреть файл

@@ -820,6 +820,17 @@ func (c *Client) UpdateUserRoles(data map[string]string) (*Result, *AppError) {
}
}
func (c *Client) AttachDeviceId(deviceId string) (*Result, *AppError) {
data := make(map[string]string)
data["device_id"] = deviceId
if r, err := c.DoApiPost("/users/attach_device", MapToJson(data)); err != nil {
return nil, err
} else {
return &Result{r.Header.Get(HEADER_REQUEST_ID),
r.Header.Get(HEADER_ETAG_SERVER), UserFromJson(r.Body)}, nil
}
}
func (c *Client) UpdateActive(userId string, active bool) (*Result, *AppError) {
data := make(map[string]string)
data["user_id"] = userId

Просмотреть файл

@@ -20,12 +20,7 @@ func splitWordsNoQuotes(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)
}
words = append(words, word)
}
return words
@@ -94,7 +89,16 @@ func parseSearchFlags(input []string) ([]string, [][2]string) {
}
if !isFlag {
words = append(words, word)
// trim off surrounding punctuation
word = puncStart.ReplaceAllString(word, "")
word = puncEnd.ReplaceAllString(word, "")
// and remove extra pound #s
word = hashtagStart.ReplaceAllString(word, "#")
if len(word) != 0 {
words = append(words, word)
}
}
}

Просмотреть файл

@@ -118,19 +118,19 @@ func TestParseSearchFlags(t *testing.T) {
t.Fatalf("got incorrect flags %v", flags)
}
if words, flags := parseSearchFlags(splitWords("fruit: cherry")); len(words) != 2 || words[0] != "fruit:" || words[1] != "cherry" {
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:" {
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:" {
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[0][0] != "channel" || flags[0][1] != "first" || flags[1][0] != "in" || flags[1][1] != "second" {
t.Fatalf("got incorrect flags %v", flags)
@@ -212,4 +212,8 @@ func TestParseSearchParams(t *testing.T) {
if sp := ParseSearchParams("testing in:channel from:someone"); len(sp) != 1 || sp[0].Terms != "testing" || len(sp[0].InChannels) != 1 || sp[0].InChannels[0] != "channel" || len(sp[0].FromUsers) != 1 || sp[0].FromUsers[0] != "someone" {
t.Fatalf("Incorrect output from parse search params: %v", sp[0])
}
if sp := ParseSearchParams("##hashtag +#plus+"); len(sp) != 1 || sp[0].Terms != "#hashtag #plus" || sp[0].IsHashtag != true || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 {
t.Fatalf("Incorrect output from parse search params: %v", sp[0])
}
}

Просмотреть файл

@@ -71,16 +71,6 @@ func AppErrorFromJson(data io.Reader) *AppError {
}
}
func NewAppError(where string, message string, details string) *AppError {
ap := &AppError{}
ap.Message = message
ap.Where = where
ap.DetailedError = details
ap.StatusCode = 500
ap.IsOAuth = false
return ap
}
func NewLocAppError(where string, id string, params map[string]interface{}, details string) *AppError {
ap := &AppError{}
ap.Id = id
@@ -298,8 +288,9 @@ 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 puncStart = regexp.MustCompile(`^[.,()&$!\?\[\]{}':;\\<>\-+=%^*|]+`)
var hashtagStart = regexp.MustCompile(`^#{2,}`)
var puncEnd = regexp.MustCompile(`[.,()&$#!\?\[\]{}':;\\<>\-+=%^*|]+$`)
func ParseHashtags(text string) (string, string) {
words := strings.Fields(text)
@@ -307,8 +298,13 @@ func ParseHashtags(text string) (string, string) {
hashtagString := ""
plainString := ""
for _, word := range words {
// trim off surrounding punctuation
word = puncStart.ReplaceAllString(word, "")
word = puncEnd.ReplaceAllString(word, "")
// and remove extra pound #s
word = hashtagStart.ReplaceAllString(word, "#")
if validHashtag.MatchString(word) {
hashtagString += " " + word
} else {

Просмотреть файл

@@ -27,7 +27,7 @@ func TestRandomString(t *testing.T) {
}
func TestAppError(t *testing.T) {
err := NewAppError("TestAppError", "message", "")
err := NewLocAppError("TestAppError", "message", nil, "")
json := err.ToJson()
rerr := AppErrorFromJson(strings.NewReader(json))
if err.Message != rerr.Message {
@@ -83,19 +83,34 @@ func TestEtag(t *testing.T) {
}
var hashtags map[string]string = map[string]string{
"#test": "#test",
"test": "",
"#test123": "#test123",
"#123test123": "",
"#test-test": "#test-test",
"#test?": "#test",
"hi #there": "#there",
"#bug #idea": "#bug #idea",
"#bug or #gif!": "#bug #gif",
"#hüllo": "#hüllo",
"#?test": "",
"#-test": "",
"#yo_yo": "#yo_yo",
"#test": "#test",
"test": "",
"#test123": "#test123",
"#123test123": "",
"#test-test": "#test-test",
"#test?": "#test",
"hi #there": "#there",
"#bug #idea": "#bug #idea",
"#bug or #gif!": "#bug #gif",
"#hüllo": "#hüllo",
"#?test": "",
"#-test": "",
"#yo_yo": "#yo_yo",
"(#brakets)": "#brakets",
")#stekarb(": "#stekarb",
"<#less_than<": "#less_than",
">#greater_than>": "#greater_than",
"-#minus-": "#minus",
"+#plus+": "#plus",
"=#equals=": "#equals",
"%#pct%": "#pct",
"&#and&": "#and",
"^#hat^": "#hat",
"##brown#": "#brown",
"*#star*": "#star",
"|#pipe|": "#pipe",
":#colon:": "#colon",
";#semi;": "#semi",
}
func TestParseHashtags(t *testing.T) {

Просмотреть файл

@@ -4,6 +4,7 @@
package model
import (
"fmt"
"strconv"
"strings"
)
@@ -25,10 +26,27 @@ var versions = []string{
}
var CurrentVersion string = versions[0]
var BuildNumber = "dev"
var BuildDate = "Fri Jan 8 14:19:26 UTC 2016"
var BuildHash = "001a4448ca5fb0018eeb442915b473b121c04bf3"
var BuildEnterpriseReady = "false"
var BuildNumber = "_BUILD_NUMBER_"
var BuildDate = "_BUILD_DATE_"
var BuildHash = "_BUILD_HASH_"
var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_"
var versionsWithoutHotFixes []string
func init() {
versionsWithoutHotFixes = make([]string, 0, len(versions))
seen := make(map[string]string)
for _, version := range versions {
maj, min, _ := SplitVersion(version)
verStr := fmt.Sprintf("%v.%v.0", maj, min)
if seen[verStr] == "" {
versionsWithoutHotFixes = append(versionsWithoutHotFixes, verStr)
seen[verStr] = verStr
}
}
}
func SplitVersion(version string) (int64, int64, int64) {
parts := strings.Split(version, ".")
@@ -52,25 +70,17 @@ func SplitVersion(version string) (int64, int64, int64) {
return major, minor, patch
}
func GetPreviousVersion(currentVersion string) (int64, int64) {
currentIndex := -1
currentMajor, currentMinor, _ := SplitVersion(currentVersion)
func GetPreviousVersion(version string) string {
verMajor, verMinor, _ := SplitVersion(version)
verStr := fmt.Sprintf("%v.%v.0", verMajor, verMinor)
for index, version := range versions {
major, minor, _ := SplitVersion(version)
if currentMajor == major && currentMinor == minor {
currentIndex = index
}
if currentIndex >= 0 {
if currentMajor != major || currentMinor != minor {
return major, minor
}
for index, v := range versionsWithoutHotFixes {
if v == verStr && len(versionsWithoutHotFixes) > index+1 {
return versionsWithoutHotFixes[index+1]
}
}
return 0, 0
return ""
}
func IsOfficalBuild() bool {
@@ -88,13 +98,24 @@ func IsCurrentVersion(versionToCheck string) bool {
}
}
func IsPreviousVersion(versionToCheck string) bool {
func IsPreviousVersionsSupported(versionToCheck string) bool {
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
prevMajor, prevMinor := GetPreviousVersion(CurrentVersion)
versionToCheckStr := fmt.Sprintf("%v.%v.0", toCheckMajor, toCheckMinor)
if toCheckMajor == prevMajor && toCheckMinor == prevMinor {
// Current Supported
if versionsWithoutHotFixes[0] == versionToCheckStr {
return true
} else {
return false
}
// Current - 1 Supported
if versionsWithoutHotFixes[1] == versionToCheckStr {
return true
}
// Current - 2 Supported
if versionsWithoutHotFixes[2] == versionToCheckStr {
return true
}
return false
}

Просмотреть файл

@@ -36,20 +36,28 @@ func TestSplitVersion(t *testing.T) {
}
func TestGetPreviousVersion(t *testing.T) {
if major, minor := GetPreviousVersion("1.0.0"); major != 0 || minor != 7 {
t.Fatal(major, minor)
if GetPreviousVersion("1.3.0") != "1.2.0" {
t.Fatal()
}
if major, minor := GetPreviousVersion("0.7.0"); major != 0 || minor != 6 {
t.Fatal(major, minor)
if GetPreviousVersion("1.2.1") != "1.1.0" {
t.Fatal()
}
if major, minor := GetPreviousVersion("0.7.1"); major != 0 || minor != 6 {
t.Fatal(major, minor)
if GetPreviousVersion("1.1.0") != "1.0.0" {
t.Fatal()
}
if major, minor := GetPreviousVersion("0.7111.1"); major != 0 || minor != 0 {
t.Fatal(major, minor)
if GetPreviousVersion("1.0.0") != "0.7.0" {
t.Fatal()
}
if GetPreviousVersion("0.7.1") != "0.6.0" {
t.Fatal()
}
if GetPreviousVersion("0.5.0") != "" {
t.Fatal()
}
}
@@ -72,3 +80,31 @@ func TestIsCurrentVersion(t *testing.T) {
t.Fatal()
}
}
func TestIsPreviousVersionsSupported(t *testing.T) {
// 1.4.0 CURRENT RELEASED VERSION
if !IsPreviousVersionsSupported(versions[0]) {
t.Fatal()
}
// 1.3.0
if !IsPreviousVersionsSupported(versions[1]) {
t.Fatal()
}
// 1.2.1
if !IsPreviousVersionsSupported(versions[2]) {
t.Fatal()
}
// 1.2.0
if !IsPreviousVersionsSupported(versions[3]) {
t.Fatal()
}
// 1.1.0 NOT SUPPORTED
if IsPreviousVersionsSupported(versions[4]) {
t.Fatal()
}
}