]> _ Git - psq.git/commitdiff
fix
authorLouis Jeckel <louis.jeckel@outlook.cm>
Wed, 23 Sep 2020 09:50:55 +0000 (11:50 +0200)
committerLouis Jeckel <louis.jeckel@outlook.cm>
Wed, 23 Sep 2020 09:50:55 +0000 (11:50 +0200)
app/AccessLog.php
app/MailgunEvent.php

index 48ba3506e79838d9bdd4b1cc3c048ef296e47a12..de05d583521feb200f41c8a899ad3d03a41d12a9 100644 (file)
@@ -49,5 +49,29 @@ class AccessLog extends Model
         $entry->save();
 
     }
+
+    /**
+     * Returns combinations of file/user access using many different sessions
+     * @param int $limit
+     * @return \Illuminate\Support\Collection
+     */
+    public static function suspicious($limit = 10): \Illuminate\Support\Collection
+    {
+         return self::query()
+             ->whereNotNull('session_id')
+             ->whereNotNull('user_id')
+             ->where('user_id', '>', '100')
+             ->get()
+             ->groupBy(['user_id', 'file_id'])
+             ->flatten(1)
+             ->mapWithKeys(function($c) {
+                 $key = $c->first()->user_id . '.' . $c->first()->file_id;
+                 $count = $c->groupBy('session_id')->count();
+
+                 return [$key => $count];
+             })
+             ->sortDesc()
+             ->take($limit);
+    }
 }
 
index 33d002efdad3c3ada4613bea3527e861c7d8eb61..e5b4919b741d0fabf0223341ca547bf242bb8cb3 100644 (file)
@@ -44,6 +44,10 @@ class MailgunEvent extends Model
             'badge' => 'danger',
             'label' => 'Désabonné'
         ],
+        'suppressed' => [
+            'badge' => 'warning',
+            'label' => 'Annulé'
+        ],
         'unknown' => [
             'badge' => 'info',
             'label' => 'Inconnu'