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

Commit8ff73c2

Browse files
code-asherstirby
authored andcommitted
fix: increase group name limit to 36 from 32 (#14443)
(cherry picked from commit4997691)
1 parentd1cd784 commit8ff73c2

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
@@ -156,7 +156,7 @@ func TestPatchGroup(t *testing.T) {
156156
constdisplayName="foobar"
157157
ctx:=testutil.Context(t,testutil.WaitLong)
158158
group,err:=userAdminClient.CreateGroup(ctx,user.OrganizationID, codersdk.CreateGroupRequest{
159-
Name:"hi",
159+
Name:"ff7dcee2-e7c4-4bc4-a9e4-84870770e4c5",// GUID should fit.
160160
AvatarURL:"https://example.com",
161161
QuotaAllowance:10,
162162
DisplayName:"",
@@ -165,14 +165,14 @@ func TestPatchGroup(t *testing.T) {
165165
require.Equal(t,10,group.QuotaAllowance)
166166

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp