@@ -30,8 +30,45 @@ func (AGPLIDPSync) GroupSyncEnabled() bool {
30
30
return false
31
31
}
32
32
33
- func (s AGPLIDPSync ) GroupSyncSettings () runtimeconfig.RuntimeEntry [* GroupSyncSettings ] {
34
- return s .Group
33
+ func (s AGPLIDPSync ) UpdateGroupSettings (ctx context.Context , orgID uuid.UUID , db database.Store , settings GroupSyncSettings ) error {
34
+ orgResolver := s .Manager .OrganizationResolver (db , orgID )
35
+ err := s .SyncSettings .Group .SetRuntimeValue (ctx , orgResolver , & settings )
36
+ if err != nil {
37
+ return xerrors .Errorf ("update group sync settings: %w" , err )
38
+ }
39
+
40
+ return nil
41
+ }
42
+
43
+ func (s AGPLIDPSync ) GroupSyncSettings (ctx context.Context , orgID uuid.UUID , db database.Store ) (* GroupSyncSettings , error ) {
44
+ orgResolver := s .Manager .OrganizationResolver (db , orgID )
45
+ settings , err := s .SyncSettings .Group .Resolve (ctx , orgResolver )
46
+ if err != nil {
47
+ if ! xerrors .Is (err , runtimeconfig .ErrEntryNotFound ) {
48
+ return nil , xerrors .Errorf ("resolve group sync settings: %w" , err )
49
+ }
50
+
51
+ // Default to not being configured
52
+ settings = & GroupSyncSettings {}
53
+ }
54
+
55
+ // Check for legacy settings if the default org.
56
+ if s .DeploymentSyncSettings .Legacy .GroupField != "" && settings .Field == "" {
57
+ defaultOrganization , err := db .GetDefaultOrganization (ctx )
58
+ if err != nil {
59
+ return nil , xerrors .Errorf ("get default organization: %w" , err )
60
+ }
61
+ if defaultOrganization .ID == orgID {
62
+ settings = ptr .Ref (GroupSyncSettings (codersdk.GroupSyncSettings {
63
+ Field : s .Legacy .GroupField ,
64
+ LegacyNameMapping : s .Legacy .GroupMapping ,
65
+ RegexFilter : s .Legacy .GroupFilter ,
66
+ AutoCreateMissing : s .Legacy .CreateMissingGroups ,
67
+ }))
68
+ }
69
+ }
70
+
71
+ return settings , nil
35
72
}
36
73
37
74
func (s AGPLIDPSync ) ParseGroupClaims (_ context.Context , _ jwt.MapClaims ) (GroupParams , * HTTPError ) {
@@ -49,18 +86,6 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
49
86
// nolint:gocritic // all syncing is done as a system user
50
87
ctx = dbauthz .AsSystemRestricted (ctx )
51
88
52
- // Only care about the default org for deployment settings if the
53
- // legacy deployment settings exist.
54
- defaultOrgID := uuid .Nil
55
- // Default organization is configured via legacy deployment values
56
- if s .DeploymentSyncSettings .Legacy .GroupField != "" {
57
- defaultOrganization , err := db .GetDefaultOrganization (ctx )
58
- if err != nil {
59
- return xerrors .Errorf ("get default organization: %w" , err )
60
- }
61
- defaultOrgID = defaultOrganization .ID
62
- }
63
-
64
89
err := db .InTx (func (tx database.Store ) error {
65
90
userGroups , err := tx .GetGroups (ctx , database.GetGroupsParams {
66
91
HasMemberID : user .ID ,
@@ -83,25 +108,21 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
83
108
// organization.
84
109
orgSettings := make (map [uuid.UUID ]GroupSyncSettings )
85
110
for orgID := range userOrgs {
86
- orgResolver := s .Manager .OrganizationResolver (tx , orgID )
87
- settings , err := s .SyncSettings .Group .Resolve (ctx , orgResolver )
111
+ def , _ := tx .GetDefaultOrganization (ctx )
112
+ if def .ID == orgID {
113
+ fmt .Println ("as" )
114
+ }
115
+ settings , err := s .GroupSyncSettings (ctx , orgID , tx )
88
116
if err != nil {
89
- if ! xerrors .Is (err , runtimeconfig .ErrEntryNotFound ) {
90
- return xerrors .Errorf ("resolve group sync settings: %w" , err )
91
- }
92
- // Default to not being configured
117
+ // TODO: This error is currently silent to org admins.
118
+ // We need to come up with a way to notify the org admin of this
119
+ // error.
120
+ s .Logger .Error (ctx , "failed to get group sync settings" ,
121
+ slog .F ("organization_id" , orgID ),
122
+ slog .Error (err ),
123
+ )
93
124
settings = & GroupSyncSettings {}
94
125
}
95
-
96
- // Legacy deployment settings will override empty settings.
97
- if orgID == defaultOrgID && settings .Field == "" {
98
- settings = ptr .Ref (GroupSyncSettings (codersdk.GroupSyncSettings {
99
- Field : s .Legacy .GroupField ,
100
- LegacyNameMapping : s .Legacy .GroupMapping ,
101
- RegexFilter : s .Legacy .GroupFilter ,
102
- AutoCreateMissing : s .Legacy .CreateMissingGroups ,
103
- }))
104
- }
105
126
orgSettings [orgID ] = * settings
106
127
}
107
128
0 commit comments