Skip to content

Commit

Permalink
Merge pull request #55 from nilede-bharat/feature/tenant-support
Browse files Browse the repository at this point in the history
tenant support logic added.
  • Loading branch information
marcogermani87 authored May 3, 2024
2 parents 063562e + 261f733 commit 0cd753b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/filament-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
'can_access' => [
'role' => [],
],
// 'tenant_model' => \App\Models\Team::class, 'pass model of relation to emails like team has many emails'
];
2 changes: 1 addition & 1 deletion database/migrations/create_filament_email_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ return new class extends Migration
{
Schema::create('filament_email_log', function (Blueprint $table) {
$table->id();

$table->foreignId('tenant_id')->nullable();
$table->string('from')->nullable();
$table->string('to')->nullable();
$table->string('cc')->nullable();
Expand Down
2 changes: 2 additions & 0 deletions src/Listeners/FilamentEmailLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace RickDBCN\FilamentEmail\Listeners;

use Filament\Facades\Filament;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use RickDBCN\FilamentEmail\Models\Email;
Expand Down Expand Up @@ -58,6 +59,7 @@ public function handle(object $event): void
'raw_body' => $savePathRaw,
'sent_debug_info' => $rawMessage->getDebug(),
'attachments' => ! empty($attachments) ? $attachments : null,
'tenant_id' => Filament::getTenant()?->id ?? auth()->id(),
]);

}
Expand Down
10 changes: 8 additions & 2 deletions src/Models/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ class Email extends Model
'attachments' => 'json',
];

public function team()
{
return $this->hasOne(config('filament-email')['tenant_model'], 'id', 'tenant_id');
}

public static function boot()
{
parent::boot();

self::deleting(function ($record) {
$folderPath = null;
if (! empty($record->attachments)) {
if (!empty($record->attachments)) {
foreach ($record->attachments as $attachment) {
$filePath = storage_path('app'.DIRECTORY_SEPARATOR.$attachment['path']);
$filePath = storage_path('app' . DIRECTORY_SEPARATOR . $attachment['path']);
if (empty($folderPath)) {
$parts = explode(DIRECTORY_SEPARATOR, $filePath);
array_pop($parts);
Expand All @@ -60,6 +65,7 @@ public static function boot()
}
}
}

$savePathRaw = storage_path('app'.DIRECTORY_SEPARATOR.$record->raw_body);
if (! is_dir($savePathRaw) && file_exists($savePathRaw)) {
if (empty($folderPath)) {
Expand Down

0 comments on commit 0cd753b

Please sign in to comment.