diff --git a/code/app/Models/Concerns/SuspendableTrait.php b/code/app/Models/Concerns/SuspendableTrait.php index b4ac30f2..753e3d79 100644 --- a/code/app/Models/Concerns/SuspendableTrait.php +++ b/code/app/Models/Concerns/SuspendableTrait.php @@ -46,4 +46,9 @@ public function printableStatus() return _i('Cessato'); } } + + public function scopeFullEnabled($query) + { + $query->whereNull('deleted_at')->whereNull('suspended_at'); + } } diff --git a/code/app/Order.php b/code/app/Order.php index db4ded62..d4e15aa4 100644 --- a/code/app/Order.php +++ b/code/app/Order.php @@ -452,6 +452,8 @@ public function notifiableUsers($gas) }); } + $query_users->fullEnabled(); + $deliveries = $order->deliveries; if ($deliveries->isEmpty() == false) { $query_users->where(function($query) use ($deliveries) { diff --git a/code/tests/Services/UsersServiceTest.php b/code/tests/Services/UsersServiceTest.php index 67b280b8..4ddf25ae 100644 --- a/code/tests/Services/UsersServiceTest.php +++ b/code/tests/Services/UsersServiceTest.php @@ -80,6 +80,7 @@ public function testCease() $this->actingAs($this->userWithAdminPerm); $users = app()->make('UsersService')->list(); $initial_count = $users->count(); + $initial_count_db = User::fullEnabled()->count(); $user = $users->random(); app()->make('UsersService')->update($user->id, [ @@ -88,9 +89,37 @@ public function testCease() 'suspended_at' => printableDate(date('Y-m-d')), ]); + $this->nextRound(); + $this->actingAs($this->userWithViewPerm); $users = app()->make('UsersService')->list('', true); $this->assertEquals($initial_count - 1, $users->count()); + $this->assertEquals($initial_count_db - 1, User::fullEnabled()->count()); + } + + /* + Sospensione utente + */ + public function testSuspend() + { + $this->actingAs($this->userWithAdminPerm); + $users = app()->make('UsersService')->list(); + $initial_count = $users->count(); + $initial_count_db = User::fullEnabled()->count(); + + $user = $users->random(); + app()->make('UsersService')->update($user->id, [ + 'status' => 'suspended', + 'deleted_at' => printableDate(date('Y-m-d')), + 'suspended_at' => printableDate(date('Y-m-d')), + ]); + + $this->nextRound(); + + $this->actingAs($this->userWithViewPerm); + $users = app()->make('UsersService')->list('', true); + $this->assertEquals($initial_count, $users->count()); + $this->assertEquals($initial_count_db - 1, User::fullEnabled()->count()); } /*