You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: improve code style with consistent negative conditions
Update OIDC user role handling to use cleaner Go style:
- Use negative conditions (loginType != codersdk.LoginTypeOIDC) for better readability
- Simplify comments to be more concise and inline
- Maintain all existing validation logic and functionality
Co-authored-by: angrycub <[email protected]>
// OIDC users get their roles from the OIDC provider's role mapping
218
-
ifloginType==codersdk.LoginTypeOIDC {
219
-
iflen(roles) >0 {
220
-
resp.Diagnostics.AddError("Configuration Error", "Cannot set explicit roles for OIDC users. OIDC users get their roles from the OIDC provider's role mapping configuration.")
221
-
return
222
-
}
223
-
tflog.Info(ctx, "skipping role assignment for OIDC user (roles come from OIDC provider)")
224
-
} else {
225
-
// For non-OIDC users, set roles explicitly
217
+
ifloginType!=codersdk.LoginTypeOIDC { // non-OIDC users get explicit roles
226
218
tflog.Info(ctx, "updating user roles", map[string]any{
tflog.Info(ctx, "successfully updated user roles")
229
+
} else {
230
+
// OIDC users get roles from provider's role mapping
231
+
iflen(roles) >0 {
232
+
resp.Diagnostics.AddError("Configuration Error", "Cannot set explicit roles for OIDC users. OIDC users get their roles from the OIDC provider's role mapping configuration.")
233
+
return
234
+
}
235
+
tflog.Info(ctx, "skipping role assignment for OIDC user (roles come from OIDC provider)")
resp.Diagnostics.AddError("Configuration Error", "Cannot set explicit roles for OIDC users. OIDC users get their roles from the OIDC provider's role mapping configuration.")
378
-
return
379
-
}
380
-
tflog.Info(ctx, "skipping role assignment for OIDC user (roles come from OIDC provider)")
381
-
} else {
382
-
// For non-OIDC users, set roles explicitly
370
+
ifloginType!=codersdk.LoginTypeOIDC { // non-OIDC users get explicit roles
383
371
tflog.Info(ctx, "updating user roles", map[string]any{
tflog.Info(ctx, "successfully updated user roles")
382
+
} else {
383
+
// OIDC users get roles from provider's role mapping
384
+
iflen(roles) >0 {
385
+
resp.Diagnostics.AddError("Configuration Error", "Cannot set explicit roles for OIDC users. OIDC users get their roles from the OIDC provider's role mapping configuration.")
386
+
return
387
+
}
388
+
tflog.Info(ctx, "skipping role assignment for OIDC user (roles come from OIDC provider)")
0 commit comments