Skip to content

feat: get and update group IdP Sync settings #14647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update unit test to use EntryNotFoundErr
  • Loading branch information
Emyrk committed Sep 16, 2024
commit 4ac097ba45335fc8f48f2f112e16b01fbcb7c313
28 changes: 14 additions & 14 deletions coderd/idpsync/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ func (s AGPLIDPSync) GroupSyncSettings(ctx context.Context, orgID uuid.UUID, db

// Default to not being configured
settings = &GroupSyncSettings{}
}

// Check for legacy settings if the default org.
if s.DeploymentSyncSettings.Legacy.GroupField != "" && settings.Field == "" {
defaultOrganization, err := db.GetDefaultOrganization(ctx)
if err != nil {
return nil, xerrors.Errorf("get default organization: %w", err)
}
if defaultOrganization.ID == orgID {
settings = ptr.Ref(GroupSyncSettings(codersdk.GroupSyncSettings{
Field: s.Legacy.GroupField,
LegacyNameMapping: s.Legacy.GroupMapping,
RegexFilter: s.Legacy.GroupFilter,
AutoCreateMissing: s.Legacy.CreateMissingGroups,
}))
// Check for legacy settings if the default org.
if s.DeploymentSyncSettings.Legacy.GroupField != "" {
defaultOrganization, err := db.GetDefaultOrganization(ctx)
if err != nil {
return nil, xerrors.Errorf("get default organization: %w", err)
}
if defaultOrganization.ID == orgID {
settings = ptr.Ref(GroupSyncSettings(codersdk.GroupSyncSettings{
Field: s.Legacy.GroupField,
LegacyNameMapping: s.Legacy.GroupMapping,
RegexFilter: s.Legacy.GroupFilter,
AutoCreateMissing: s.Legacy.CreateMissingGroups,
}))
}
}
}

Expand Down
11 changes: 4 additions & 7 deletions coderd/idpsync/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,16 +727,13 @@ func SetupOrganization(t *testing.T, s *idpsync.AGPLIDPSync, db database.Store,
require.NoError(t, err, "Everyone group for an org")
}

var settings idpsync.GroupSyncSettings
manager := runtimeconfig.NewManager()
if def.Settings != nil {
settings = idpsync.GroupSyncSettings(*def.Settings)
orgResolver := manager.OrganizationResolver(db, org.ID)
err = s.Group.SetRuntimeValue(context.Background(), orgResolver, (*idpsync.GroupSyncSettings)(def.Settings))
require.NoError(t, err)
}

manager := runtimeconfig.NewManager()
orgResolver := manager.OrganizationResolver(db, org.ID)
err = s.Group.SetRuntimeValue(context.Background(), orgResolver, &settings)
require.NoError(t, err)

if !def.NotMember {
dbgen.OrganizationMember(t, db, database.OrganizationMember{
UserID: user.ID,
Expand Down