Skip to content

Commit

Permalink
fix: fix bypass account limitation to create more contacts (#5125)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Apr 29, 2021
1 parent 75cc20e commit 3d66188
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/Exceptions/AccountLimitException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Exceptions;

use RuntimeException;

/**
* Exception thrown if the account has reach its.
*/
class AccountLimitException extends RuntimeException
{
}
10 changes: 10 additions & 0 deletions app/Services/Contact/Contact/CreateContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use App\Services\BaseService;
use App\Helpers\AccountHelper;
use function Safe\json_encode;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use App\Jobs\AuditLog\LogAccountAudit;
use App\Exceptions\AccountLimitException;
use App\Jobs\Avatars\GenerateDefaultAvatar;
use App\Jobs\Avatars\GetAvatarsFromInternet;

Expand Down Expand Up @@ -57,6 +60,13 @@ public function execute(array $data): Contact
{
$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();
}

// filter out the data that shall not be updated here
$dataOnly = Arr::except(
$data,
Expand Down

0 comments on commit 3d66188

Please sign in to comment.