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

Function SetupOrganization

coderd/idpsync/group_test.go:745–830  ·  view source on GitHub ↗
(t *testing.T, s *idpsync.AGPLIDPSync, db database.Store, user database.User, orgID uuid.UUID, def orgSetupDefinition)

Source from the content-addressed store, hash-verified

743}
744
745func SetupOrganization(t *testing.T, s *idpsync.AGPLIDPSync, db database.Store, user database.User, orgID uuid.UUID, def orgSetupDefinition) {
746 t.Helper()
747
748 // Account that the org might be the default organization
749 org, err := db.GetOrganizationByID(context.Background(), orgID)
750 if xerrors.Is(err, sql.ErrNoRows) {
751 org = dbgen.Organization(t, db, database.Organization{
752 ID: orgID,
753 })
754 }
755
756 _, err = db.InsertAllUsersGroup(context.Background(), org.ID)
757 if !database.IsUniqueViolation(err) {
758 require.NoError(t, err, "Everyone group for an org")
759 }
760
761 manager := runtimeconfig.NewManager()
762 orgResolver := manager.OrganizationResolver(db, org.ID)
763 if def.GroupSettings != nil {
764 err = s.Group.SetRuntimeValue(context.Background(), orgResolver, (*idpsync.GroupSyncSettings)(def.GroupSettings))
765 require.NoError(t, err)
766 }
767
768 if def.RoleSettings != nil {
769 err = s.Role.SetRuntimeValue(context.Background(), orgResolver, def.RoleSettings)
770 require.NoError(t, err)
771 }
772
773 if !def.NotMember {
774 dbgen.OrganizationMember(t, db, database.OrganizationMember{
775 UserID: user.ID,
776 OrganizationID: org.ID,
777 })
778 }
779
780 if len(def.OrganizationRoles) > 0 {
781 _, err := db.UpdateMemberRoles(context.Background(), database.UpdateMemberRolesParams{
782 GrantedRoles: def.OrganizationRoles,
783 UserID: user.ID,
784 OrgID: org.ID,
785 })
786 require.NoError(t, err)
787 }
788
789 if len(def.CustomRoles) > 0 {
790 for _, cr := range def.CustomRoles {
791 _, err := db.InsertCustomRole(context.Background(), database.InsertCustomRoleParams{
792 Name: cr,
793 DisplayName: cr,
794 OrganizationID: uuid.NullUUID{
795 UUID: org.ID,
796 Valid: true,
797 },
798 SitePermissions: nil,
799 OrgPermissions: nil,
800 UserPermissions: nil,
801 })
802 require.NoError(t, err)

Callers 3

TestRoleSyncTableFunction · 0.85
TestGroupSyncTableFunction · 0.85
TestSyncDisabledFunction · 0.85

Calls 14

OrganizationResolverMethod · 0.95
OrganizationFunction · 0.92
IsUniqueViolationFunction · 0.92
NewManagerFunction · 0.92
OrganizationMemberFunction · 0.92
GroupFunction · 0.92
GroupMemberFunction · 0.92
SetRuntimeValueMethod · 0.80
HelperMethod · 0.65
GetOrganizationByIDMethod · 0.65
InsertAllUsersGroupMethod · 0.65
UpdateMemberRolesMethod · 0.65

Tested by

no test coverage detected