mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: increase group name limit to 36 from 32 (#14443)
This commit is contained in:
@@ -46,7 +46,7 @@ func init() {
|
||||
valid := NameValid(str)
|
||||
return valid == nil
|
||||
}
|
||||
for _, tag := range []string{"username", "organization_name", "template_name", "group_name", "workspace_name", "oauth2_app_name"} {
|
||||
for _, tag := range []string{"username", "organization_name", "template_name", "workspace_name", "oauth2_app_name"} {
|
||||
err := Validate.RegisterValidation(tag, nameValidator)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -96,6 +96,20 @@ func init() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
groupNameValidator := func(fl validator.FieldLevel) bool {
|
||||
f := fl.Field().Interface()
|
||||
str, ok := f.(string)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
valid := GroupNameValid(str)
|
||||
return valid == nil
|
||||
}
|
||||
err = Validate.RegisterValidation("group_name", groupNameValidator)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Is404Error returns true if the given error should return a 404 status code.
|
||||
|
||||
@@ -96,6 +96,23 @@ func UserRealNameValid(str string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupNameValid returns whether the input string is a valid group name.
|
||||
func GroupNameValid(str string) error {
|
||||
// 36 is to support using UUIDs as the group name.
|
||||
if len(str) > 36 {
|
||||
return xerrors.New("must be <= 36 characters")
|
||||
}
|
||||
// Avoid conflicts with routes like /groups/new and /groups/create.
|
||||
if str == "new" || str == "create" {
|
||||
return xerrors.Errorf("cannot use %q as a name", str)
|
||||
}
|
||||
matched := UsernameValidRegex.MatchString(str)
|
||||
if !matched {
|
||||
return xerrors.New("must be alphanumeric with hyphens")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NormalizeUserRealName normalizes a user name such that it will pass
|
||||
// validation by UserRealNameValid. This is done to avoid blocking
|
||||
// little Bobby Whitespace from using Coder.
|
||||
|
||||
Reference in New Issue
Block a user