@@ -61,14 +61,22 @@ func NewOrganizationUseCase(repo OrganizationRepo, repoUC *CASBackendUseCase, au
6161 l = log .NewStdLogger (io .Discard )
6262 }
6363
64- return & OrganizationUseCase {orgRepo : repo ,
64+ uc := & OrganizationUseCase {orgRepo : repo ,
6565 logger : servicelogger .ScopedHelper (l , "biz/organization" ),
6666 casBackendUseCase : repoUC ,
6767 integrationUC : iUC ,
6868 membershipRepo : mRepo ,
6969 onboardingConfig : onboardingConfig ,
7070 auditor : auditor ,
7171 }
72+
73+ if len (onboardingConfig ) > 0 {
74+ for _ , spec := range onboardingConfig {
75+ uc .logger .Infow ("msg" , "Auto-onboarding enabled" , "org" , spec .GetName (), "role" , spec .GetRole ())
76+ }
77+ }
78+
79+ return uc
7280}
7381
7482const RandomNameMaxTries = 10
@@ -294,18 +302,12 @@ func (uc *OrganizationUseCase) AutoOnboardOrganizations(ctx context.Context, use
294302 if err != nil {
295303 return fmt .Errorf ("failed to find organization: %w" , err )
296304 } else if org == nil {
297- uc .logger .Infow ("msg" , "Organization not found" , "name" , spec .GetName ())
305+ uc .logger .Infow ("msg" , "can't auto-onboard to organization, not found" , "name" , spec .GetName ())
298306 continue
299307 }
300308
301- // Parse organization UUID
302- orgUUID , err := uuid .Parse (org .ID )
303- if err != nil {
304- return NewErrInvalidUUID (err )
305- }
306-
307309 // Ensure user membership
308- if err := uc .ensureUserMembership (ctx , orgUUID , userUUID , PbRoleToBiz (spec .GetRole ())); err != nil {
310+ if err := uc .ensureUserMembership (ctx , org , userUUID , PbRoleToBiz (spec .GetRole ())); err != nil {
309311 return fmt .Errorf ("failed to ensure user membership: %w" , err )
310312 }
311313 }
@@ -315,7 +317,12 @@ func (uc *OrganizationUseCase) AutoOnboardOrganizations(ctx context.Context, use
315317
316318// ensureUserMembership ensures that a user is a member of the specified organization with the appropriate role.
317319// If the membership does not exist, it creates it.
318- func (uc * OrganizationUseCase ) ensureUserMembership (ctx context.Context , orgUUID , userUUID uuid.UUID , role authz.Role ) error {
320+ func (uc * OrganizationUseCase ) ensureUserMembership (ctx context.Context , org * Organization , userUUID uuid.UUID , role authz.Role ) error {
321+ orgUUID , err := uuid .Parse (org .ID )
322+ if err != nil {
323+ return NewErrInvalidUUID (err )
324+ }
325+
319326 m , err := uc .membershipRepo .FindByOrgAndUser (ctx , orgUUID , userUUID )
320327 if err != nil {
321328 return fmt .Errorf ("failed to find membership: %w" , err )
@@ -332,6 +339,6 @@ func (uc *OrganizationUseCase) ensureUserMembership(ctx context.Context, orgUUID
332339 return fmt .Errorf ("failed to create membership: %w" , err )
333340 }
334341
335- uc .logger .Infow ("msg" , "User auto-onboarded to organization" , "org" , orgUUID , "user" , userUUID , "role" , role )
342+ uc .logger .Infow ("msg" , "User auto-onboarded to organization" , "orgName" , org . Name , "orgID " , orgUUID , "user" , userUUID , "role" , role )
336343 return nil
337344}
0 commit comments