Skip to content

Commit

Permalink
PLT-4165 removing team name reserved words (#4289)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyhulen committed Oct 22, 2016
1 parent 3885532 commit 486d12e
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 113 deletions.
2 changes: 1 addition & 1 deletion api/team.go
Expand Up @@ -122,7 +122,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {

teamSignup.Team.PreSave()

if err := teamSignup.Team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); err != nil {
if err := teamSignup.Team.IsValid(); err != nil {
c.Err = err
return
}
Expand Down
1 change: 0 additions & 1 deletion config/config.json
Expand Up @@ -43,7 +43,6 @@
"EnableUserCreation": true,
"EnableOpenServer": false,
"RestrictCreationToDomains": "",
"RestrictTeamNames": true,
"EnableCustomBrand": false,
"CustomBrandText": "",
"CustomDescriptionText": "",
Expand Down
6 changes: 0 additions & 6 deletions model/config.go
Expand Up @@ -214,7 +214,6 @@ type TeamSettings struct {
EnableUserCreation bool
EnableOpenServer *bool
RestrictCreationToDomains string
RestrictTeamNames *bool
EnableCustomBrand *bool
CustomBrandText *string
CustomDescriptionText *string
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions model/team.go
Expand Up @@ -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, "")
Expand Down Expand Up @@ -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)
}

Expand Down
27 changes: 12 additions & 15 deletions model/team_test.go
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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},
Expand All @@ -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")
}
Expand Down
47 changes: 2 additions & 45 deletions model/utils.go
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions store/sql_team_store.go
Expand Up @@ -65,7 +65,7 @@ func (s SqlTeamStore) Save(team *model.Team) StoreChannel {

team.PreSave()

if result.Err = team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); result.Err != nil {
if result.Err = team.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
Expand Down Expand Up @@ -97,7 +97,7 @@ func (s SqlTeamStore) Update(team *model.Team) StoreChannel {

team.PreUpdate()

if result.Err = team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); result.Err != nil {
if result.Err = team.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
Expand Down
1 change: 0 additions & 1 deletion utils/config.go
Expand Up @@ -236,7 +236,6 @@ func getClientConfig(c *model.Config) map[string]string {
props["EnableTeamCreation"] = strconv.FormatBool(c.TeamSettings.EnableTeamCreation)
props["EnableUserCreation"] = strconv.FormatBool(c.TeamSettings.EnableUserCreation)
props["EnableOpenServer"] = strconv.FormatBool(*c.TeamSettings.EnableOpenServer)
props["RestrictTeamNames"] = strconv.FormatBool(*c.TeamSettings.RestrictTeamNames)
props["RestrictDirectMessage"] = *c.TeamSettings.RestrictDirectMessage
props["RestrictTeamInvite"] = *c.TeamSettings.RestrictTeamInvite
props["RestrictPublicChannelManagement"] = *c.TeamSettings.RestrictPublicChannelManagement
Expand Down
1 change: 0 additions & 1 deletion utils/diagnostic.go
Expand Up @@ -87,7 +87,6 @@ func trackConfig() {
SendDiagnostic(TRACK_CONFIG_TEAM, map[string]interface{}{
"enable_user_creation": Cfg.TeamSettings.EnableUserCreation,
"enable_team_creation": Cfg.TeamSettings.EnableTeamCreation,
"restrict_team_names": *Cfg.TeamSettings.RestrictTeamNames,
"restrict_team_invite": *Cfg.TeamSettings.RestrictTeamInvite,
"restrict_public_channel_management": *Cfg.TeamSettings.RestrictPublicChannelManagement,
"restrict_private_channel_management": *Cfg.TeamSettings.RestrictPrivateChannelManagement,
Expand Down
19 changes: 0 additions & 19 deletions webapp/components/admin_console/users_and_teams_settings.jsx
Expand Up @@ -30,7 +30,6 @@ export default class UsersAndTeamsSettings extends AdminSettings {
config.TeamSettings.EnableTeamCreation = this.state.enableTeamCreation;
config.TeamSettings.MaxUsersPerTeam = this.parseIntNonZero(this.state.maxUsersPerTeam, Constants.DEFAULT_MAX_USERS_PER_TEAM);
config.TeamSettings.RestrictCreationToDomains = this.state.restrictCreationToDomains;
config.TeamSettings.RestrictTeamNames = this.state.restrictTeamNames;
config.TeamSettings.RestrictDirectMessage = this.state.restrictDirectMessage;
config.TeamSettings.MaxChannelsPerTeam = this.parseIntNonZero(this.state.maxChannelsPerTeam, Constants.DEFAULT_MAX_CHANNELS_PER_TEAM);

Expand All @@ -43,7 +42,6 @@ export default class UsersAndTeamsSettings extends AdminSettings {
enableTeamCreation: config.TeamSettings.EnableTeamCreation,
maxUsersPerTeam: config.TeamSettings.MaxUsersPerTeam,
restrictCreationToDomains: config.TeamSettings.RestrictCreationToDomains,
restrictTeamNames: config.TeamSettings.RestrictTeamNames,
restrictDirectMessage: config.TeamSettings.RestrictDirectMessage,
maxChannelsPerTeam: config.TeamSettings.MaxChannelsPerTeam
};
Expand Down Expand Up @@ -151,23 +149,6 @@ export default class UsersAndTeamsSettings extends AdminSettings {
value={this.state.restrictCreationToDomains}
onChange={this.handleChange}
/>
<BooleanSetting
id='restrictTeamNames'
label={
<FormattedMessage
id='admin.team.restrictNameTitle'
defaultMessage='Restrict Team Names: '
/>
}
helpText={
<FormattedMessage
id='admin.team.restrictNameDesc'
defaultMessage='When true, You cannot create a team name with reserved words like www, admin, support, test, channel, etc'
/>
}
value={this.state.restrictTeamNames}
onChange={this.handleChange}
/>
<DropdownSetting
id='restrictDirectMessage'
values={[
Expand Down
10 changes: 4 additions & 6 deletions webapp/components/create_team/components/team_url.jsx
Expand Up @@ -54,12 +54,10 @@ export default class TeamUrl extends React.Component {
return;
}

if (global.window.mm_config.RestrictTeamNames === 'true') {
for (let index = 0; index < Constants.RESERVED_TEAM_NAMES.length; index++) {
if (cleanedName.indexOf(Constants.RESERVED_TEAM_NAMES[index]) === 0) {
this.setState({nameError: Utils.localizeMessage('create_team.team_url.taken', 'URL is taken or contains a reserved word')});
return;
}
for (let index = 0; index < Constants.RESERVED_TEAM_NAMES.length; index++) {
if (cleanedName.indexOf(Constants.RESERVED_TEAM_NAMES[index]) === 0) {
this.setState({nameError: Utils.localizeMessage('create_team.team_url.taken', 'URL is taken or contains a reserved word')});
return;
}
}

Expand Down
18 changes: 4 additions & 14 deletions webapp/utils/constants.jsx
Expand Up @@ -331,23 +331,13 @@ export const Constants = {
SYSTEM_MESSAGE_PROFILE_NAME: 'System',
SYSTEM_MESSAGE_PROFILE_IMAGE: logoImage,
RESERVED_TEAM_NAMES: [
'www',
'web',
'signup',
'login',
'admin',
'support',
'notify',
'test',
'demo',
'mail',
'team',
'channel',
'internal',
'localhost',
'dockerhost',
'stag',
'post',
'cluster',
'api'
'api',
'oauth'
],
RESERVED_USERNAMES: [
'valet',
Expand Down

0 comments on commit 486d12e

Please sign in to comment.