From e284b125ab65af167aa39dff0f5fbc5c017aa263 Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Wed, 23 Sep 2020 11:50:55 +0200 Subject: [PATCH] fix --- app/AccessLog.php | 24 ++++++++++++++++++++++++ app/MailgunEvent.php | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/app/AccessLog.php b/app/AccessLog.php index 48ba350..de05d58 100644 --- a/app/AccessLog.php +++ b/app/AccessLog.php @@ -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); + } } diff --git a/app/MailgunEvent.php b/app/MailgunEvent.php index 33d002e..e5b4919 100644 --- a/app/MailgunEvent.php +++ b/app/MailgunEvent.php @@ -44,6 +44,10 @@ class MailgunEvent extends Model 'badge' => 'danger', 'label' => 'Désabonné' ], + 'suppressed' => [ + 'badge' => 'warning', + 'label' => 'Annulé' + ], 'unknown' => [ 'badge' => 'info', 'label' => 'Inconnu' -- 2.39.5