mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
MeteredBillingRestrictionsEngine update with the new rule for dunning
This commit is contained in:
@@ -46,6 +46,10 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
private function setSubscriptionConfig(): void
|
||||
{
|
||||
if (app()->runningUnitTests()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = getAllSettings();
|
||||
|
||||
config([
|
||||
|
||||
@@ -8,26 +8,46 @@ class MeteredBillingRestrictionsEngine implements RestrictionsEngine
|
||||
{
|
||||
public function canUpload(User $user, int $fileSize = 0): bool
|
||||
{
|
||||
// Check the count of the dunning emails
|
||||
if ($this->getDunningSequenceCount($user) === 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disable upload when user has more than 3 failed payments
|
||||
return ! ($user->failedPayments()->count() >= 3);
|
||||
return $this->checkFailedPayments($user);
|
||||
}
|
||||
|
||||
public function canDownload(User $user): bool
|
||||
{
|
||||
// Check the count of the dunning emails
|
||||
if ($this->getDunningSequenceCount($user) === 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disable download when user has more than 3 failed payments
|
||||
return ! ($user->failedPayments()->count() >= 3);
|
||||
return $this->checkFailedPayments($user);
|
||||
}
|
||||
|
||||
public function canCreateFolder(User $user): bool
|
||||
{
|
||||
// Check the count of the dunning emails
|
||||
if ($this->getDunningSequenceCount($user) === 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disable create folder when user has more than 3 failed payments
|
||||
return ! ($user->failedPayments()->count() >= 3);
|
||||
return $this->checkFailedPayments($user);
|
||||
}
|
||||
|
||||
public function canCreateTeamFolder(User $user): bool
|
||||
{
|
||||
// Check the count of the dunning emails
|
||||
if ($this->getDunningSequenceCount($user) === 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disable create folder when user has more than 3 failed payments
|
||||
return ! ($user->failedPayments()->count() >= 3);
|
||||
return $this->checkFailedPayments($user);
|
||||
}
|
||||
|
||||
public function canInviteTeamMembers(User $user, array $newInvites = []): bool
|
||||
@@ -37,7 +57,22 @@ class MeteredBillingRestrictionsEngine implements RestrictionsEngine
|
||||
|
||||
public function canVisitShared(User $user): bool
|
||||
{
|
||||
// Check the count of the dunning emails
|
||||
if ($this->getDunningSequenceCount($user) === 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disable share visit when user has more than 3 failed payments
|
||||
return ! ($user->failedPayments()->count() >= 3);
|
||||
return $this->checkFailedPayments($user);
|
||||
}
|
||||
|
||||
private function getDunningSequenceCount(User $user): int
|
||||
{
|
||||
return cache()->remember("dunning-count.$user->id", 3600, fn () => $user?->dunning->sequence ?? 0);
|
||||
}
|
||||
|
||||
private function checkFailedPayments(User $user): bool
|
||||
{
|
||||
return cache()->remember("failed-payments-count.$user->id", 3600, fn () => !($user->failedPayments()->count() >= 3));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user