Additional checks around quotas

This commit is contained in:
David Bomba 2023-11-01 11:00:23 +11:00
parent a8b1c2cb8d
commit b540a98ac6
2 changed files with 13 additions and 3 deletions

View File

@ -493,6 +493,10 @@ class InvoiceController extends BaseController
return response(['message' => 'Please verify your account to send emails.'], 400);
}
if (Ninja::isHosted() && (stripos($action, 'email') !== false) && $user->account->emailQuotaExceeded()) {
return response(['message' => ctrans('texts.email_quota_exceeded_subject')], 400);
}
if(in_array($request->action, ['auto_bill','mark_paid']) && $user->cannot('create', \App\Models\Payment::class)) {
return response(['message' => ctrans('texts.not_authorized'), 'errors' => ['ids' => [ctrans('texts.not_authorized')]]], 422);
}

View File

@ -85,17 +85,23 @@ class SendEmailRequest extends Request
private function checkUserAbleToSend()
{
$input = $this->all();
/** @var \App\Models\User $user */
$user = auth()->user();
if (Ninja::isHosted() && !auth()->user()->account->account_sms_verified) {
if (Ninja::isHosted() && !$user->account->account_sms_verified) {
$this->error_message = ctrans('texts.authorization_sms_failure');
return false;
}
if (Ninja::isHosted() && $user->account->emailQuotaExceeded()) {
$this->error_message = ctrans('texts.email_quota_exceeded_subject');
return false;
}
/*Make sure we have all the require ingredients to send a template*/
if (isset($input['entity']) && array_key_exists('entity_id', $input) && is_string($input['entity']) && $input['entity_id']) {
/** @var \App\Models\User $user */
$user = auth()->user();
$company = $user->company();