@@ -66,7 +66,7 @@ protected function handle2($event)
6666
6767 Log::debug ("Assembling audit report for {$ user ->email }... " );
6868
69- $ subject = $ this ->buildEmailSubject ($ user , $ assets );
69+ $ subject = $ this ->buildEmailSubject ($ user , $ assets, $ isOnboarding );
7070 $ body = ['<table cellspacing="0" cellpadding="0" style="margin: auto;"><tbody> ' ];
7171 $ body [] = '<tr><td style="font-size: 28px; text-align: center;">Bonjour !</td></tr> ' ;
7272 $ body [] = '<tr><td style="font-size: 16px; line-height: 1.6;"> ' ;
@@ -129,17 +129,22 @@ private function buildEmailCta(User $user): string
129129 " ;
130130 }
131131
132- private function buildEmailSubject (User $ user , Collection $ assets ): string
132+ private function buildEmailSubject (User $ user , Collection $ assets, bool $ isOnboarding ): string
133133 {
134134 Log::debug ("Building subject for user {$ user ->email }... " );
135135
136136 $ nbNewAssets = Asset::where ('created_at ' , '>= ' , Carbon::now ()->subDay ())->count ();
137137
138138 Log::debug ("{$ nbNewAssets } new assets found for user {$ user ->email }" );
139139
140- $ nbLeaks = $ this ->fetchLeaks ($ user )->unique ()->count ();
141-
142- Log::debug ("{$ nbLeaks } leaks found for user {$ user ->email }" );
140+ if ($ isOnboarding ) {
141+ $ nbLeaks = $ this ->fetchLeaks ($ user )->unique ()->count ();
142+ Log::debug ("{$ nbLeaks } leaks found for user {$ user ->email }" );
143+ } else {
144+ $ minDate = Carbon::now ()->utc ()->subDays (7 );
145+ $ nbLeaks = $ this ->fetchLeaks ($ user , $ minDate )->unique ()->count ();
146+ Log::debug ("{$ nbLeaks } new leaks found for user {$ user ->email } since {$ minDate ->format ('Y-m-d ' )}" );
147+ }
143148
144149 $ nbHigh = $ assets ->flatMap (fn (Asset $ asset ) => $ asset ->alertsWithCriticalityHigh ()->get ())
145150 ->filter (fn (Alert $ alert ) => $ alert ->is_hidden === 0 )
@@ -178,7 +183,12 @@ private function buildEmailSubject(User $user, Collection $assets): string
178183 if ($ nbNewAssets > 0 ) {
179184 return "Cywise - {$ nbNewAssets } nouveaux actifs ont été ajoutés ! " ;
180185 }
181- return 'Cywise - Une fuite de données ou compromission a été détectée ! ' ;
186+ if ($ nbLeaks > 0 ) {
187+ return $ isOnboarding ?
188+ "Cywise - {$ nbLeaks } fuites de données ou compromissions ont été découvertes ! " :
189+ "Cywise - {$ nbLeaks } nouvelles fuites de données ou compromissions ont été découvertes ! " ;
190+ }
191+ return 'Cywise - Tout va bien ! ' ;
182192 }
183193
184194 private function buildSummary (User $ user , Collection $ assets ): string
0 commit comments