mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
PLT-350 allow ability to disable restricted team names
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
"MaxUsersPerTeam": 50,
|
||||
"EnableTeamCreation": true,
|
||||
"EnableUserCreation": true,
|
||||
"RestrictCreationToDomains": ""
|
||||
"RestrictCreationToDomains": "",
|
||||
"RestrictTeamNames": true
|
||||
},
|
||||
"SqlSettings": {
|
||||
"DriverName": "mysql",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
</div>
|
||||
</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}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user