Skip to content

Commit fbac248

Browse files
authored
fix: fix import job without subscription bypass (#5147)
1 parent 5fc4584 commit fbac248

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

app/Exceptions/Handler.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
use Throwable;
66
use Illuminate\Session\TokenMismatchException;
7-
use Illuminate\Validation\ValidationException;
8-
use Illuminate\Auth\Access\AuthorizationException;
9-
use Illuminate\Database\Eloquent\ModelNotFoundException;
107
use League\OAuth2\Server\Exception\OAuthServerException;
118
use Symfony\Component\HttpKernel\Exception\HttpException;
129
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
@@ -19,11 +16,8 @@ class Handler extends ExceptionHandler
1916
* @var array
2017
*/
2118
protected $dontReport = [
22-
AuthorizationException::class,
23-
HttpException::class,
24-
ModelNotFoundException::class,
19+
AccountLimitException::class,
2520
OAuthServerException::class,
26-
ValidationException::class,
2721
WrongIdException::class,
2822
];
2923

app/Http/Controllers/SettingsController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,16 @@ public function upload()
233233

234234
public function storeImport(ImportsRequest $request)
235235
{
236+
$account = auth()->user()->account;
237+
if (AccountHelper::hasReachedContactLimit($account)
238+
&& AccountHelper::hasLimitations($account)
239+
&& ! $account->legacy_free_plan_unlimited_contacts) {
240+
throw new AccountLimitException();
241+
}
242+
236243
$filename = $request->file('vcard')->store('imports', 'public');
237244

238-
$importJob = auth()->user()->account->importjobs()->create([
245+
$importJob = $account->importjobs()->create([
239246
'user_id' => auth()->user()->id,
240247
'type' => 'vcard',
241248
'filename' => $filename,

app/Services/Contact/Document/UploadDocument.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace App\Services\Contact\Document;
44

55
use App\Services\BaseService;
6+
use App\Helpers\AccountHelper;
7+
use App\Models\Account\Account;
68
use App\Models\Contact\Contact;
79
use App\Models\Contact\Document;
10+
use App\Exceptions\AccountLimitException;
811

912
class UploadDocument extends BaseService
1013
{
@@ -32,6 +35,13 @@ public function execute(array $data): Document
3235
{
3336
$this->validate($data);
3437

38+
$account = Account::find($data['account_id']);
39+
if (AccountHelper::hasReachedContactLimit($account)
40+
&& AccountHelper::hasLimitations($account)
41+
&& ! $account->legacy_free_plan_unlimited_contacts) {
42+
throw new AccountLimitException();
43+
}
44+
3545
Contact::where('account_id', $data['account_id'])
3646
->findOrFail($data['contact_id']);
3747

0 commit comments

Comments
 (0)