MCPcopy Index your code
hub / github.com/coder/coder / TestGetAuthorizedChatsByChatFileIDACLSharing

Function TestGetAuthorizedChatsByChatFileIDACLSharing

coderd/database/querier_test.go:1687–1770  ·  view source on GitHub ↗

nolint:tparallel,paralleltest // It toggles the global chat ACL flag.

(t *testing.T)

Source from the content-addressed store, hash-verified

1685
1686//nolint:tparallel,paralleltest // It toggles the global chat ACL flag.
1687func TestGetAuthorizedChatsByChatFileIDACLSharing(t *testing.T) {
1688 if testing.Short() {
1689 t.SkipNow()
1690 }
1691
1692 rbac.SetChatACLDisabled(false)
1693 t.Cleanup(func() { rbac.SetChatACLDisabled(false) })
1694
1695 ctx := testutil.Context(t, testutil.WaitMedium)
1696 sqlDB := testSQLDB(t)
1697 err := migrations.Up(sqlDB)
1698 require.NoError(t, err)
1699 db := database.New(sqlDB)
1700 authorizer := rbac.NewStrictCachingAuthorizer(prometheus.NewRegistry())
1701
1702 owner := dbgen.User(t, db, database.User{})
1703 recipient := dbgen.User(t, db, database.User{})
1704 org := dbgen.Organization(t, db, database.Organization{})
1705 dbgen.OrganizationMember(t, db, database.OrganizationMember{
1706 UserID: owner.ID,
1707 OrganizationID: org.ID,
1708 Roles: []string{rbac.RoleAgentsAccess()},
1709 })
1710 dbgen.OrganizationMember(t, db, database.OrganizationMember{
1711 UserID: recipient.ID,
1712 OrganizationID: org.ID,
1713 Roles: []string{rbac.RoleAgentsAccess()},
1714 })
1715
1716 dbgen.ChatProvider(t, db, database.ChatProvider{Provider: "openai", DisplayName: "OpenAI"})
1717 modelCfg := dbgen.ChatModelConfig(t, db, database.ChatModelConfig{
1718 Provider: "openai",
1719 Model: "test-model",
1720 CreatedBy: uuid.NullUUID{UUID: owner.ID, Valid: true},
1721 UpdatedBy: uuid.NullUUID{UUID: owner.ID, Valid: true},
1722 IsDefault: true,
1723 CompressionThreshold: 80,
1724 })
1725
1726 ownerChat := dbgen.Chat(t, db, database.Chat{
1727 OrganizationID: org.ID,
1728 OwnerID: owner.ID,
1729 LastModelConfigID: modelCfg.ID,
1730 Title: "shared owner chat",
1731 })
1732 sharedACL := database.ChatACL{
1733 recipient.ID.String(): database.ChatACLEntry{Permissions: []policy.Action{policy.ActionRead}},
1734 }
1735 err = db.UpdateChatACLByID(ctx, database.UpdateChatACLByIDParams{
1736 ID: ownerChat.ID,
1737 UserACL: sharedACL,
1738 GroupACL: database.ChatACL{},
1739 })
1740 require.NoError(t, err)
1741
1742 fileRow, err := db.InsertChatFile(ctx, database.InsertChatFileParams{
1743 OwnerID: owner.ID,
1744 OrganizationID: org.ID,

Callers

nothing calls this directly

Calls 15

SetChatACLDisabledFunction · 0.92
ContextFunction · 0.92
UpFunction · 0.92
NewFunction · 0.92
UserFunction · 0.92
OrganizationFunction · 0.92
OrganizationMemberFunction · 0.92
RoleAgentsAccessFunction · 0.92
ChatProviderFunction · 0.92
ChatModelConfigFunction · 0.92
ChatFunction · 0.92

Tested by

no test coverage detected