summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/platform/model/team.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-03-25 21:04:10 +0100
committerWim <wim@42.be>2017-03-25 21:04:10 +0100
commiteacb1c1771cec126593f99f50aca4584236475fa (patch)
tree5ae7d8271c28e378d1d5ca2d0e1e243717a9bdbe /vendor/github.com/mattermost/platform/model/team.go
parent07fd825349e8b7e86f8afb3843cb8e2c2afc7c74 (diff)
downloadmatterbridge-msglm-eacb1c1771cec126593f99f50aca4584236475fa.tar.gz
matterbridge-msglm-eacb1c1771cec126593f99f50aca4584236475fa.tar.bz2
matterbridge-msglm-eacb1c1771cec126593f99f50aca4584236475fa.zip
Update vendor (mattermost)
Diffstat (limited to 'vendor/github.com/mattermost/platform/model/team.go')
-rw-r--r--vendor/github.com/mattermost/platform/model/team.go80
1 files changed, 58 insertions, 22 deletions
diff --git a/vendor/github.com/mattermost/platform/model/team.go b/vendor/github.com/mattermost/platform/model/team.go
index 3f05ce83..99444bc5 100644
--- a/vendor/github.com/mattermost/platform/model/team.go
+++ b/vendor/github.com/mattermost/platform/model/team.go
@@ -7,14 +7,22 @@ import (
"encoding/json"
"fmt"
"io"
+ "net/http"
"regexp"
"strings"
"unicode/utf8"
)
const (
- TEAM_OPEN = "O"
- TEAM_INVITE = "I"
+ TEAM_OPEN = "O"
+ TEAM_INVITE = "I"
+ TEAM_ALLOWED_DOMAINS_MAX_LENGTH = 500
+ TEAM_COMPANY_NAME_MAX_LENGTH = 64
+ TEAM_DESCRIPTION_MAX_LENGTH = 255
+ TEAM_DISPLAY_NAME_MAX_RUNES = 64
+ TEAM_EMAIL_MAX_LENGTH = 128
+ TEAM_NAME_MAX_LENGTH = 64
+ TEAM_NAME_MIN_LENGTH = 2
)
type Team struct {
@@ -48,6 +56,14 @@ func InvitesFromJson(data io.Reader) *Invites {
}
}
+func (o *Invites) ToEmailList() []string {
+ emailList := make([]string, len(o.Invites))
+ for _, invite := range o.Invites {
+ emailList = append(emailList, invite["email"])
+ }
+ return emailList
+}
+
func (o *Invites) ToJson() string {
b, err := json.Marshal(o)
if err != nil {
@@ -97,6 +113,26 @@ func TeamMapFromJson(data io.Reader) map[string]*Team {
}
}
+func TeamListToJson(t []*Team) string {
+ b, err := json.Marshal(t)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+func TeamListFromJson(data io.Reader) []*Team {
+ decoder := json.NewDecoder(data)
+ var teams []*Team
+ err := decoder.Decode(&teams)
+ if err == nil {
+ return teams
+ } else {
+ return nil
+ }
+}
+
func (o *Team) Etag() string {
return Etag(o.Id, o.UpdateAt)
}
@@ -104,55 +140,55 @@ func (o *Team) Etag() string {
func (o *Team) IsValid() *AppError {
if len(o.Id) != 26 {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.id.app_error", nil, "")
+ return NewAppError("Team.IsValid", "model.team.is_valid.id.app_error", nil, "", http.StatusBadRequest)
}
if o.CreateAt == 0 {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.create_at.app_error", nil, "id="+o.Id)
+ return NewAppError("Team.IsValid", "model.team.is_valid.create_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
if o.UpdateAt == 0 {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.update_at.app_error", nil, "id="+o.Id)
+ return NewAppError("Team.IsValid", "model.team.is_valid.update_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
- if len(o.Email) > 128 {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.email.app_error", nil, "id="+o.Id)
+ if len(o.Email) > TEAM_EMAIL_MAX_LENGTH {
+ return NewAppError("Team.IsValid", "model.team.is_valid.email.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
if len(o.Email) > 0 && !IsValidEmail(o.Email) {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.email.app_error", nil, "id="+o.Id)
+ return NewAppError("Team.IsValid", "model.team.is_valid.email.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
- if utf8.RuneCountInString(o.DisplayName) == 0 || utf8.RuneCountInString(o.DisplayName) > 64 {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.name.app_error", nil, "id="+o.Id)
+ if utf8.RuneCountInString(o.DisplayName) == 0 || utf8.RuneCountInString(o.DisplayName) > TEAM_DISPLAY_NAME_MAX_RUNES {
+ return NewAppError("Team.IsValid", "model.team.is_valid.name.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
- if len(o.Name) > 64 {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.url.app_error", nil, "id="+o.Id)
+ if len(o.Name) > TEAM_NAME_MAX_LENGTH {
+ return NewAppError("Team.IsValid", "model.team.is_valid.url.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
- if len(o.Description) > 255 {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.description.app_error", nil, "id="+o.Id)
+ if len(o.Description) > TEAM_DESCRIPTION_MAX_LENGTH {
+ return NewAppError("Team.IsValid", "model.team.is_valid.description.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
if IsReservedTeamName(o.Name) {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.reserved.app_error", nil, "id="+o.Id)
+ return NewAppError("Team.IsValid", "model.team.is_valid.reserved.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
if !IsValidTeamName(o.Name) {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.characters.app_error", nil, "id="+o.Id)
+ return NewAppError("Team.IsValid", "model.team.is_valid.characters.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
if !(o.Type == TEAM_OPEN || o.Type == TEAM_INVITE) {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.type.app_error", nil, "id="+o.Id)
+ return NewAppError("Team.IsValid", "model.team.is_valid.type.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
- if len(o.CompanyName) > 64 {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.company.app_error", nil, "id="+o.Id)
+ if len(o.CompanyName) > TEAM_COMPANY_NAME_MAX_LENGTH {
+ return NewAppError("Team.IsValid", "model.team.is_valid.company.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
- if len(o.AllowedDomains) > 500 {
- return NewLocAppError("Team.IsValid", "model.team.is_valid.domains.app_error", nil, "id="+o.Id)
+ if len(o.AllowedDomains) > TEAM_ALLOWED_DOMAINS_MAX_LENGTH {
+ return NewAppError("Team.IsValid", "model.team.is_valid.domains.app_error", nil, "id="+o.Id, http.StatusBadRequest)
}
return nil
@@ -193,7 +229,7 @@ func IsValidTeamName(s string) bool {
return false
}
- if len(s) <= 1 {
+ if len(s) < TEAM_NAME_MIN_LENGTH {
return false
}