(t *testing.T)
| 14648 | } |
| 14649 | |
| 14650 | func TestChatReadOnlySharedWriteHandlers(t *testing.T) { |
| 14651 | t.Parallel() |
| 14652 | |
| 14653 | const sharedChatText = "read only shared chat" |
| 14654 | |
| 14655 | setup := func(t *testing.T) ( |
| 14656 | ctx context.Context, |
| 14657 | ownerClient *codersdk.ExperimentalClient, |
| 14658 | sharedClient *codersdk.ExperimentalClient, |
| 14659 | chat codersdk.Chat, |
| 14660 | db database.Store, |
| 14661 | ) { |
| 14662 | t.Helper() |
| 14663 | |
| 14664 | ctx = testutil.Context(t, testutil.WaitLong) |
| 14665 | ownerClient, db = newChatClientWithDatabase(t) |
| 14666 | owner := coderdtest.CreateFirstUser(t, ownerClient.Client) |
| 14667 | _ = createChatModelConfig(t, ownerClient) |
| 14668 | sharedRaw, sharedUser := coderdtest.CreateAnotherUser( |
| 14669 | t, |
| 14670 | ownerClient.Client, |
| 14671 | owner.OrganizationID, |
| 14672 | rbac.ScopedRoleAgentsAccess(owner.OrganizationID), |
| 14673 | ) |
| 14674 | sharedClient = codersdk.NewExperimentalClient(sharedRaw) |
| 14675 | |
| 14676 | var err error |
| 14677 | chat, err = ownerClient.CreateChat(ctx, codersdk.CreateChatRequest{ |
| 14678 | OrganizationID: owner.OrganizationID, |
| 14679 | Content: []codersdk.ChatInputPart{{ |
| 14680 | Type: codersdk.ChatInputPartTypeText, |
| 14681 | Text: sharedChatText, |
| 14682 | }}, |
| 14683 | }) |
| 14684 | require.NoError(t, err) |
| 14685 | |
| 14686 | err = db.UpdateChatACLByID(dbauthz.As(ctx, rbac.Subject{ |
| 14687 | ID: owner.UserID.String(), |
| 14688 | Roles: rbac.RoleIdentifiers{rbac.RoleOwner()}, |
| 14689 | Scope: rbac.ScopeAll, |
| 14690 | }), database.UpdateChatACLByIDParams{ |
| 14691 | ID: chat.ID, |
| 14692 | UserACL: database.ChatACL{ |
| 14693 | sharedUser.ID.String(): database.ChatACLEntry{Permissions: []policy.Action{policy.ActionRead}}, |
| 14694 | }, |
| 14695 | GroupACL: database.ChatACL{}, |
| 14696 | }) |
| 14697 | require.NoError(t, err) |
| 14698 | return ctx, ownerClient, sharedClient, chat, db |
| 14699 | } |
| 14700 | |
| 14701 | t.Run("GetChatAndMessages", func(t *testing.T) { |
| 14702 | t.Parallel() |
| 14703 | |
| 14704 | ctx, _, sharedClient, chat, _ := setup(t) |
| 14705 | |
| 14706 | gotChat, err := sharedClient.GetChat(ctx, chat.ID) |
| 14707 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected