Skip to content

Commit

Permalink
limita notifiche ordini a utenti attivi (non sospesi né cessati). closes
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Nov 17, 2024
1 parent 86f7442 commit 6e48999
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions code/app/Models/Concerns/SuspendableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public function printableStatus()
return _i('Cessato');
}
}

public function scopeFullEnabled($query)
{
$query->whereNull('deleted_at')->whereNull('suspended_at');
}
}
2 changes: 2 additions & 0 deletions code/app/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
29 changes: 29 additions & 0 deletions code/tests/Services/UsersServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand All @@ -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());
}

/*
Expand Down

0 comments on commit 6e48999

Please sign in to comment.