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

Commit69c2c40

Browse files
authored
chore: add user details to aibridge interception list endpoint (#20397)
- Adds FK from `aibridge_interceptions.initiator_id` to `users.id`- This is enforced by deleting any rows that don't have any users. Sincethis is an experimental feature AND coder never deletes user rows Ithink this is acceptable.- Adds `name` as a property on `codersdk.MinimalUser`- This matches the `visible_users` view in the database. I'm unsure why`name` wasn't already included given that `username` is.- Adds a new `initiator` field to `codersdk.AIBridgeInterception` whichcontains `codersdk.MinimalUser` (ID, username, name, avatar URL)- Removes `initiator_id` from `codersdk.AIBridgeInterception` - Should be fine since we're still in early access
1 parent9da60a9 commit69c2c40

30 files changed

+329
-78
lines changed

‎cli/sharing_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func TestSharingShare(t *testing.T) {
5454
MinimalUser: codersdk.MinimalUser{
5555
ID:toShareWithUser.ID,
5656
Username:toShareWithUser.Username,
57+
Name:toShareWithUser.Name,
5758
AvatarURL:toShareWithUser.AvatarURL,
5859
},
5960
Role:codersdk.WorkspaceRole("use"),
@@ -103,6 +104,7 @@ func TestSharingShare(t *testing.T) {
103104
MinimalUser: codersdk.MinimalUser{
104105
ID:toShareWithUser1.ID,
105106
Username:toShareWithUser1.Username,
107+
Name:toShareWithUser1.Name,
106108
AvatarURL:toShareWithUser1.AvatarURL,
107109
},
108110
Role:codersdk.WorkspaceRoleUse,
@@ -111,6 +113,7 @@ func TestSharingShare(t *testing.T) {
111113
MinimalUser: codersdk.MinimalUser{
112114
ID:toShareWithUser2.ID,
113115
Username:toShareWithUser2.Username,
116+
Name:toShareWithUser2.Name,
114117
AvatarURL:toShareWithUser2.AvatarURL,
115118
},
116119
Role:codersdk.WorkspaceRoleUse,
@@ -155,6 +158,7 @@ func TestSharingShare(t *testing.T) {
155158
MinimalUser: codersdk.MinimalUser{
156159
ID:toShareWithUser.ID,
157160
Username:toShareWithUser.Username,
161+
Name:toShareWithUser.Name,
158162
AvatarURL:toShareWithUser.AvatarURL,
159163
},
160164
Role:codersdk.WorkspaceRoleAdmin,

‎cli/testdata/coder_users_list_--help.golden‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ USAGE:
88
Aliases: ls
99

1010
OPTIONS:
11-
-c, --column [id|username|email|created at|updated at|status] (default: username,email,created at,status)
11+
-c, --column [id|username|name|email|created at|updated at|status] (default: username,email,created at,status)
1212
Columns to display in table output.
1313

1414
--github-user-id int

‎coderd/apidoc/docs.go‎

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

‎coderd/apidoc/swagger.json‎

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

‎coderd/database/db2sdk/db2sdk.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ func MinimalUser(user database.User) codersdk.MinimalUser {
189189
return codersdk.MinimalUser{
190190
ID:user.ID,
191191
Username:user.Username,
192+
Name:user.Name,
193+
AvatarURL:user.AvatarURL,
194+
}
195+
}
196+
197+
funcMinimalUserFromVisibleUser(user database.VisibleUser) codersdk.MinimalUser {
198+
return codersdk.MinimalUser{
199+
ID:user.ID,
200+
Username:user.Username,
201+
Name:user.Name,
192202
AvatarURL:user.AvatarURL,
193203
}
194204
}
@@ -197,7 +207,6 @@ func ReducedUser(user database.User) codersdk.ReducedUser {
197207
return codersdk.ReducedUser{
198208
MinimalUser:MinimalUser(user),
199209
Email:user.Email,
200-
Name:user.Name,
201210
CreatedAt:user.CreatedAt,
202211
UpdatedAt:user.UpdatedAt,
203212
LastSeenAt:user.LastSeenAt,
@@ -927,7 +936,7 @@ func PreviewParameterValidation(v *previewtypes.ParameterValidation) codersdk.Pr
927936
}
928937
}
929938

930-
funcAIBridgeInterception(interception database.AIBridgeInterception,tokenUsages []database.AIBridgeTokenUsage,userPrompts []database.AIBridgeUserPrompt,toolUsages []database.AIBridgeToolUsage) codersdk.AIBridgeInterception {
939+
funcAIBridgeInterception(interception database.AIBridgeInterception,initiator database.VisibleUser,tokenUsages []database.AIBridgeTokenUsage,userPrompts []database.AIBridgeUserPrompt,toolUsages []database.AIBridgeToolUsage) codersdk.AIBridgeInterception {
931940
sdkTokenUsages:=List(tokenUsages,AIBridgeTokenUsage)
932941
sort.Slice(sdkTokenUsages,func(i,jint)bool {
933942
// created_at ASC
@@ -945,7 +954,7 @@ func AIBridgeInterception(interception database.AIBridgeInterception, tokenUsage
945954
})
946955
return codersdk.AIBridgeInterception{
947956
ID:interception.ID,
948-
InitiatorID:interception.InitiatorID,
957+
Initiator:MinimalUserFromVisibleUser(initiator),
949958
Provider:interception.Provider,
950959
Model:interception.Model,
951960
Metadata:jsonOrEmptyMap(interception.Metadata),

‎coderd/database/dbauthz/dbauthz.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4461,7 +4461,7 @@ func (q *querier) InsertWorkspaceResourceMetadata(ctx context.Context, arg datab
44614461
returnq.db.InsertWorkspaceResourceMetadata(ctx,arg)
44624462
}
44634463

4464-
func (q*querier)ListAIBridgeInterceptions(ctx context.Context,arg database.ListAIBridgeInterceptionsParams) ([]database.AIBridgeInterception,error) {
4464+
func (q*querier)ListAIBridgeInterceptions(ctx context.Context,arg database.ListAIBridgeInterceptionsParams) ([]database.ListAIBridgeInterceptionsRow,error) {
44654465
prep,err:=prepareSQLFilter(ctx,q.auth,policy.ActionRead,rbac.ResourceAibridgeInterception.Type)
44664466
iferr!=nil {
44674467
returnnil,xerrors.Errorf("(dev error) prepare sql filter: %w",err)
@@ -5870,7 +5870,7 @@ func (q *querier) CountAuthorizedConnectionLogs(ctx context.Context, arg databas
58705870
returnq.CountConnectionLogs(ctx,arg)
58715871
}
58725872

5873-
func (q*querier)ListAuthorizedAIBridgeInterceptions(ctx context.Context,arg database.ListAIBridgeInterceptionsParams,_ rbac.PreparedAuthorized) ([]database.AIBridgeInterception,error) {
5873+
func (q*querier)ListAuthorizedAIBridgeInterceptions(ctx context.Context,arg database.ListAIBridgeInterceptionsParams,_ rbac.PreparedAuthorized) ([]database.ListAIBridgeInterceptionsRow,error) {
58745874
// TODO: Delete this function, all ListAIBridgeInterceptions should be authorized. For now just call ListAIBridgeInterceptions on the authz querier.
58755875
// This cannot be deleted for now because it's included in the
58765876
// database.Store interface, so dbauthz needs to implement it.

‎coderd/database/dbauthz/dbauthz_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4537,14 +4537,14 @@ func (s *MethodTestSuite) TestAIBridge() {
45374537

45384538
s.Run("ListAIBridgeInterceptions",s.Mocked(func(db*dbmock.MockStore,faker*gofakeit.Faker,check*expects) {
45394539
params:= database.ListAIBridgeInterceptionsParams{}
4540-
db.EXPECT().ListAuthorizedAIBridgeInterceptions(gomock.Any(),params,gomock.Any()).Return([]database.AIBridgeInterception{},nil).AnyTimes()
4540+
db.EXPECT().ListAuthorizedAIBridgeInterceptions(gomock.Any(),params,gomock.Any()).Return([]database.ListAIBridgeInterceptionsRow{},nil).AnyTimes()
45414541
// No asserts here because SQLFilter.
45424542
check.Args(params).Asserts()
45434543
}))
45444544

45454545
s.Run("ListAuthorizedAIBridgeInterceptions",s.Mocked(func(db*dbmock.MockStore,faker*gofakeit.Faker,check*expects) {
45464546
params:= database.ListAIBridgeInterceptionsParams{}
4547-
db.EXPECT().ListAuthorizedAIBridgeInterceptions(gomock.Any(),params,gomock.Any()).Return([]database.AIBridgeInterception{},nil).AnyTimes()
4547+
db.EXPECT().ListAuthorizedAIBridgeInterceptions(gomock.Any(),params,gomock.Any()).Return([]database.ListAIBridgeInterceptionsRow{},nil).AnyTimes()
45484548
// No asserts here because SQLFilter.
45494549
check.Args(params,emptyPreparedAuthorized{}).Asserts()
45504550
}))

‎coderd/database/dbmetrics/querymetrics.go‎

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

‎coderd/database/dbmock/dbmock.go‎

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

‎coderd/database/dump.sql‎

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp