mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Updates for removing suppressions from emails
This commit is contained in:
parent
17e4962435
commit
6a4d19eea3
@ -14,6 +14,8 @@ namespace App\Http\Controllers;
|
||||
use App\Utils\Ninja;
|
||||
use App\Models\Client;
|
||||
use App\Models\Account;
|
||||
use App\Models\Company;
|
||||
use App\Models\SystemLog;
|
||||
use Postmark\PostmarkClient;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Factory\ClientFactory;
|
||||
@ -38,6 +40,7 @@ use App\Http\Requests\Client\UpdateClientRequest;
|
||||
use App\Http\Requests\Client\UploadClientRequest;
|
||||
use App\Http\Requests\Client\DestroyClientRequest;
|
||||
use App\Http\Requests\Client\ReactivateClientEmailRequest;
|
||||
use App\Jobs\PostMark\ProcessPostmarkWebhook;
|
||||
|
||||
/**
|
||||
* Class ClientController.
|
||||
@ -221,7 +224,7 @@ class ClientController extends BaseController
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(Client::withTrashed()->company()->whereIn('id', $request->ids));
|
||||
return $this->listResponse(Client::query()->withTrashed()->company()->whereIn('id', $request->ids));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,12 +323,42 @@ class ClientController extends BaseController
|
||||
* Reactivate a client email
|
||||
*
|
||||
* @param ReactivateClientEmailRequest $request
|
||||
* @param string $bounce_id
|
||||
* @param string $bounce_id //could also be the invitationId
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function reactivateEmail(ReactivateClientEmailRequest $request, string $bounce_id)
|
||||
{
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
if(stripos($bounce_id, '-') !== false){
|
||||
$log =
|
||||
SystemLog::query()
|
||||
->where('company_id', $user->company()->id)
|
||||
->where('type_id', SystemLog::TYPE_WEBHOOK_RESPONSE)
|
||||
->where('category_id', SystemLog::CATEGORY_MAIL)
|
||||
->whereJsonContains('log', ['MessageID' => $bounce_id])
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
|
||||
$resolved_bounce_id = false;
|
||||
|
||||
if($log && ($log?->log['ID'] ?? false)){
|
||||
$resolved_bounce_id = $log->log['ID'] ?? false;
|
||||
}
|
||||
|
||||
if(!$resolved_bounce_id){
|
||||
$ppwebhook = new ProcessPostmarkWebhook([]);
|
||||
$resolved_bounce_id = $ppwebhook->getBounceId($bounce_id);
|
||||
}
|
||||
|
||||
if(!$resolved_bounce_id){
|
||||
return response()->json(['message' => 'Bounce ID not found'], 400);
|
||||
}
|
||||
|
||||
$bounce_id = $resolved_bounce_id;
|
||||
}
|
||||
|
||||
$postmark = new PostmarkClient(config('services.postmark.token'));
|
||||
|
||||
try {
|
||||
|
@ -339,6 +339,32 @@ class ProcessPostmarkWebhook implements ShouldQueue
|
||||
}
|
||||
}
|
||||
|
||||
public function getRawMessage(string $message_id)
|
||||
{
|
||||
|
||||
$postmark = new PostmarkClient(config('services.postmark.token'));
|
||||
$messageDetail = $postmark->getOutboundMessageDetails($message_id);
|
||||
return $messageDetail;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getBounceId(string $message_id): ?int
|
||||
{
|
||||
|
||||
$messageDetail = $this->getRawMessage($message_id);
|
||||
|
||||
|
||||
$event = collect($messageDetail->messageevents)->first(function ($event) {
|
||||
|
||||
return $event?->Details?->BounceID ?? false;
|
||||
|
||||
});
|
||||
|
||||
return $event?->Details?->BounceID ?? null;
|
||||
|
||||
}
|
||||
|
||||
private function fetchMessage(): array
|
||||
{
|
||||
if(strlen($this->request['MessageID']) < 1){
|
||||
|
@ -306,10 +306,7 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
return $this->hasMany(ClientContact::class)->where('is_primary', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function company()
|
||||
public function company(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
@ -786,6 +786,26 @@ class Company extends BaseModel
|
||||
return $this->hasMany(CompanyUser::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function invoice_invitations(): HasMany
|
||||
{
|
||||
return $this->hasMany(InvoiceInvitation::class);
|
||||
}
|
||||
|
||||
public function quote_invitations(): HasMany
|
||||
{
|
||||
return $this->hasMany(QuoteInvitation::class);
|
||||
}
|
||||
|
||||
public function credit_invitations(): HasMany
|
||||
{
|
||||
return $this->hasMany(CreditInvitation::class);
|
||||
}
|
||||
|
||||
public function purchase_order_invitations(): HasMany
|
||||
{
|
||||
return $this->hasMany(PurchaseOrderInvitation::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \App\Models\User|null
|
||||
*/
|
||||
|
@ -33,6 +33,7 @@ class CreditInvitationTransformer extends EntityTransformer
|
||||
'created_at' => (int) $invitation->created_at,
|
||||
'email_status' => $invitation->email_status ?: '',
|
||||
'email_error' => (string) $invitation->email_error,
|
||||
'message_id' => (string) $invitation->message_id ?: '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ class InvoiceInvitationTransformer extends EntityTransformer
|
||||
'created_at' => (int) $invitation->created_at,
|
||||
'email_status' => $invitation->email_status ?: '',
|
||||
'email_error' => (string) $invitation->email_error,
|
||||
'message_id' => (string) $invitation->message_id ?: '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ class PurchaseOrderInvitationTransformer extends EntityTransformer
|
||||
'created_at' => (int) $invitation->created_at,
|
||||
'email_status' => $invitation->email_status ?: '',
|
||||
'email_error' => (string) $invitation->email_error,
|
||||
'message_id' => (string) $invitation->message_id ?: '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ class QuoteInvitationTransformer extends EntityTransformer
|
||||
'created_at' => (int) $invitation->created_at,
|
||||
'email_status' => $invitation->email_status ?: '',
|
||||
'email_error' => (string) $invitation->email_error,
|
||||
'message_id' => (string) $invitation->message_id ?: '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ class RecurringInvoiceInvitationTransformer extends EntityTransformer
|
||||
'created_at' => (int) $invitation->created_at,
|
||||
'email_status' => $invitation->email_status ?: '',
|
||||
'email_error' => (string) $invitation->email_error,
|
||||
'message_id' => (string) $invitation->message_id ?: '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user