Frontend upload restrict consolidation

This commit is contained in:
Čarodej
2022-01-06 12:24:27 +01:00
parent 8d53ed1531
commit e5e713659e
13 changed files with 84 additions and 108 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Users\Restrictions\Engines;
use App\Users\Models\User;
use App\Users\Restrictions\RestrictionsEngine;
use Domain\Teams\Actions\CheckMaxTeamMembersLimitAction;
class DefaultRestrictionsEngine implements RestrictionsEngine
{
public function canUpload(User $user, int $fileSize = 0): bool
{
// 1. If storage limitations is set to false, then allow upload
if (! get_settings('storage_limitation')) {
return true;
}
// Get used storage percentage
$usedPercentage = get_storage_percentage(
used: $user->usedCapacity + $fileSize,
maxAmount: $user->limitations->max_storage_amount,
);
// 2. Check if storage usage exceed predefined capacity
return ! ($usedPercentage >= 100);
}
public function canDownload(User $user): bool
{
return true;
}
public function canCreateFolder(User $user): bool
{
return true;
}
public function canCreateTeamFolder(User $user): bool
{
return true;
}
public function canInviteTeamMembers(User $user, array $newInvites = []): bool
{
return true;
}
public function canVisitShared(User $user): bool
{
return true;
}
}