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

Commitc3a7b13

Browse files
authored
chore: remove organization requirement from convertGroup() (#12195)
* feat: convertGroups() no longer requires organization infoRemoving role information from some users in the api. This info isexcessive and not required. It is costly to always include
1 parent3f65bd1 commitc3a7b13

File tree

25 files changed

+351
-279
lines changed

25 files changed

+351
-279
lines changed

‎cli/clitest/golden.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ func prepareTestData(t *testing.T) (*codersdk.Client, map[string]string) {
167167
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitLong)
168168
defercancel()
169169

170-
db,pubsub:=dbtestutil.NewDB(t)
170+
// This needs to be a fixed timezone because timezones increase the length
171+
// of timestamp strings. The increased length can pad table formatting's
172+
// and differ the table header spacings.
173+
//nolint:gocritic
174+
db,pubsub:=dbtestutil.NewDB(t,dbtestutil.WithTimezone("UTC"))
171175
rootClient:=coderdtest.New(t,&coderdtest.Options{
172176
Database:db,
173177
Pubsub:pubsub,

‎cli/cliui/output.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TableFormat(out any, defaultColumns []string) OutputFormat {
106106
}
107107

108108
// Get the list of table column headers.
109-
headers,defaultSort,err:=typeToTableHeaders(v.Type().Elem())
109+
headers,defaultSort,err:=typeToTableHeaders(v.Type().Elem(),true)
110110
iferr!=nil {
111111
panic("parse table headers: "+err.Error())
112112
}

‎cli/cliui/table.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
7070
}
7171

7272
// Get the list of table column headers.
73-
headersRaw,defaultSort,err:=typeToTableHeaders(v.Type().Elem())
73+
headersRaw,defaultSort,err:=typeToTableHeaders(v.Type().Elem(),true)
7474
iferr!=nil {
7575
return"",xerrors.Errorf("get table headers recursively for type %q: %w",v.Type().Elem().String(),err)
7676
}
@@ -230,7 +230,11 @@ func isStructOrStructPointer(t reflect.Type) bool {
230230
// typeToTableHeaders converts a type to a slice of column names. If the given
231231
// type is invalid (not a struct or a pointer to a struct, has invalid table
232232
// tags, etc.), an error is returned.
233-
functypeToTableHeaders(t reflect.Type) ([]string,string,error) {
233+
//
234+
// requireDefault is only needed for the root call. This is recursive, so nested
235+
// structs do not need the default sort name.
236+
// nolint:revive
237+
functypeToTableHeaders(t reflect.Type,requireDefaultbool) ([]string,string,error) {
234238
if!isStructOrStructPointer(t) {
235239
returnnil,"",xerrors.Errorf("typeToTableHeaders called with a non-struct or a non-pointer-to-a-struct type")
236240
}
@@ -246,6 +250,12 @@ func typeToTableHeaders(t reflect.Type) ([]string, string, error) {
246250
iferr!=nil {
247251
returnnil,"",xerrors.Errorf("parse struct tags for field %q in type %q: %w",field.Name,t.String(),err)
248252
}
253+
254+
ifname==""&& (recursive&&skip) {
255+
returnnil,"",xerrors.Errorf("a name is required for the field %q. "+
256+
"recursive_line will ensure this is never shown to the user, but is still needed",field.Name)
257+
}
258+
// If recurse and skip is set, the name is intentionally empty.
249259
ifname=="" {
250260
continue
251261
}
@@ -262,7 +272,7 @@ func typeToTableHeaders(t reflect.Type) ([]string, string, error) {
262272
returnnil,"",xerrors.Errorf("field %q in type %q is marked as recursive but does not contain a struct or a pointer to a struct",field.Name,t.String())
263273
}
264274

265-
childNames,_,err:=typeToTableHeaders(fieldType)
275+
childNames,defaultSort,err:=typeToTableHeaders(fieldType,false)
266276
iferr!=nil {
267277
returnnil,"",xerrors.Errorf("get child field header names for field %q in type %q: %w",field.Name,fieldType.String(),err)
268278
}
@@ -273,13 +283,16 @@ func typeToTableHeaders(t reflect.Type) ([]string, string, error) {
273283
}
274284
headers=append(headers,fullName)
275285
}
286+
ifdefaultSortName=="" {
287+
defaultSortName=defaultSort
288+
}
276289
continue
277290
}
278291

279292
headers=append(headers,name)
280293
}
281294

282-
ifdefaultSortName=="" {
295+
ifdefaultSortName==""&&requireDefault{
283296
returnnil,"",xerrors.Errorf("no field marked as default_sort in type %q",t.String())
284297
}
285298

‎cli/cliui/table_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ type tableTest2 struct {
4646

4747
typetableTest3struct {
4848
NotIncludedstring// no table tag
49-
SubtableTest2`table:"inner,recursive,default_sort"`
49+
SubtableTest2`table:"inner,recursive"`
5050
}
5151

5252
typetableTest4struct {
5353
InlinetableTest2`table:"ignored,recursive_inline"`
54-
SortFieldstring`table:"sort_field,default_sort"`
54+
SortFieldstring`table:"sort_field"`
5555
}
5656

5757
funcTest_DisplayTable(t*testing.T) {

‎cli/root_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func TestCommandHelp(t *testing.T) {
5151
Name:"coder users list --output json",
5252
Cmd: []string{"users","list","--output","json"},
5353
},
54+
clitest.CommandHelpCase{
55+
Name:"coder users list",
56+
Cmd: []string{"users","list"},
57+
},
5458
))
5559
}
5660

‎cli/testdata/coder_users_list.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
USERNAME EMAIL CREATED AT STATUS
2+
testuser testuser@coder.com [timestamp] active
3+
testuser2 testuser2@coder.com [timestamp] dormant

‎cli/testdata/coder_users_list_--output_json.golden

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
{
33
"id": "[first user ID]",
44
"username": "testuser",
5+
"avatar_url": "",
56
"name": "",
67
"email": "testuser@coder.com",
78
"created_at": "[timestamp]",
89
"last_seen_at": "[timestamp]",
910
"status": "active",
11+
"login_type": "password",
12+
"theme_preference": "",
1013
"organization_ids": [
1114
"[first org ID]"
1215
],
@@ -15,25 +18,22 @@
1518
"name": "owner",
1619
"display_name": "Owner"
1720
}
18-
],
19-
"avatar_url": "",
20-
"login_type": "password",
21-
"theme_preference": ""
21+
]
2222
},
2323
{
2424
"id": "[second user ID]",
2525
"username": "testuser2",
26+
"avatar_url": "",
2627
"name": "",
2728
"email": "testuser2@coder.com",
2829
"created_at": "[timestamp]",
2930
"last_seen_at": "[timestamp]",
3031
"status": "dormant",
32+
"login_type": "password",
33+
"theme_preference": "",
3134
"organization_ids": [
3235
"[first org ID]"
3336
],
34-
"roles": [],
35-
"avatar_url": "",
36-
"login_type": "password",
37-
"theme_preference": ""
37+
"roles": []
3838
}
3939
]

‎coderd/apidoc/docs.go

Lines changed: 56 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 48 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/audit.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,17 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs
186186

187187
ifdblog.UserUsername.Valid {
188188
user=&codersdk.User{
189-
ID:dblog.UserID,
190-
Username:dblog.UserUsername.String,
191-
Email:dblog.UserEmail.String,
192-
CreatedAt:dblog.UserCreatedAt.Time,
193-
Status:codersdk.UserStatus(dblog.UserStatus.UserStatus),
194-
Roles: []codersdk.Role{},
195-
AvatarURL:dblog.UserAvatarUrl.String,
189+
ReducedUser: codersdk.ReducedUser{
190+
MinimalUser: codersdk.MinimalUser{
191+
ID:dblog.UserID,
192+
Username:dblog.UserUsername.String,
193+
AvatarURL:dblog.UserAvatarUrl.String,
194+
},
195+
Email:dblog.UserEmail.String,
196+
CreatedAt:dblog.UserCreatedAt.Time,
197+
Status:codersdk.UserStatus(dblog.UserStatus.UserStatus),
198+
},
199+
Roles: []codersdk.Role{},
196200
}
197201

198202
for_,roleName:=rangedblog.UserRoles {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp