summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-10-21 17:19:28 -0700
committerGitHub <noreply@github.com>2016-10-21 17:19:28 -0700
commit486d12e1c3a5d6658ca0ebd8fd28bec9f6753ce9 (patch)
tree1833ccb7c0ecfccf1400fa5c8153902d8c058fe0 /model
parent38855327502420f06d1235d9ac34a66d0bcbca34 (diff)
downloadchat-486d12e1c3a5d6658ca0ebd8fd28bec9f6753ce9.tar.gz
chat-486d12e1c3a5d6658ca0ebd8fd28bec9f6753ce9.tar.bz2
chat-486d12e1c3a5d6658ca0ebd8fd28bec9f6753ce9.zip
PLT-4165 removing team name reserved words (#4289)
Diffstat (limited to 'model')
-rw-r--r--model/config.go6
-rw-r--r--model/team.go4
-rw-r--r--model/team_test.go27
-rw-r--r--model/utils.go47
4 files changed, 16 insertions, 68 deletions
diff --git a/model/config.go b/model/config.go
index 09bf11a71..321307539 100644
--- a/model/config.go
+++ b/model/config.go
@@ -214,7 +214,6 @@ type TeamSettings struct {
EnableUserCreation bool
EnableOpenServer *bool
RestrictCreationToDomains string
- RestrictTeamNames *bool
EnableCustomBrand *bool
CustomBrandText *string
CustomDescriptionText *string
@@ -453,11 +452,6 @@ func (o *Config) SetDefaults() {
*o.PasswordSettings.Symbol = false
}
- if o.TeamSettings.RestrictTeamNames == nil {
- o.TeamSettings.RestrictTeamNames = new(bool)
- *o.TeamSettings.RestrictTeamNames = true
- }
-
if o.TeamSettings.EnableCustomBrand == nil {
o.TeamSettings.EnableCustomBrand = new(bool)
*o.TeamSettings.EnableCustomBrand = false
diff --git a/model/team.go b/model/team.go
index dccc0219e..38feda325 100644
--- a/model/team.go
+++ b/model/team.go
@@ -100,7 +100,7 @@ func (o *Team) Etag() string {
return Etag(o.Id, o.UpdateAt)
}
-func (o *Team) IsValid(restrictTeamNames bool) *AppError {
+func (o *Team) IsValid() *AppError {
if len(o.Id) != 26 {
return NewLocAppError("Team.IsValid", "model.team.is_valid.id.app_error", nil, "")
@@ -130,7 +130,7 @@ func (o *Team) IsValid(restrictTeamNames bool) *AppError {
return NewLocAppError("Team.IsValid", "model.team.is_valid.url.app_error", nil, "id="+o.Id)
}
- if restrictTeamNames && IsReservedTeamName(o.Name) {
+ if IsReservedTeamName(o.Name) {
return NewLocAppError("Team.IsValid", "model.team.is_valid.reserved.app_error", nil, "id="+o.Id)
}
diff --git a/model/team_test.go b/model/team_test.go
index 4b691e76a..eb7e27b0e 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(true); err == nil {
+ if err := o.IsValid(); err == nil {
t.Fatal("should be invalid")
}
o.Id = NewId()
- if err := o.IsValid(true); err == nil {
+ if err := o.IsValid(); err == nil {
t.Fatal("should be invalid")
}
o.CreateAt = GetMillis()
- if err := o.IsValid(true); err == nil {
+ if err := o.IsValid(); err == nil {
t.Fatal("should be invalid")
}
o.UpdateAt = GetMillis()
- if err := o.IsValid(true); err == nil {
+ if err := o.IsValid(); err == nil {
t.Fatal("should be invalid")
}
o.Email = strings.Repeat("01234567890", 20)
- if err := o.IsValid(true); err == nil {
+ if err := o.IsValid(); err == nil {
t.Fatal("should be invalid")
}
o.Email = "corey+test@hulen.com"
o.DisplayName = strings.Repeat("01234567890", 20)
- if err := o.IsValid(true); err == nil {
+ if err := o.IsValid(); err == nil {
t.Fatal("should be invalid")
}
o.DisplayName = "1234"
o.Name = "ZZZZZZZ"
- if err := o.IsValid(true); err == nil {
+ if err := o.IsValid(); err == nil {
t.Fatal("should be invalid")
}
o.Name = "zzzzz"
o.Type = TEAM_OPEN
- if err := o.IsValid(true); err != nil {
+ if err := o.IsValid(); err != nil {
t.Fatal(err)
}
}
@@ -104,8 +104,6 @@ var tReservedDomains = []struct {
value string
expected bool
}{
- {"test-hello", true},
- {"test", true},
{"admin", true},
{"Admin-punch", true},
{"spin-punch-admin", false},
@@ -120,15 +118,14 @@ func TestReservedTeamName(t *testing.T) {
}
func TestCleanTeamName(t *testing.T) {
- if CleanTeamName("Jimbo's Team") != "jimbos-team" {
- t.Fatal("didn't clean name properly")
- }
- if len(CleanTeamName("Test")) != 26 {
+ if CleanTeamName("Jimbo's Admin") != "jimbos-admin" {
t.Fatal("didn't clean name properly")
}
- if CleanTeamName("Team Really cool") != "really-cool" {
+
+ if CleanTeamName("Admin Really cool") != "really-cool" {
t.Fatal("didn't clean name properly")
}
+
if CleanTeamName("super-duper-guys") != "super-duper-guys" {
t.Fatal("didn't clean name properly")
}
diff --git a/model/utils.go b/model/utils.go
index 4ebd23939..457b64c09 100644
--- a/model/utils.go
+++ b/model/utils.go
@@ -253,58 +253,15 @@ func IsValidEmail(email string) bool {
}
var reservedName = []string{
- "www",
- "web",
+ "signup",
+ "login",
"admin",
- "support",
- "notify",
- "test",
- "demo",
- "mail",
- "team",
"channel",
- "internal",
- "localhost",
- "dockerhost",
- "stag",
"post",
- "cluster",
"api",
"oauth",
}
-var wwwStart = regexp.MustCompile(`^www`)
-var betaStart = regexp.MustCompile(`^beta`)
-var ciStart = regexp.MustCompile(`^ci`)
-
-func GetSubDomain(s string) (string, string) {
- s = strings.Replace(s, "http://", "", 1)
- s = strings.Replace(s, "https://", "", 1)
-
- match := wwwStart.MatchString(s)
- if match {
- return "", ""
- }
-
- match = betaStart.MatchString(s)
- if match {
- return "", ""
- }
-
- match = ciStart.MatchString(s)
- if match {
- return "", ""
- }
-
- parts := strings.Split(s, ".")
-
- if len(parts) != 3 {
- return "", ""
- }
-
- return parts[0], parts[1]
-}
-
func IsValidChannelIdentifier(s string) bool {
if !IsValidAlphaNum(s, true) {