PLT-4165 removing team name reserved words (#4289)
Этот коммит содержится в:
@@ -122,7 +122,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
teamSignup.Team.PreSave()
|
teamSignup.Team.PreSave()
|
||||||
|
|
||||||
if err := teamSignup.Team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); err != nil {
|
if err := teamSignup.Team.IsValid(); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@
|
|||||||
"EnableUserCreation": true,
|
"EnableUserCreation": true,
|
||||||
"EnableOpenServer": false,
|
"EnableOpenServer": false,
|
||||||
"RestrictCreationToDomains": "",
|
"RestrictCreationToDomains": "",
|
||||||
"RestrictTeamNames": true,
|
|
||||||
"EnableCustomBrand": false,
|
"EnableCustomBrand": false,
|
||||||
"CustomBrandText": "",
|
"CustomBrandText": "",
|
||||||
"CustomDescriptionText": "",
|
"CustomDescriptionText": "",
|
||||||
|
|||||||
@@ -214,7 +214,6 @@ type TeamSettings struct {
|
|||||||
EnableUserCreation bool
|
EnableUserCreation bool
|
||||||
EnableOpenServer *bool
|
EnableOpenServer *bool
|
||||||
RestrictCreationToDomains string
|
RestrictCreationToDomains string
|
||||||
RestrictTeamNames *bool
|
|
||||||
EnableCustomBrand *bool
|
EnableCustomBrand *bool
|
||||||
CustomBrandText *string
|
CustomBrandText *string
|
||||||
CustomDescriptionText *string
|
CustomDescriptionText *string
|
||||||
@@ -453,11 +452,6 @@ func (o *Config) SetDefaults() {
|
|||||||
*o.PasswordSettings.Symbol = false
|
*o.PasswordSettings.Symbol = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.TeamSettings.RestrictTeamNames == nil {
|
|
||||||
o.TeamSettings.RestrictTeamNames = new(bool)
|
|
||||||
*o.TeamSettings.RestrictTeamNames = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if o.TeamSettings.EnableCustomBrand == nil {
|
if o.TeamSettings.EnableCustomBrand == nil {
|
||||||
o.TeamSettings.EnableCustomBrand = new(bool)
|
o.TeamSettings.EnableCustomBrand = new(bool)
|
||||||
*o.TeamSettings.EnableCustomBrand = false
|
*o.TeamSettings.EnableCustomBrand = false
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ func (o *Team) Etag() string {
|
|||||||
return Etag(o.Id, o.UpdateAt)
|
return Etag(o.Id, o.UpdateAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Team) IsValid(restrictTeamNames bool) *AppError {
|
func (o *Team) IsValid() *AppError {
|
||||||
|
|
||||||
if len(o.Id) != 26 {
|
if len(o.Id) != 26 {
|
||||||
return NewLocAppError("Team.IsValid", "model.team.is_valid.id.app_error", nil, "")
|
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)
|
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)
|
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) {
|
func TestTeamIsValid(t *testing.T) {
|
||||||
o := Team{}
|
o := Team{}
|
||||||
|
|
||||||
if err := o.IsValid(true); err == nil {
|
if err := o.IsValid(); err == nil {
|
||||||
t.Fatal("should be invalid")
|
t.Fatal("should be invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Id = NewId()
|
o.Id = NewId()
|
||||||
if err := o.IsValid(true); err == nil {
|
if err := o.IsValid(); err == nil {
|
||||||
t.Fatal("should be invalid")
|
t.Fatal("should be invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
o.CreateAt = GetMillis()
|
o.CreateAt = GetMillis()
|
||||||
if err := o.IsValid(true); err == nil {
|
if err := o.IsValid(); err == nil {
|
||||||
t.Fatal("should be invalid")
|
t.Fatal("should be invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
o.UpdateAt = GetMillis()
|
o.UpdateAt = GetMillis()
|
||||||
if err := o.IsValid(true); err == nil {
|
if err := o.IsValid(); err == nil {
|
||||||
t.Fatal("should be invalid")
|
t.Fatal("should be invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Email = strings.Repeat("01234567890", 20)
|
o.Email = strings.Repeat("01234567890", 20)
|
||||||
if err := o.IsValid(true); err == nil {
|
if err := o.IsValid(); err == nil {
|
||||||
t.Fatal("should be invalid")
|
t.Fatal("should be invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Email = "corey+test@hulen.com"
|
o.Email = "corey+test@hulen.com"
|
||||||
o.DisplayName = strings.Repeat("01234567890", 20)
|
o.DisplayName = strings.Repeat("01234567890", 20)
|
||||||
if err := o.IsValid(true); err == nil {
|
if err := o.IsValid(); err == nil {
|
||||||
t.Fatal("should be invalid")
|
t.Fatal("should be invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
o.DisplayName = "1234"
|
o.DisplayName = "1234"
|
||||||
o.Name = "ZZZZZZZ"
|
o.Name = "ZZZZZZZ"
|
||||||
if err := o.IsValid(true); err == nil {
|
if err := o.IsValid(); err == nil {
|
||||||
t.Fatal("should be invalid")
|
t.Fatal("should be invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Name = "zzzzz"
|
o.Name = "zzzzz"
|
||||||
o.Type = TEAM_OPEN
|
o.Type = TEAM_OPEN
|
||||||
if err := o.IsValid(true); err != nil {
|
if err := o.IsValid(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,8 +104,6 @@ var tReservedDomains = []struct {
|
|||||||
value string
|
value string
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
{"test-hello", true},
|
|
||||||
{"test", true},
|
|
||||||
{"admin", true},
|
{"admin", true},
|
||||||
{"Admin-punch", true},
|
{"Admin-punch", true},
|
||||||
{"spin-punch-admin", false},
|
{"spin-punch-admin", false},
|
||||||
@@ -120,15 +118,14 @@ func TestReservedTeamName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCleanTeamName(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")
|
t.Fatal("didn't clean name properly")
|
||||||
}
|
}
|
||||||
if len(CleanTeamName("Test")) != 26 {
|
|
||||||
t.Fatal("didn't clean name properly")
|
if CleanTeamName("Admin Really cool") != "really-cool" {
|
||||||
}
|
|
||||||
if CleanTeamName("Team Really cool") != "really-cool" {
|
|
||||||
t.Fatal("didn't clean name properly")
|
t.Fatal("didn't clean name properly")
|
||||||
}
|
}
|
||||||
|
|
||||||
if CleanTeamName("super-duper-guys") != "super-duper-guys" {
|
if CleanTeamName("super-duper-guys") != "super-duper-guys" {
|
||||||
t.Fatal("didn't clean name properly")
|
t.Fatal("didn't clean name properly")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,58 +253,15 @@ func IsValidEmail(email string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var reservedName = []string{
|
var reservedName = []string{
|
||||||
"www",
|
"signup",
|
||||||
"web",
|
"login",
|
||||||
"admin",
|
"admin",
|
||||||
"support",
|
|
||||||
"notify",
|
|
||||||
"test",
|
|
||||||
"demo",
|
|
||||||
"mail",
|
|
||||||
"team",
|
|
||||||
"channel",
|
"channel",
|
||||||
"internal",
|
|
||||||
"localhost",
|
|
||||||
"dockerhost",
|
|
||||||
"stag",
|
|
||||||
"post",
|
"post",
|
||||||
"cluster",
|
|
||||||
"api",
|
"api",
|
||||||
"oauth",
|
"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 {
|
func IsValidChannelIdentifier(s string) bool {
|
||||||
|
|
||||||
if !IsValidAlphaNum(s, true) {
|
if !IsValidAlphaNum(s, true) {
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func (s SqlTeamStore) Save(team *model.Team) StoreChannel {
|
|||||||
|
|
||||||
team.PreSave()
|
team.PreSave()
|
||||||
|
|
||||||
if result.Err = team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); result.Err != nil {
|
if result.Err = team.IsValid(); result.Err != nil {
|
||||||
storeChannel <- result
|
storeChannel <- result
|
||||||
close(storeChannel)
|
close(storeChannel)
|
||||||
return
|
return
|
||||||
@@ -97,7 +97,7 @@ func (s SqlTeamStore) Update(team *model.Team) StoreChannel {
|
|||||||
|
|
||||||
team.PreUpdate()
|
team.PreUpdate()
|
||||||
|
|
||||||
if result.Err = team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); result.Err != nil {
|
if result.Err = team.IsValid(); result.Err != nil {
|
||||||
storeChannel <- result
|
storeChannel <- result
|
||||||
close(storeChannel)
|
close(storeChannel)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -236,7 +236,6 @@ func getClientConfig(c *model.Config) map[string]string {
|
|||||||
props["EnableTeamCreation"] = strconv.FormatBool(c.TeamSettings.EnableTeamCreation)
|
props["EnableTeamCreation"] = strconv.FormatBool(c.TeamSettings.EnableTeamCreation)
|
||||||
props["EnableUserCreation"] = strconv.FormatBool(c.TeamSettings.EnableUserCreation)
|
props["EnableUserCreation"] = strconv.FormatBool(c.TeamSettings.EnableUserCreation)
|
||||||
props["EnableOpenServer"] = strconv.FormatBool(*c.TeamSettings.EnableOpenServer)
|
props["EnableOpenServer"] = strconv.FormatBool(*c.TeamSettings.EnableOpenServer)
|
||||||
props["RestrictTeamNames"] = strconv.FormatBool(*c.TeamSettings.RestrictTeamNames)
|
|
||||||
props["RestrictDirectMessage"] = *c.TeamSettings.RestrictDirectMessage
|
props["RestrictDirectMessage"] = *c.TeamSettings.RestrictDirectMessage
|
||||||
props["RestrictTeamInvite"] = *c.TeamSettings.RestrictTeamInvite
|
props["RestrictTeamInvite"] = *c.TeamSettings.RestrictTeamInvite
|
||||||
props["RestrictPublicChannelManagement"] = *c.TeamSettings.RestrictPublicChannelManagement
|
props["RestrictPublicChannelManagement"] = *c.TeamSettings.RestrictPublicChannelManagement
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ func trackConfig() {
|
|||||||
SendDiagnostic(TRACK_CONFIG_TEAM, map[string]interface{}{
|
SendDiagnostic(TRACK_CONFIG_TEAM, map[string]interface{}{
|
||||||
"enable_user_creation": Cfg.TeamSettings.EnableUserCreation,
|
"enable_user_creation": Cfg.TeamSettings.EnableUserCreation,
|
||||||
"enable_team_creation": Cfg.TeamSettings.EnableTeamCreation,
|
"enable_team_creation": Cfg.TeamSettings.EnableTeamCreation,
|
||||||
"restrict_team_names": *Cfg.TeamSettings.RestrictTeamNames,
|
|
||||||
"restrict_team_invite": *Cfg.TeamSettings.RestrictTeamInvite,
|
"restrict_team_invite": *Cfg.TeamSettings.RestrictTeamInvite,
|
||||||
"restrict_public_channel_management": *Cfg.TeamSettings.RestrictPublicChannelManagement,
|
"restrict_public_channel_management": *Cfg.TeamSettings.RestrictPublicChannelManagement,
|
||||||
"restrict_private_channel_management": *Cfg.TeamSettings.RestrictPrivateChannelManagement,
|
"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.EnableTeamCreation = this.state.enableTeamCreation;
|
||||||
config.TeamSettings.MaxUsersPerTeam = this.parseIntNonZero(this.state.maxUsersPerTeam, Constants.DEFAULT_MAX_USERS_PER_TEAM);
|
config.TeamSettings.MaxUsersPerTeam = this.parseIntNonZero(this.state.maxUsersPerTeam, Constants.DEFAULT_MAX_USERS_PER_TEAM);
|
||||||
config.TeamSettings.RestrictCreationToDomains = this.state.restrictCreationToDomains;
|
config.TeamSettings.RestrictCreationToDomains = this.state.restrictCreationToDomains;
|
||||||
config.TeamSettings.RestrictTeamNames = this.state.restrictTeamNames;
|
|
||||||
config.TeamSettings.RestrictDirectMessage = this.state.restrictDirectMessage;
|
config.TeamSettings.RestrictDirectMessage = this.state.restrictDirectMessage;
|
||||||
config.TeamSettings.MaxChannelsPerTeam = this.parseIntNonZero(this.state.maxChannelsPerTeam, Constants.DEFAULT_MAX_CHANNELS_PER_TEAM);
|
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,
|
enableTeamCreation: config.TeamSettings.EnableTeamCreation,
|
||||||
maxUsersPerTeam: config.TeamSettings.MaxUsersPerTeam,
|
maxUsersPerTeam: config.TeamSettings.MaxUsersPerTeam,
|
||||||
restrictCreationToDomains: config.TeamSettings.RestrictCreationToDomains,
|
restrictCreationToDomains: config.TeamSettings.RestrictCreationToDomains,
|
||||||
restrictTeamNames: config.TeamSettings.RestrictTeamNames,
|
|
||||||
restrictDirectMessage: config.TeamSettings.RestrictDirectMessage,
|
restrictDirectMessage: config.TeamSettings.RestrictDirectMessage,
|
||||||
maxChannelsPerTeam: config.TeamSettings.MaxChannelsPerTeam
|
maxChannelsPerTeam: config.TeamSettings.MaxChannelsPerTeam
|
||||||
};
|
};
|
||||||
@@ -151,23 +149,6 @@ export default class UsersAndTeamsSettings extends AdminSettings {
|
|||||||
value={this.state.restrictCreationToDomains}
|
value={this.state.restrictCreationToDomains}
|
||||||
onChange={this.handleChange}
|
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
|
<DropdownSetting
|
||||||
id='restrictDirectMessage'
|
id='restrictDirectMessage'
|
||||||
values={[
|
values={[
|
||||||
|
|||||||
@@ -54,12 +54,10 @@ export default class TeamUrl extends React.Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.window.mm_config.RestrictTeamNames === 'true') {
|
for (let index = 0; index < Constants.RESERVED_TEAM_NAMES.length; index++) {
|
||||||
for (let index = 0; index < Constants.RESERVED_TEAM_NAMES.length; index++) {
|
if (cleanedName.indexOf(Constants.RESERVED_TEAM_NAMES[index]) === 0) {
|
||||||
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')});
|
||||||
this.setState({nameError: Utils.localizeMessage('create_team.team_url.taken', 'URL is taken or contains a reserved word')});
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -331,23 +331,13 @@ export const Constants = {
|
|||||||
SYSTEM_MESSAGE_PROFILE_NAME: 'System',
|
SYSTEM_MESSAGE_PROFILE_NAME: 'System',
|
||||||
SYSTEM_MESSAGE_PROFILE_IMAGE: logoImage,
|
SYSTEM_MESSAGE_PROFILE_IMAGE: logoImage,
|
||||||
RESERVED_TEAM_NAMES: [
|
RESERVED_TEAM_NAMES: [
|
||||||
'www',
|
'signup',
|
||||||
'web',
|
'login',
|
||||||
'admin',
|
'admin',
|
||||||
'support',
|
|
||||||
'notify',
|
|
||||||
'test',
|
|
||||||
'demo',
|
|
||||||
'mail',
|
|
||||||
'team',
|
|
||||||
'channel',
|
'channel',
|
||||||
'internal',
|
|
||||||
'localhost',
|
|
||||||
'dockerhost',
|
|
||||||
'stag',
|
|
||||||
'post',
|
'post',
|
||||||
'cluster',
|
'api',
|
||||||
'api'
|
'oauth'
|
||||||
],
|
],
|
||||||
RESERVED_USERNAMES: [
|
RESERVED_USERNAMES: [
|
||||||
'valet',
|
'valet',
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user