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

Function Organization

coderd/database/dbgen/dbgen.go:1001–1035  ·  view source on GitHub ↗
(t testing.TB, db database.Store, orig database.Organization)

Source from the content-addressed store, hash-verified

999}
1000
1001func Organization(t testing.TB, db database.Store, orig database.Organization) database.Organization {
1002 org, err := db.InsertOrganization(genCtx, database.InsertOrganizationParams{
1003 ID: takeFirst(orig.ID, uuid.New()),
1004 Name: takeFirst(orig.Name, testutil.GetRandomName(t)),
1005 DisplayName: takeFirst(orig.Name, testutil.GetRandomName(t)),
1006 Description: takeFirst(orig.Description, testutil.GetRandomName(t)),
1007 Icon: takeFirst(orig.Icon, ""),
1008 CreatedAt: takeFirst(orig.CreatedAt, dbtime.Now()),
1009 UpdatedAt: takeFirst(orig.UpdatedAt, dbtime.Now()),
1010 })
1011 require.NoError(t, err, "insert organization")
1012
1013 // Populate the placeholder system roles (created by DB
1014 // trigger/migration) so org members have expected permissions.
1015 //nolint:gocritic // ReconcileSystemRole needs the system:update
1016 // permission that `genCtx` does not have.
1017 sysCtx := dbauthz.AsSystemRestricted(genCtx)
1018 for roleName := range rolestore.SystemRoleNames {
1019 role := database.CustomRole{
1020 Name: roleName,
1021 OrganizationID: uuid.NullUUID{UUID: org.ID, Valid: true},
1022 }
1023 _, _, err = rolestore.ReconcileSystemRole(sysCtx, db, role, org)
1024 if errors.Is(err, sql.ErrNoRows) {
1025 // The trigger that creates the placeholder role didn't run (e.g.,
1026 // triggers were disabled in the test). Create the role manually.
1027 err = rolestore.CreateSystemRole(sysCtx, db, org, roleName)
1028 require.NoError(t, err, "create role "+roleName)
1029 _, _, err = rolestore.ReconcileSystemRole(sysCtx, db, role, org)
1030 }
1031 require.NoError(t, err, "reconcile role "+roleName)
1032 }
1033
1034 return org
1035}
1036
1037func OrganizationMember(t testing.TB, db database.Store, orig database.OrganizationMember) database.OrganizationMember {
1038 mem, err := db.InsertOrganizationMember(genCtx, database.InsertOrganizationMemberParams{

Callers 15

TestPostChatsFunction · 0.92
TestPatchChatFunction · 0.92
TestListMembersFunction · 0.92
TestAPIKeyFunction · 0.92
TestTaskParamFunction · 0.92
TestOrganizationParamFunction · 0.92
TestWorkspaceParamFunction · 0.92
TestChatParamFunction · 0.92
TestWorkspaceBuildParamFunction · 0.92
TestTemplateParamFunction · 0.92
TestTemplateVersionParamFunction · 0.92

Calls 9

GetRandomNameFunction · 0.92
NowFunction · 0.92
AsSystemRestrictedFunction · 0.92
ReconcileSystemRoleFunction · 0.92
CreateSystemRoleFunction · 0.92
takeFirstFunction · 0.70
InsertOrganizationMethod · 0.65
NewMethod · 0.65
IsMethod · 0.45

Tested by 15

TestPostChatsFunction · 0.74
TestPatchChatFunction · 0.74
TestListMembersFunction · 0.74
TestAPIKeyFunction · 0.74
TestTaskParamFunction · 0.74
TestOrganizationParamFunction · 0.74
TestWorkspaceParamFunction · 0.74
TestChatParamFunction · 0.74
TestWorkspaceBuildParamFunction · 0.74
TestTemplateParamFunction · 0.74
TestTemplateVersionParamFunction · 0.74