-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from liberu-genealogy/sweep/add_to_email_resou…
…rces_under_appfilament Sweep: Add Email Resource with Dovecot and Postfix Configuration
- Loading branch information
Showing
1 changed file
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
|
||
namespace App\Filament\Admin\Resources; | ||
|
||
use App\Filament\Admin\Resources\EmailResource\Pages; | ||
use App\Models\Email; | ||
use Filament\Forms; | ||
use Filament\Resources\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Resources\Table; | ||
use Filament\Tables; | ||
|
||
class EmailResource extends Resource | ||
{ | ||
protected static ?string $model = Email::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-mail'; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('email') | ||
->email() | ||
->required() | ||
->maxLength(255), | ||
Forms\Components\TextInput::make('password') | ||
->password() | ||
->required() | ||
->maxLength(255), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('email') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('created_at') | ||
->dateTime(), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
Tables\Actions\DeleteAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ManageEmails::route('/'), | ||
]; | ||
} | ||
|
||
protected function handleRecordCreation(array $data): Email | ||
{ | ||
$email = Email::create($data); | ||
|
||
// Generate Dovecot configuration | ||
$dovecotConfig = $this->generateDovecotConfig($email); | ||
Storage::disk('dovecot')->put($email->email, $dovecotConfig); | ||
|
||
// Generate Postfix configuration | ||
$postfixConfig = $this->generatePostfixConfig($email); | ||
Storage::disk('postfix')->put($email->email, $postfixConfig); | ||
|
||
// Restart Dovecot and Postfix containers | ||
$this->restartContainers(); | ||
|
||
return $email; | ||
} | ||
|
||
protected function handleRecordUpdate(Email $email, array $data): Email | ||
{ | ||
$email->update($data); | ||
|
||
// Update Dovecot configuration | ||
$dovecotConfig = $this->generateDovecotConfig($email); | ||
Storage::disk('dovecot')->put($email->email, $dovecotConfig); | ||
|
||
// Update Postfix configuration | ||
$postfixConfig = $this->generatePostfixConfig($email); | ||
Storage::disk('postfix')->put($email->email, $postfixConfig); | ||
|
||
// Restart Dovecot and Postfix containers | ||
$this->restartContainers(); | ||
|
||
return $email; | ||
} | ||
|
||
protected function handleRecordDeletion(Email $email) | ||
{ | ||
// Remove Dovecot configuration | ||
Storage::disk('dovecot')->delete($email->email); | ||
|
||
// Remove Postfix configuration | ||
Storage::disk('postfix')->delete($email->email); | ||
|
||
// Restart Dovecot and Postfix containers | ||
$this->restartContainers(); | ||
|
||
$email->delete(); | ||
} | ||
|
||
protected function generateDovecotConfig(Email $email): string | ||
{ | ||
// Generate Dovecot configuration based on $email | ||
// ... | ||
} | ||
|
||
protected function generatePostfixConfig(Email $email): string | ||
{ | ||
// Generate Postfix configuration based on $email | ||
// ... | ||
} | ||
|
||
protected function restartContainers() | ||
{ | ||
// Restart Dovecot and Postfix containers | ||
// ... | ||
} | ||
} |