From b9ce4a644d8e97ed05acb79033ea2f5043494ee4 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Tue, 20 Oct 2015 17:30:24 -0700 Subject: PLT-350 allow ability to disable restricted team names --- api/team.go | 9 ++---- config/config.json | 3 +- model/config.go | 6 ++++ model/team.go | 4 +-- store/sql_team_store.go | 5 ++-- utils/config.go | 1 + .../components/admin_console/team_settings.jsx | 34 ++++++++++++++++++++++ web/react/components/team_signup_url_page.jsx | 10 ++++--- 8 files changed, 56 insertions(+), 16 deletions(-) diff --git a/api/team.go b/api/team.go index f6038566a..2d7b05ff6 100644 --- a/api/team.go +++ b/api/team.go @@ -108,7 +108,7 @@ func createTeamFromSSO(c *Context, w http.ResponseWriter, r *http.Request) { team.Name = model.CleanTeamName(team.Name) - if err := team.IsValid(); err != nil { + if err := team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); err != nil { c.Err = err return } @@ -164,7 +164,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) { teamSignup.Team.PreSave() - if err := teamSignup.Team.IsValid(); err != nil { + if err := teamSignup.Team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); err != nil { c.Err = err return } @@ -379,11 +379,6 @@ func FindTeamByName(c *Context, name string, all string) bool { return false } - if model.IsReservedTeamName(name) { - c.Err = model.NewAppError("findTeamByName", "This URL is unavailable. Please try another.", "name="+name) - return false - } - if result := <-Srv.Store.Team().GetByName(name); result.Err != nil { return false } else { diff --git a/config/config.json b/config/config.json index 37109428d..7bac58df7 100644 --- a/config/config.json +++ b/config/config.json @@ -17,7 +17,8 @@ "MaxUsersPerTeam": 50, "EnableTeamCreation": true, "EnableUserCreation": true, - "RestrictCreationToDomains": "" + "RestrictCreationToDomains": "", + "RestrictTeamNames": true }, "SqlSettings": { "DriverName": "mysql", diff --git a/model/config.go b/model/config.go index 3a39df2f1..216b1de86 100644 --- a/model/config.go +++ b/model/config.go @@ -122,6 +122,7 @@ type TeamSettings struct { EnableTeamCreation bool EnableUserCreation bool RestrictCreationToDomains string + RestrictTeamNames *bool } type Config struct { @@ -169,6 +170,11 @@ func (o *Config) SetDefaults() { o.ServiceSettings.EnableSecurityFixAlert = new(bool) *o.ServiceSettings.EnableSecurityFixAlert = true } + + if o.TeamSettings.RestrictTeamNames == nil { + o.TeamSettings.RestrictTeamNames = new(bool) + *o.TeamSettings.RestrictTeamNames = true + } } func (o *Config) IsValid() *AppError { diff --git a/model/team.go b/model/team.go index 584c78f8d..9da2cd5b2 100644 --- a/model/team.go +++ b/model/team.go @@ -97,7 +97,7 @@ func (o *Team) Etag() string { return Etag(o.Id, o.UpdateAt) } -func (o *Team) IsValid() *AppError { +func (o *Team) IsValid(restrictTeamNames bool) *AppError { if len(o.Id) != 26 { return NewAppError("Team.IsValid", "Invalid Id", "") @@ -127,7 +127,7 @@ func (o *Team) IsValid() *AppError { return NewAppError("Team.IsValid", "Invalid URL Identifier", "id="+o.Id) } - if IsReservedTeamName(o.Name) { + if restrictTeamNames && IsReservedTeamName(o.Name) { return NewAppError("Team.IsValid", "This URL is unavailable. Please try another.", "id="+o.Id) } diff --git a/store/sql_team_store.go b/store/sql_team_store.go index 2d65435b0..380d979bd 100644 --- a/store/sql_team_store.go +++ b/store/sql_team_store.go @@ -5,6 +5,7 @@ package store import ( "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" ) type SqlTeamStore struct { @@ -52,7 +53,7 @@ func (s SqlTeamStore) Save(team *model.Team) StoreChannel { team.PreSave() - if result.Err = team.IsValid(); result.Err != nil { + if result.Err = team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); result.Err != nil { storeChannel <- result close(storeChannel) return @@ -84,7 +85,7 @@ func (s SqlTeamStore) Update(team *model.Team) StoreChannel { team.PreUpdate() - if result.Err = team.IsValid(); result.Err != nil { + if result.Err = team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); result.Err != nil { storeChannel <- result close(storeChannel) return diff --git a/utils/config.go b/utils/config.go index e3349650b..15d6b217c 100644 --- a/utils/config.go +++ b/utils/config.go @@ -182,6 +182,7 @@ func getClientProperties(c *model.Config) map[string]string { props["SiteName"] = c.TeamSettings.SiteName props["EnableTeamCreation"] = strconv.FormatBool(c.TeamSettings.EnableTeamCreation) + props["RestrictTeamNames"] = strconv.FormatBool(*c.TeamSettings.RestrictTeamNames) props["EnableOAuthServiceProvider"] = strconv.FormatBool(c.ServiceSettings.EnableOAuthServiceProvider) diff --git a/web/react/components/admin_console/team_settings.jsx b/web/react/components/admin_console/team_settings.jsx index da4299714..9ecd14a1e 100644 --- a/web/react/components/admin_console/team_settings.jsx +++ b/web/react/components/admin_console/team_settings.jsx @@ -31,6 +31,7 @@ export default class TeamSettings extends React.Component { config.TeamSettings.RestrictCreationToDomains = ReactDOM.findDOMNode(this.refs.RestrictCreationToDomains).value.trim(); config.TeamSettings.EnableTeamCreation = ReactDOM.findDOMNode(this.refs.EnableTeamCreation).checked; config.TeamSettings.EnableUserCreation = ReactDOM.findDOMNode(this.refs.EnableUserCreation).checked; + config.TeamSettings.RestrictTeamNames = ReactDOM.findDOMNode(this.refs.RestrictTeamNames).checked; var MaxUsersPerTeam = 50; if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.MaxUsersPerTeam).value, 10))) { @@ -208,6 +209,39 @@ export default class TeamSettings extends React.Component { +
+ +
+ + +

{'When true, You cannot create a team name with reserved words like www, admin, support, test, channel, etc'}

+
+
+
{serverError} diff --git a/web/react/components/team_signup_url_page.jsx b/web/react/components/team_signup_url_page.jsx index 67e4c9dd7..75ec2dfd9 100644 --- a/web/react/components/team_signup_url_page.jsx +++ b/web/react/components/team_signup_url_page.jsx @@ -40,10 +40,12 @@ export default class TeamSignupUrlPage extends React.Component { return; } - for (let index = 0; index < Constants.RESERVED_TEAM_NAMES.length; index++) { - if (cleanedName.indexOf(Constants.RESERVED_TEAM_NAMES[index]) === 0) { - this.setState({nameError: 'URL is taken or contains a reserved word'}); - return; + if (global.window.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: 'URL is taken or contains a reserved word'}); + return; + } } } -- cgit v1.2.3-1-g7c22