PLT-4165 removing team name reserved words (#4289)
Этот коммит содержится в:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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" {
|
||||
if CleanTeamName("Jimbo's Admin") != "jimbos-admin" {
|
||||
t.Fatal("didn't clean name properly")
|
||||
}
|
||||
if len(CleanTeamName("Test")) != 26 {
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Ссылка в новой задаче
Block a user