mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Attach links instead of files for attachments that are greater than 3mb in size
This commit is contained in:
parent
6d07e78280
commit
46bda415c2
@ -176,25 +176,17 @@ class NinjaMailerJob implements ShouldQueue
|
||||
* this merges a text string with a json object
|
||||
* need to harvest the ->Message property using the following
|
||||
*/
|
||||
if(stripos($e->getMessage(), 'code 406') || stripos($e->getMessage(), 'code 300'))
|
||||
if(stripos($e->getMessage(), 'code 406') || stripos($e->getMessage(), 'code 300') || stripos($e->getMessage(), 'code 413'))
|
||||
{
|
||||
|
||||
$message = "Either Attachment too large, or recipient has been suppressed.";
|
||||
|
||||
$this->fail();
|
||||
$this->logMailError($e->getMessage(), $this->company->clients()->first());
|
||||
$this->cleanUpMailers();
|
||||
|
||||
return;
|
||||
|
||||
// $response = $e->getResponse();
|
||||
// $message_body = json_decode($response->getBody()->getContents());
|
||||
|
||||
// if($message_body && property_exists($message_body, 'Message')){
|
||||
// $message = $message_body->Message;
|
||||
// }
|
||||
|
||||
/*Do not retry if this is a postmark specific issue such as invalid recipient. */
|
||||
|
||||
}
|
||||
|
||||
//only report once, not on all tries
|
||||
|
@ -27,6 +27,8 @@ class BaseEmailEngine implements EngineInterface
|
||||
|
||||
public $attachments = [];
|
||||
|
||||
public $attachment_links = [];
|
||||
|
||||
public $link;
|
||||
|
||||
public $text;
|
||||
@ -37,6 +39,8 @@ class BaseEmailEngine implements EngineInterface
|
||||
|
||||
public $text_footer;
|
||||
|
||||
public int $max_attachment_size = 3000000;
|
||||
|
||||
public function setFooter($footer)
|
||||
{
|
||||
$this->footer = $footer;
|
||||
@ -95,6 +99,14 @@ class BaseEmailEngine implements EngineInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAttachmentLinks($links)
|
||||
{
|
||||
$this->attachment_links = array_merge($this->getAttachmentLinks(), $links);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function setViewLink($link)
|
||||
{
|
||||
$this->link = $link;
|
||||
@ -131,6 +143,11 @@ class BaseEmailEngine implements EngineInterface
|
||||
return $this->attachments;
|
||||
}
|
||||
|
||||
public function getAttachmentLinks()
|
||||
{
|
||||
return $this->attachment_links;
|
||||
}
|
||||
|
||||
public function getFooter()
|
||||
{
|
||||
return $this->footer;
|
||||
|
@ -18,6 +18,7 @@ use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class CreditEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
@ -136,11 +137,19 @@ class CreditEmailEngine extends BaseEmailEngine
|
||||
|
||||
// Storage::url
|
||||
foreach ($this->credit->documents as $document) {
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]);
|
||||
}
|
||||
|
||||
foreach ($this->credit->company->documents as $document) {
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ use App\Utils\Number;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class InvoiceEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
@ -136,13 +137,22 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
//attach third party documents
|
||||
if ($this->client->getSetting('document_email_attachment') !== false && $this->invoice->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) {
|
||||
|
||||
|
||||
// Storage::url
|
||||
foreach ($this->invoice->documents as $document) {
|
||||
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
}
|
||||
|
||||
foreach ($this->invoice->company->documents as $document) {
|
||||
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
}
|
||||
|
||||
$line_items = $this->invoice->line_items;
|
||||
@ -160,7 +170,12 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
->cursor()
|
||||
->each(function ($expense) {
|
||||
foreach ($expense->documents as $document) {
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -176,7 +191,12 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
->cursor()
|
||||
->each(function ($task) {
|
||||
foreach ($task->documents as $document) {
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class PaymentEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
@ -100,7 +101,11 @@ class PaymentEmailEngine extends BaseEmailEngine
|
||||
if ($this->client->getSetting('document_email_attachment') !== false)
|
||||
{
|
||||
foreach ($invoice->documents as $document) {
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\VendorHtmlEngine;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class PurchaseOrderEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
@ -126,11 +127,6 @@ class PurchaseOrderEmailEngine extends BaseEmailEngine
|
||||
->setTextBody($text_body);
|
||||
|
||||
if ($this->vendor->getSetting('pdf_email_attachment') !== false && $this->purchase_order->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) {
|
||||
// if (Ninja::isHosted()) {
|
||||
// $this->setAttachments([$this->purchase_order->pdf_file_path($this->invitation, 'url', true)]);
|
||||
// } else {
|
||||
// $this->setAttachments([$this->purchase_order->pdf_file_path($this->invitation)]);
|
||||
// }
|
||||
|
||||
$pdf = (new CreatePurchaseOrderPdf($this->invitation))->rawPdf();
|
||||
|
||||
@ -143,13 +139,19 @@ class PurchaseOrderEmailEngine extends BaseEmailEngine
|
||||
|
||||
// Storage::url
|
||||
foreach ($this->purchase_order->documents as $document) {
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
|
||||
// $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
|
||||
}
|
||||
|
||||
foreach ($this->purchase_order->company->documents as $document) {
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
|
||||
// $this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, 'file' => base64_encode($document->getFile())]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class QuoteEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
@ -128,11 +129,19 @@ class QuoteEmailEngine extends BaseEmailEngine
|
||||
|
||||
// Storage::url
|
||||
foreach ($this->quote->documents as $document) {
|
||||
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
}
|
||||
|
||||
foreach ($this->quote->company->documents as $document) {
|
||||
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
|
||||
if($document->size > $this->max_attachment_size)
|
||||
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
|
||||
else
|
||||
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => NULL, ]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,7 @@ class TemplateEmail extends Mailable
|
||||
'company' => $company,
|
||||
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
|
||||
'logo' => $this->company->present()->logo($settings),
|
||||
'links' => $this->build_email->getAttachmentLinks(),
|
||||
]);
|
||||
|
||||
foreach ($this->build_email->getAttachments() as $file) {
|
||||
|
@ -109,6 +109,7 @@ class VendorTemplateEmail extends Mailable
|
||||
'company' => $this->company,
|
||||
'whitelabel' => $this->vendor->user->account->isPaid() ? true : false,
|
||||
'logo' => $this->company->present()->logo($settings),
|
||||
'links' => $this->build_email->getAttachmentLinks(),
|
||||
]);
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
supported-color-schemes: light dark;
|
||||
}
|
||||
@if(isset($settings) && $settings->email_style === 'dark')
|
||||
body {
|
||||
body {
|
||||
background-color: #1a1a1a !important;
|
||||
color: #ffffff !important;
|
||||
}
|
||||
@ -109,6 +109,21 @@
|
||||
z-index:200 !important;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.doc_links {
|
||||
|
||||
padding-bottom: 10px;
|
||||
display: inline-block;
|
||||
|
||||
}
|
||||
|
||||
a {
|
||||
|
||||
text-decoration: none;
|
||||
color: inherit !important;
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<!--[if gte mso 9]>
|
||||
@ -160,7 +175,15 @@
|
||||
style="display: inline-block;background-color: {{ $primary_color }}; color: #ffffff; text-transform: uppercase;letter-spacing: 2px; text-decoration: none; font-size: 13px; font-weight: 600;">
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@isset($links)
|
||||
@foreach($links as $link)
|
||||
{!! $link ?? '' !!}<br>
|
||||
@endforeach
|
||||
@endisset
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
@ -64,4 +64,48 @@ class CompanyDocumentsTest extends TestCase
|
||||
|
||||
// $this->assertFalse(Storage::exists($document->url));
|
||||
}
|
||||
|
||||
// public function testSignedRoutes()
|
||||
// {
|
||||
|
||||
// $company_key = $this->company->company_key;
|
||||
|
||||
// $original_count = Document::whereCompanyId($this->company->id)->count();
|
||||
|
||||
// $image = UploadedFile::fake()->image('avatar.jpg');
|
||||
|
||||
|
||||
// $document = (new UploadFile(
|
||||
// $image,
|
||||
// UploadFile::IMAGE,
|
||||
// $this->user,
|
||||
// $this->company,
|
||||
// $this->invoice))->handle();
|
||||
|
||||
// $this->assertNotNull($document);
|
||||
|
||||
// // $url = \Illuminate\Support\Facades\URL::signedRoute('api.documents.show', ['document' => $document->hashed_id]);
|
||||
// $url = \Illuminate\Support\Facades\URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]);
|
||||
|
||||
// nlog($url);
|
||||
|
||||
// $response = $this->withHeaders([
|
||||
// 'X-API-SECRET' => config('ninja.api_secret'),
|
||||
// 'X-API-TOKEN' => $this->token,
|
||||
// ])->get($url);
|
||||
|
||||
|
||||
// $content = $response->streamedContent();
|
||||
// nlog($content);
|
||||
|
||||
|
||||
// $response->assertStatus(200);
|
||||
|
||||
// $arr = $response->json();
|
||||
|
||||
|
||||
|
||||
// $this->assertFalse($arr);
|
||||
|
||||
// }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user