[MM-42400] Prevent making groups with reserved names (#21040)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9da1f1ce43
Коммит
aee1600d49
@@ -154,6 +154,16 @@ func TestCreateGroup(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, response)
|
||||
|
||||
reservedNameGroup := &model.Group{
|
||||
DisplayName: "dn_" + model.NewId(),
|
||||
Name: model.NewString("here"),
|
||||
Source: model.GroupSourceCustom,
|
||||
AllowReference: true,
|
||||
}
|
||||
_, response, err = th.SystemAdminClient.CreateGroup(reservedNameGroup)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, response)
|
||||
|
||||
th.SystemAdminClient.Logout()
|
||||
_, response, err = th.SystemAdminClient.CreateGroup(g)
|
||||
require.Error(t, err)
|
||||
@@ -294,6 +304,12 @@ func TestPatchGroup(t *testing.T) {
|
||||
CheckOKStatus(t, response)
|
||||
require.Equal(t, true, patchedG2.AllowReference)
|
||||
|
||||
_, response, err = th.SystemAdminClient.PatchGroup(g2.Id, &model.GroupPatch{
|
||||
Name: model.NewString("here"),
|
||||
})
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, response)
|
||||
|
||||
th.SystemAdminClient.Logout()
|
||||
_, response, err = th.SystemAdminClient.PatchGroup(group.Id, gp)
|
||||
require.Error(t, err)
|
||||
|
||||
@@ -8643,6 +8643,10 @@
|
||||
"id": "model.group.name.invalid_length.app_error",
|
||||
"translation": "Name must be 1 to 64 lowercase alphanumeric characters."
|
||||
},
|
||||
{
|
||||
"id": "model.group.name.reserved_name.app_error",
|
||||
"translation": "group name already exists as a reserved name"
|
||||
},
|
||||
{
|
||||
"id": "model.group.remote_id.app_error",
|
||||
"translation": "invalid remote id property for group."
|
||||
|
||||
@@ -218,6 +218,10 @@ func (group *Group) IsValidName() *AppError {
|
||||
return NewAppError("Group.IsValidName", "model.group.name.invalid_length.app_error", map[string]any{"GroupNameMaxLength": GroupNameMaxLength}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if *group.Name == UserNotifyAll || *group.Name == ChannelMentionsNotifyProp || *group.Name == UserNotifyHere {
|
||||
return NewAppError("IsValidName", "model.group.name.reserved_name.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !validGroupnameChars.MatchString(*group.Name) {
|
||||
return NewAppError("Group.IsValidName", "model.group.name.invalid_chars.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user