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)
|
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
|
c.Err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
teamSignup.Team.PreSave()
|
teamSignup.Team.PreSave()
|
||||||
|
|
||||||
if err := teamSignup.Team.IsValid(); err != nil {
|
if err := teamSignup.Team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -379,11 +379,6 @@ func FindTeamByName(c *Context, name string, all string) bool {
|
|||||||
return false
|
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 {
|
if result := <-Srv.Store.Team().GetByName(name); result.Err != nil {
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
"MaxUsersPerTeam": 50,
|
"MaxUsersPerTeam": 50,
|
||||||
"EnableTeamCreation": true,
|
"EnableTeamCreation": true,
|
||||||
"EnableUserCreation": true,
|
"EnableUserCreation": true,
|
||||||
"RestrictCreationToDomains": ""
|
"RestrictCreationToDomains": "",
|
||||||
|
"RestrictTeamNames": true
|
||||||
},
|
},
|
||||||
"SqlSettings": {
|
"SqlSettings": {
|
||||||
"DriverName": "mysql",
|
"DriverName": "mysql",
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ type TeamSettings struct {
|
|||||||
EnableTeamCreation bool
|
EnableTeamCreation bool
|
||||||
EnableUserCreation bool
|
EnableUserCreation bool
|
||||||
RestrictCreationToDomains string
|
RestrictCreationToDomains string
|
||||||
|
RestrictTeamNames *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -169,6 +170,11 @@ func (o *Config) SetDefaults() {
|
|||||||
o.ServiceSettings.EnableSecurityFixAlert = new(bool)
|
o.ServiceSettings.EnableSecurityFixAlert = new(bool)
|
||||||
*o.ServiceSettings.EnableSecurityFixAlert = true
|
*o.ServiceSettings.EnableSecurityFixAlert = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.TeamSettings.RestrictTeamNames == nil {
|
||||||
|
o.TeamSettings.RestrictTeamNames = new(bool)
|
||||||
|
*o.TeamSettings.RestrictTeamNames = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Config) IsValid() *AppError {
|
func (o *Config) IsValid() *AppError {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func (o *Team) Etag() string {
|
|||||||
return Etag(o.Id, o.UpdateAt)
|
return Etag(o.Id, o.UpdateAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Team) IsValid() *AppError {
|
func (o *Team) IsValid(restrictTeamNames bool) *AppError {
|
||||||
|
|
||||||
if len(o.Id) != 26 {
|
if len(o.Id) != 26 {
|
||||||
return NewAppError("Team.IsValid", "Invalid Id", "")
|
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)
|
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)
|
return NewAppError("Team.IsValid", "This URL is unavailable. Please try another.", "id="+o.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package store
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
|
"github.com/mattermost/platform/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SqlTeamStore struct {
|
type SqlTeamStore struct {
|
||||||
@@ -52,7 +53,7 @@ func (s SqlTeamStore) Save(team *model.Team) StoreChannel {
|
|||||||
|
|
||||||
team.PreSave()
|
team.PreSave()
|
||||||
|
|
||||||
if result.Err = team.IsValid(); result.Err != nil {
|
if result.Err = team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); result.Err != nil {
|
||||||
storeChannel <- result
|
storeChannel <- result
|
||||||
close(storeChannel)
|
close(storeChannel)
|
||||||
return
|
return
|
||||||
@@ -84,7 +85,7 @@ func (s SqlTeamStore) Update(team *model.Team) StoreChannel {
|
|||||||
|
|
||||||
team.PreUpdate()
|
team.PreUpdate()
|
||||||
|
|
||||||
if result.Err = team.IsValid(); result.Err != nil {
|
if result.Err = team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); result.Err != nil {
|
||||||
storeChannel <- result
|
storeChannel <- result
|
||||||
close(storeChannel)
|
close(storeChannel)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ func getClientProperties(c *model.Config) map[string]string {
|
|||||||
|
|
||||||
props["SiteName"] = c.TeamSettings.SiteName
|
props["SiteName"] = c.TeamSettings.SiteName
|
||||||
props["EnableTeamCreation"] = strconv.FormatBool(c.TeamSettings.EnableTeamCreation)
|
props["EnableTeamCreation"] = strconv.FormatBool(c.TeamSettings.EnableTeamCreation)
|
||||||
|
props["RestrictTeamNames"] = strconv.FormatBool(*c.TeamSettings.RestrictTeamNames)
|
||||||
|
|
||||||
props["EnableOAuthServiceProvider"] = strconv.FormatBool(c.ServiceSettings.EnableOAuthServiceProvider)
|
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.RestrictCreationToDomains = ReactDOM.findDOMNode(this.refs.RestrictCreationToDomains).value.trim();
|
||||||
config.TeamSettings.EnableTeamCreation = ReactDOM.findDOMNode(this.refs.EnableTeamCreation).checked;
|
config.TeamSettings.EnableTeamCreation = ReactDOM.findDOMNode(this.refs.EnableTeamCreation).checked;
|
||||||
config.TeamSettings.EnableUserCreation = ReactDOM.findDOMNode(this.refs.EnableUserCreation).checked;
|
config.TeamSettings.EnableUserCreation = ReactDOM.findDOMNode(this.refs.EnableUserCreation).checked;
|
||||||
|
config.TeamSettings.RestrictTeamNames = ReactDOM.findDOMNode(this.refs.RestrictTeamNames).checked;
|
||||||
|
|
||||||
var MaxUsersPerTeam = 50;
|
var MaxUsersPerTeam = 50;
|
||||||
if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.MaxUsersPerTeam).value, 10))) {
|
if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.MaxUsersPerTeam).value, 10))) {
|
||||||
@@ -208,6 +209,39 @@ export default class TeamSettings extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
</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='form-group'>
|
||||||
<div className='col-sm-12'>
|
<div className='col-sm-12'>
|
||||||
{serverError}
|
{serverError}
|
||||||
|
|||||||
@@ -40,10 +40,12 @@ export default class TeamSignupUrlPage extends React.Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let index = 0; index < Constants.RESERVED_TEAM_NAMES.length; index++) {
|
if (global.window.config.RestrictTeamNames === 'true') {
|
||||||
if (cleanedName.indexOf(Constants.RESERVED_TEAM_NAMES[index]) === 0) {
|
for (let index = 0; index < Constants.RESERVED_TEAM_NAMES.length; index++) {
|
||||||
this.setState({nameError: 'URL is taken or contains a reserved word'});
|
if (cleanedName.indexOf(Constants.RESERVED_TEAM_NAMES[index]) === 0) {
|
||||||
return;
|
this.setState({nameError: 'URL is taken or contains a reserved word'});
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user