From 1ef5523b9f430165f2bf7fe91570747cf88c4f1d Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 25 Jun 2020 16:00:12 +0200 Subject: [PATCH] [MM-26390] Ensures the generated team name in sampledata is a valid one (#14901) --- cmd/mattermost/commands/sampledata.go | 11 ++++++++++- model/team.go | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/mattermost/commands/sampledata.go b/cmd/mattermost/commands/sampledata.go index 8fb3efd229..07f21b8d4e 100644 --- a/cmd/mattermost/commands/sampledata.go +++ b/cmd/mattermost/commands/sampledata.go @@ -563,9 +563,18 @@ func createChannelMembership(channelName string, guest bool) app.UserChannelImpo } } +func getSampleTeamName(idx int) string { + for { + name := fmt.Sprintf("%s-%d", fake.Word(), idx) + if !model.IsReservedTeamName(name) { + return name + } + } +} + func createTeam(idx int) app.LineImportData { displayName := fake.Word() - name := fmt.Sprintf("%s-%d", fake.Word(), idx) + name := getSampleTeamName(idx) allowOpenInvite := rand.Intn(2) == 0 description := fake.Paragraph() diff --git a/model/team.go b/model/team.go index ca0f94fee7..381eb8bb9f 100644 --- a/model/team.go +++ b/model/team.go @@ -234,7 +234,6 @@ func IsReservedTeamName(s string) bool { } func IsValidTeamName(s string) bool { - if !IsValidAlphaNum(s) { return false }