Limit bulk emailing

This commit is contained in:
Hillel Coren 2018-02-04 10:43:14 +02:00
parent 29b2c565fc
commit f39f744dca
3 changed files with 13 additions and 3 deletions

View File

@ -211,7 +211,9 @@ class InvoiceApiController extends BaseAPIController
$invoice = $recurringInvoice; $invoice = $recurringInvoice;
} }
$reminder = isset($data['email_type']) ? $data['email_type'] : false; $reminder = isset($data['email_type']) ? $data['email_type'] : false;
$this->dispatch(new SendInvoiceEmail($invoice, auth()->user()->id, $reminder)); if (auth()->user()->isTrusted()) {
$this->dispatch(new SendInvoiceEmail($invoice, auth()->user()->id, $reminder));
}
} }
} }
@ -342,6 +344,10 @@ class InvoiceApiController extends BaseAPIController
public function emailInvoice(InvoiceRequest $request) public function emailInvoice(InvoiceRequest $request)
{ {
if (! auth()->user()->isTrusted()) {
return $this->errorResponse('Requires paid pro plan', 400);
}
$invoice = $request->entity(); $invoice = $request->entity();
if ($invoice->is_recurring && $recurringInvoice = $this->invoiceRepo->createRecurringInvoice($invoice)) { if ($invoice->is_recurring && $recurringInvoice = $this->invoiceRepo->createRecurringInvoice($invoice)) {

View File

@ -138,8 +138,12 @@ class User extends Authenticatable
/** /**
* @return mixed * @return mixed
*/ */
public function isPaidPro() public function isTrusted()
{ {
if (Utils::isSelfHost()) {
true;
}
return $this->account->isPro() && ! $this->account->isTrial(); return $this->account->isPro() && ! $this->account->isTrial();
} }

View File

@ -196,7 +196,7 @@ class InvoiceDatatable extends EntityDatatable
'label' => mtrans($this->entityType, 'download_' . $this->entityType), 'label' => mtrans($this->entityType, 'download_' . $this->entityType),
'url' => 'javascript:submitForm_'.$this->entityType.'("download")', 'url' => 'javascript:submitForm_'.$this->entityType.'("download")',
]; ];
if (Utils::isSelfHost() || auth()->user()->isPaidPro()) { if (auth()->user()->isTrusted()) {
$actions[] = [ $actions[] = [
'label' => mtrans($this->entityType, 'email_' . $this->entityType), 'label' => mtrans($this->entityType, 'email_' . $this->entityType),
'url' => 'javascript:submitForm_'.$this->entityType.'("emailInvoice")', 'url' => 'javascript:submitForm_'.$this->entityType.'("emailInvoice")',