Skip to content

Commit c5f8ccb

Browse files
committed
make display name optional to avoid breakage
1 parent 78c19b7 commit c5f8ccb

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

coderd/organizations.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ func (api *API) postOrganizations(rw http.ResponseWriter, r *http.Request) {
7474

7575
var organization database.Organization
7676
err = api.Database.InTx(func(tx database.Store) error {
77+
if req.DisplayName == "" {
78+
req.DisplayName = req.Name
79+
}
80+
7781
organization, err = tx.InsertOrganization(ctx, database.InsertOrganizationParams{
7882
ID: uuid.New(),
7983
Name: req.Name,

coderd/organizations_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ func TestPostOrganizationsByUser(t *testing.T) {
148148
require.Equal(t, "New", o.DisplayName)
149149
require.Equal(t, "A new organization to love and cherish forever.", o.Description)
150150
})
151+
152+
t.Run("CreateWithoutExplicitDisplayName", func(t *testing.T) {
153+
t.Parallel()
154+
client := coderdtest.New(t, nil)
155+
_ = coderdtest.CreateFirstUser(t, client)
156+
ctx := testutil.Context(t, testutil.WaitLong)
157+
158+
o, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
159+
Name: "new",
160+
})
161+
require.NoError(t, err)
162+
require.Equal(t, "new", o.Name)
163+
require.Equal(t, "new", o.DisplayName) // should match the given `Name`
164+
})
151165
}
152166

153167
func TestPatchOrganizationsByUser(t *testing.T) {

codersdk/organizations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type OrganizationMember struct {
5959

6060
type CreateOrganizationRequest struct {
6161
Name string `json:"name" validate:"required,organization_name"`
62-
DisplayName string `json:"display_name" validate:"required,organization_display_name"`
62+
DisplayName string `json:"display_name" validate:"omitempty,organization_display_name"`
6363
Description string `json:"description,omitempty"`
6464
}
6565

0 commit comments

Comments
 (0)