Skip to content

Commit

Permalink
fix: fix import job without subscription bypass (#5147)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored May 2, 2021
1 parent 5fc4584 commit fbac248
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 1 addition & 7 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use Throwable;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use League\OAuth2\Server\Exception\OAuthServerException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
Expand All @@ -19,11 +16,8 @@ class Handler extends ExceptionHandler
* @var array
*/
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
AccountLimitException::class,
OAuthServerException::class,
ValidationException::class,
WrongIdException::class,
];

Expand Down
9 changes: 8 additions & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,16 @@ public function upload()

public function storeImport(ImportsRequest $request)
{
$account = auth()->user()->account;
if (AccountHelper::hasReachedContactLimit($account)
&& AccountHelper::hasLimitations($account)
&& ! $account->legacy_free_plan_unlimited_contacts) {
throw new AccountLimitException();
}

$filename = $request->file('vcard')->store('imports', 'public');

$importJob = auth()->user()->account->importjobs()->create([
$importJob = $account->importjobs()->create([
'user_id' => auth()->user()->id,
'type' => 'vcard',
'filename' => $filename,
Expand Down
10 changes: 10 additions & 0 deletions app/Services/Contact/Document/UploadDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace App\Services\Contact\Document;

use App\Services\BaseService;
use App\Helpers\AccountHelper;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use App\Models\Contact\Document;
use App\Exceptions\AccountLimitException;

class UploadDocument extends BaseService
{
Expand Down Expand Up @@ -32,6 +35,13 @@ public function execute(array $data): Document
{
$this->validate($data);

$account = Account::find($data['account_id']);
if (AccountHelper::hasReachedContactLimit($account)
&& AccountHelper::hasLimitations($account)
&& ! $account->legacy_free_plan_unlimited_contacts) {
throw new AccountLimitException();
}

Contact::where('account_id', $data['account_id'])
->findOrFail($data['contact_id']);

Expand Down

0 comments on commit fbac248

Please sign in to comment.