Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4997691

Browse files
authored
fix: increase group name limit to 36 from 32 (#14443)
1 parent88d7181 commit4997691

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

‎coderd/httpapi/httpapi.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func init() {
4646
valid:=NameValid(str)
4747
returnvalid==nil
4848
}
49-
for_,tag:=range []string{"username","organization_name","template_name","group_name","workspace_name","oauth2_app_name"} {
49+
for_,tag:=range []string{"username","organization_name","template_name","workspace_name","oauth2_app_name"} {
5050
err:=Validate.RegisterValidation(tag,nameValidator)
5151
iferr!=nil {
5252
panic(err)
@@ -96,6 +96,20 @@ func init() {
9696
iferr!=nil {
9797
panic(err)
9898
}
99+
100+
groupNameValidator:=func(fl validator.FieldLevel)bool {
101+
f:=fl.Field().Interface()
102+
str,ok:=f.(string)
103+
if!ok {
104+
returnfalse
105+
}
106+
valid:=GroupNameValid(str)
107+
returnvalid==nil
108+
}
109+
err=Validate.RegisterValidation("group_name",groupNameValidator)
110+
iferr!=nil {
111+
panic(err)
112+
}
99113
}
100114

101115
// Is404Error returns true if the given error should return a 404 status code.

‎coderd/httpapi/name.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ func UserRealNameValid(str string) error {
9696
returnnil
9797
}
9898

99+
// GroupNameValid returns whether the input string is a valid group name.
100+
funcGroupNameValid(strstring)error {
101+
// 36 is to support using UUIDs as the group name.
102+
iflen(str)>36 {
103+
returnxerrors.New("must be <= 36 characters")
104+
}
105+
// Avoid conflicts with routes like /groups/new and /groups/create.
106+
ifstr=="new"||str=="create" {
107+
returnxerrors.Errorf("cannot use %q as a name",str)
108+
}
109+
matched:=UsernameValidRegex.MatchString(str)
110+
if!matched {
111+
returnxerrors.New("must be alphanumeric with hyphens")
112+
}
113+
returnnil
114+
}
115+
99116
// NormalizeUserRealName normalizes a user name such that it will pass
100117
// validation by UserRealNameValid. This is done to avoid blocking
101118
// little Bobby Whitespace from using Coder.

‎enterprise/coderd/groups_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestPatchGroup(t *testing.T) {
159159
constdisplayName="foobar"
160160
ctx:=testutil.Context(t,testutil.WaitLong)
161161
group,err:=userAdminClient.CreateGroup(ctx,user.OrganizationID, codersdk.CreateGroupRequest{
162-
Name:"hi",
162+
Name:"ff7dcee2-e7c4-4bc4-a9e4-84870770e4c5",// GUID should fit.
163163
AvatarURL:"https://example.com",
164164
QuotaAllowance:10,
165165
DisplayName:"",
@@ -168,14 +168,14 @@ func TestPatchGroup(t *testing.T) {
168168
require.Equal(t,10,group.QuotaAllowance)
169169

170170
group,err=userAdminClient.PatchGroup(ctx,group.ID, codersdk.PatchGroupRequest{
171-
Name:"bye",
171+
Name:"ddd502d2-2984-4724-b5bf-1109a4d7462d",// GUID should fit.
172172
AvatarURL:ptr.Ref("https://google.com"),
173173
QuotaAllowance:ptr.Ref(20),
174174
DisplayName:ptr.Ref(displayName),
175175
})
176176
require.NoError(t,err)
177177
require.Equal(t,displayName,group.DisplayName)
178-
require.Equal(t,"bye",group.Name)
178+
require.Equal(t,"ddd502d2-2984-4724-b5bf-1109a4d7462d",group.Name)
179179
require.Equal(t,"https://google.com",group.AvatarURL)
180180
require.Equal(t,20,group.QuotaAllowance)
181181
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp