mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
PLT-4165 removing team name reserved words (#4289)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
"EnableUserCreation": true,
|
||||
"EnableOpenServer": false,
|
||||
"RestrictCreationToDomains": "",
|
||||
"RestrictTeamNames": true,
|
||||
"EnableCustomBrand": false,
|
||||
"CustomBrandText": "",
|
||||
"CustomDescriptionText": "",
|
||||
|
||||
@@ -214,7 +214,6 @@ type TeamSettings struct {
|
||||
EnableUserCreation bool
|
||||
EnableOpenServer *bool
|
||||
RestrictCreationToDomains string
|
||||
RestrictTeamNames *bool
|
||||
EnableCustomBrand *bool
|
||||
CustomBrandText *string
|
||||
CustomDescriptionText *string
|
||||
@@ -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
|
||||
|
||||
@@ -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, "")
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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},
|
||||
@@ -120,15 +118,14 @@ func TestReservedTeamName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCleanTeamName(t *testing.T) {
|
||||
if CleanTeamName("Jimbo's Team") != "jimbos-team" {
|
||||
if CleanTeamName("Jimbo's Admin") != "jimbos-admin" {
|
||||
t.Fatal("didn't clean name properly")
|
||||
}
|
||||
if len(CleanTeamName("Test")) != 26 {
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
};
|
||||
@@ -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={[
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user