1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Updates for unsubscribe

This commit is contained in:
David Bomba 2024-01-22 10:52:30 +11:00
parent 6052e44186
commit 48374cf009
4 changed files with 41 additions and 22 deletions

View File

@ -12,14 +12,15 @@
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use App\Models\ClientContact;
use App\Jobs\Mail\NinjaMailer;
use App\Jobs\Mail\NinjaMailerJob;
use App\Http\Controllers\Controller;
use App\Jobs\Mail\NinjaMailerObject;
use Illuminate\Support\Facades\Cache;
use App\Mail\Admin\ClientUnsubscribedObject;
use App\Models\ClientContact;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class EmailPreferencesController extends Controller
{
@ -42,14 +43,16 @@ class EmailPreferencesController extends Controller
$invitation->contact->is_locked = $request->action === 'unsubscribe' ? true : false;
$invitation->contact->push();
if ($invitation->contact->is_locked) {
if ($invitation->contact->is_locked && !Cache::has("unsubscribe_notitfication_suppression:{$invitation_key}")) {
$nmo = new NinjaMailerObject();
$nmo->mailable = new NinjaMailer((new ClientUnsubscribedObject($invitation->contact, $invitation->contact->company))->build());
$nmo->mailable = new NinjaMailer((new ClientUnsubscribedObject($invitation->contact, $invitation->contact->company, $invitation->contact->company->owner()->company_users()->first()->portalType() ?? true))->build());
$nmo->company = $invitation->contact->company;
$nmo->to_user = $invitation->contact->company->owner();
$nmo->settings = $invitation->contact->company->settings;
NinjaMailerJob::dispatch($nmo);
Cache::put("unsubscribe_notitfication_suppression:{$invitation_key}", true, 3600);
}
return back()->with('message', ctrans('texts.updated_settings'));

View File

@ -20,7 +20,8 @@ class ClientUnsubscribedObject
{
public function __construct(
public ClientContact $contact,
public Company $company
public Company $company,
private bool $use_react_link = false
) {
}
@ -36,12 +37,13 @@ class ClientUnsubscribedObject
$data = [
'title' => ctrans('texts.client_unsubscribed'),
'message' => ctrans('texts.client_unsubscribed_help', ['client' => $this->contact->present()->name()]),
'url' => $this->contact->client->portalUrl(false),
'content' => ctrans('texts.client_unsubscribed_help', ['client' => $this->contact->present()->name()]),
'url' => $this->contact->getAdminLink($this->use_react_link),
'button' => ctrans('texts.view_client'),
'signature' => $this->company->settings->email_signature,
'settings' => $this->company->settings,
'logo' => $this->company->present()->logo(),
'text_body' => "\n\n".ctrans('texts.client_unsubscribed_help', ['client' => $this->contact->present()->name()])."\n\n",
];
$mail_obj = new \stdClass();
@ -49,6 +51,7 @@ class ClientUnsubscribedObject
$mail_obj->data = $data;
$mail_obj->markdown = 'email.admin.generic';
$mail_obj->tag = $this->company->company_key;
$mail_obj->text_view = 'email.template.text';
return $mail_obj;
}

View File

@ -11,22 +11,23 @@
namespace App\Models;
use App\Jobs\Mail\NinjaMailer;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Mail\ClientContact\ClientContactResetPasswordObject;
use App\Models\Presenters\ClientContactPresenter;
use App\Utils\Ninja;
use Illuminate\Support\Str;
use App\Jobs\Mail\NinjaMailer;
use App\Utils\Traits\AppSetup;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use Illuminate\Support\Facades\Cache;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Laracasts\Presenter\PresentableTrait;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Presenters\ClientContactPresenter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Contracts\Translation\HasLocalePreference;
use App\Mail\ClientContact\ClientContactResetPasswordObject;
/**
* Class ClientContact
@ -339,4 +340,16 @@ class ClientContact extends Authenticatable implements HasLocalePreference
return '';
}
}
public function getAdminLink($use_react_link = false): string
{
return $use_react_link ? $this->getReactLink() : config('ninja.app_url');
}
private function getReactLink(): string
{
return config('ninja.react_url')."/#/clients/{$this->client->hashed_id}";
}
}

View File

@ -5213,8 +5213,8 @@ $lang = array(
'nordigen_requisition_body' => 'Access to bank account feeds has expired as set in End User Agreement. <br><br>Please log into Invoice Ninja and re-authenticate with your banks to continue receiving transactions.',
'participant' => 'Participant',
'participant_name' => 'Participant name',
'client_unsubscribed' => 'Client changed e-mail preferences',
'client_unsubscribed_help' => 'Client :client changed preferences and unsubscribed from e-mails.',
'client_unsubscribed' => 'Client unsubscribed from emails.',
'client_unsubscribed_help' => 'Client :client has unsubscribed from your e-mails. The client needs to consent to receive future emails from you.',
'resubscribe' => 'Resubscribe',
'subscribe' => 'Subscribe',
'subscribe_help' => 'You are currently subscribed and will continue to receive email communications.',