summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-10-20 17:30:24 -0700
committer=Corey Hulen <corey@hulen.com>2015-10-20 17:30:24 -0700
commitb9ce4a644d8e97ed05acb79033ea2f5043494ee4 (patch)
tree18856536744f9eb93a779997a006973c0ae6c2b7
parent7ea8268ae88ecd3b94c0bf9bafbc169c50df4595 (diff)
downloadchat-b9ce4a644d8e97ed05acb79033ea2f5043494ee4.tar.gz
chat-b9ce4a644d8e97ed05acb79033ea2f5043494ee4.tar.bz2
chat-b9ce4a644d8e97ed05acb79033ea2f5043494ee4.zip
PLT-350 allow ability to disable restricted team names
-rw-r--r--api/team.go9
-rw-r--r--config/config.json3
-rw-r--r--model/config.go6
-rw-r--r--model/team.go4
-rw-r--r--store/sql_team_store.go5
-rw-r--r--utils/config.go1
-rw-r--r--web/react/components/admin_console/team_settings.jsx34
-rw-r--r--web/react/components/team_signup_url_page.jsx10
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))) {
@@ -209,6 +210,39 @@ export default class TeamSettings extends React.Component {
</div>
<div className='form-group'>
+ <label
+ className='control-label col-sm-4'
+ htmlFor='RestrictTeamNames'
+ >
+ {'Restrict Team Names: '}
+ </label>
+ <div className='col-sm-8'>
+ <label className='radio-inline'>
+ <input
+ type='radio'
+ name='RestrictTeamNames'
+ value='true'
+ ref='RestrictTeamNames'
+ defaultChecked={this.props.config.TeamSettings.RestrictTeamNames}
+ onChange={this.handleChange}
+ />
+ {'true'}
+ </label>
+ <label className='radio-inline'>
+ <input
+ type='radio'
+ name='RestrictTeamNames'
+ value='false'
+ defaultChecked={!this.props.config.TeamSettings.RestrictTeamNames}
+ onChange={this.handleChange}
+ />
+ {'false'}
+ </label>
+ <p className='help-text'>{'When true, You cannot create a team name with reserved words like www, admin, support, test, channel, etc'}</p>
+ </div>
+ </div>
+
+ <div className='form-group'>
<div className='col-sm-12'>
{serverError}
<button
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;
+ }
}
}