Skip to content

Beautiful Open-Source Form Builder

Add logging for user block/unblock actions (#818)

Chirag Chhatrala6000fd485094
diff --git a/api/.env.example b/api/.env.example
index ff2fe6b35..b950810d9 100644
--- a/api/.env.example
+++ b/api/.env.example
@@ -98,4 +98,7 @@ ZAPIER_ENABLED=false
STRIPE_CLIENT_ID=
STRIPE_CLIENT_SECRET=
-STRIPE_REDIRECT_URI=http://localhost:3000/connections/callback/stripe
\ No newline at end of file
+STRIPE_REDIRECT_URI=http://localhost:3000/connections/callback/stripe
+
+LOG_SLACK_WEBHOOK_URL=
+LOG_SLACK_CHURN_WEBHOOK_URL=
\ No newline at end of file
diff --git a/api/app/Service/UserActionService.php b/api/app/Service/UserActionService.php
index 781cb6ee0..fcb0e0fa6 100644
--- a/api/app/Service/UserActionService.php
+++ b/api/app/Service/UserActionService.php
@@ -7,6 +7,7 @@ use App\Mail\UserBlockedEmail;
use App\Mail\UserUnblockedEmail;
use App\Models\User;
use Illuminate\Support\Facades\Mail;
+use Illuminate\Support\Facades\Log;
class UserActionService
{
@@ -22,6 +23,16 @@ class UserActionService
'moderator_id' => $moderatorId,
]);
+ // Log to Slack
+ if (app()->environment() !== 'testing') {
+ Log::channel('slack_churn')->info('User blocked 🚫', [
+ 'user_id' => $user->id,
+ 'email' => $user->email,
+ 'reason' => $reason,
+ 'moderator_id' => $moderatorId,
+ ]);
+ }
+
Mail::to($user)->send(new UserBlockedEmail($user, $reason));
return $user->fresh();
@@ -37,6 +48,16 @@ class UserActionService
'moderator_id' => $moderatorId,
]);
+ // Log to Slack
+ if (app()->environment() !== 'testing') {
+ Log::channel('slack_churn')->info('User unblocked πŸ”“', [
+ 'user_id' => $user->id,
+ 'email' => $user->email,
+ 'reason' => $reason,
+ 'moderator_id' => $moderatorId,
+ ]);
+ }
+
Mail::to($user)->send(new UserUnblockedEmail($user, $reason));
return $user->fresh();
diff --git a/api/config/logging.php b/api/config/logging.php
index ed886d449..4d7f10d18 100644
--- a/api/config/logging.php
+++ b/api/config/logging.php
@@ -69,6 +69,14 @@ return [
'level' => env('LOG_LEVEL', 'debug'),
],
+ 'slack_churn' => [
+ 'driver' => 'slack',
+ 'url' => env('LOG_SLACK_CHURN_WEBHOOK_URL', env('LOG_SLACK_WEBHOOK_URL')),
+ 'username' => 'OpenForm Churn Bot',
+ 'emoji' => ':wave:',
+ 'level' => 'info',
+ ],
+
'papertrail' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),