diff --git a/app-modules/engagement/database/factories/EngagementFactory.php b/app-modules/engagement/database/factories/EngagementFactory.php index 14f70a0a1c..0b1cd3fe7b 100644 --- a/app-modules/engagement/database/factories/EngagementFactory.php +++ b/app-modules/engagement/database/factories/EngagementFactory.php @@ -70,8 +70,7 @@ public function definition(): array return $sender->getKey(); }, 'subject' => fake()->sentence, - 'body' => fake()->paragraph, - 'body_json' => ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => fake()->paragraph]]]]], + 'body' => ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => fake()->paragraph]]]]], 'deliver_at' => fake()->dateTimeBetween('-1 year', '-1 day'), 'scheduled' => true, ]; diff --git a/app-modules/engagement/database/migrations/2023_08_17_161256_create_engagements_table.php b/app-modules/engagement/database/migrations/2023_08_17_161256_create_engagements_table.php index 465b2b4035..5e19ed9d62 100644 --- a/app-modules/engagement/database/migrations/2023_08_17_161256_create_engagements_table.php +++ b/app-modules/engagement/database/migrations/2023_08_17_161256_create_engagements_table.php @@ -48,8 +48,7 @@ public function up(): void $table->string('recipient_id')->nullable(); $table->string('recipient_type')->nullable(); $table->string('subject')->nullable(); - $table->longText('body')->nullable(); - $table->json('body_json')->nullable(); + $table->json('body')->nullable(); $table->boolean('scheduled')->default(true); $table->timestamp('deliver_at'); $table->timestamps(); diff --git a/app-modules/engagement/database/migrations/2023_11_22_182233_create_sms_templates_table.php b/app-modules/engagement/database/migrations/2023_11_22_182233_create_sms_templates_table.php index f0b7383c0a..ab059baeb2 100644 --- a/app-modules/engagement/database/migrations/2023_11_22_182233_create_sms_templates_table.php +++ b/app-modules/engagement/database/migrations/2023_11_22_182233_create_sms_templates_table.php @@ -45,7 +45,8 @@ public function up(): void $table->uuid('id')->primary(); $table->string('name'); $table->text('description')->nullable(); - $table->text('content'); + $table->json('content'); + $table->foreignUuid('user_id')->nullable()->constrained()->nullOnDelete(); $table->timestamps(); }); } diff --git a/app-modules/engagement/src/Actions/CreateEngagementBatch.php b/app-modules/engagement/src/Actions/CreateEngagementBatch.php index 2d28e1b454..8b8d7112ce 100644 --- a/app-modules/engagement/src/Actions/CreateEngagementBatch.php +++ b/app-modules/engagement/src/Actions/CreateEngagementBatch.php @@ -77,7 +77,6 @@ public function handle(): void 'recipient_type' => $record->getMorphClass(), 'subject' => $this->data->subject, 'body' => $this->data->body, - 'body_json' => $this->data->bodyJson, 'scheduled' => false, ]); diff --git a/app-modules/engagement/src/Actions/EngagementSmsChannelDelivery.php b/app-modules/engagement/src/Actions/EngagementSmsChannelDelivery.php index de3d33e4f0..6e953c9363 100644 --- a/app-modules/engagement/src/Actions/EngagementSmsChannelDelivery.php +++ b/app-modules/engagement/src/Actions/EngagementSmsChannelDelivery.php @@ -45,14 +45,19 @@ public function deliver(): void { $client = new Client(config('services.twilio.account_sid'), config('services.twilio.auth_token')); + $messageContent = [ + 'from' => config('services.twilio.from_number'), + 'body' => $this->deliverable->engagement->getBody(), + ]; + + if (! app()->environment('local')) { + $messageContent['statusCallback'] = route('inbound.webhook.twilio', ['event' => 'status_callback']); + } + try { $message = $client->messages->create( ! is_null(config('services.twilio.test_to_number')) ? config('services.twilio.test_to_number') : $this->deliverable->engagement->recipient->mobile, - [ - 'from' => config('services.twilio.from_number'), - 'body' => $this->deliverable->engagement->getBody(), - 'statusCallback' => route('inbound.webhook.twilio', ['event' => 'status_callback']), - ] + $messageContent ); $this->deliverable->update([ diff --git a/app-modules/engagement/src/DataTransferObjects/EngagementBatchCreationData.php b/app-modules/engagement/src/DataTransferObjects/EngagementBatchCreationData.php index 4e4ab2e23e..d83e98b0ed 100644 --- a/app-modules/engagement/src/DataTransferObjects/EngagementBatchCreationData.php +++ b/app-modules/engagement/src/DataTransferObjects/EngagementBatchCreationData.php @@ -47,7 +47,6 @@ public function __construct( public Collection $records, public string $deliveryMethod, public ?string $subject = null, - public ?string $body = null, - public ?array $bodyJson = null, + public ?array $body = null, ) {} } diff --git a/app-modules/engagement/src/Filament/Actions/BulkEngagementAction.php b/app-modules/engagement/src/Filament/Actions/BulkEngagementAction.php index 0e917ece38..aff584776b 100644 --- a/app-modules/engagement/src/Filament/Actions/BulkEngagementAction.php +++ b/app-modules/engagement/src/Filament/Actions/BulkEngagementAction.php @@ -42,7 +42,6 @@ use Filament\Forms\Components\Select; use FilamentTiptapEditor\TiptapEditor; use Filament\Forms\Components\Checkbox; -use Filament\Forms\Components\Textarea; use Filament\Tables\Actions\BulkAction; use Filament\Forms\Components\TextInput; use Illuminate\Database\Eloquent\Builder; @@ -55,6 +54,7 @@ use Assist\Engagement\Enums\EngagementDeliveryMethod; use Assist\Engagement\DataTransferObjects\EngagementBatchCreationData; use Assist\Engagement\Filament\Actions\Contracts\HasBulkEngagementAction; +use Assist\Engagement\Filament\Resources\EngagementResource\Fields\EngagementSmsBodyField; class BulkEngagementAction { @@ -84,7 +84,7 @@ public static function make(string $context) ->placeholder(__('Subject')) ->hidden(fn (Get $get): bool => $get('delivery_method') === EngagementDeliveryMethod::Sms->value) ->columnSpanFull(), - TiptapEditor::make('body_json') + TiptapEditor::make('body') ->label('Body') ->mergeTags([ 'student full name', @@ -146,13 +146,7 @@ public static function make(string $context) ->hidden(fn (Get $get): bool => $get('delivery_method') === EngagementDeliveryMethod::Sms->value) ->helperText('You can insert student information by typing {{ and choosing a merge value to insert.') ->columnSpanFull(), - Textarea::make('body') - ->placeholder('Body') - ->required() - ->maxLength(320) // https://www.twilio.com/docs/glossary/what-sms-character-limit#:~:text=Twilio's%20platform%20supports%20long%20messages,best%20deliverability%20and%20user%20experience. - ->helperText('The body of your message can be up to 320 characters long.') - ->visible(fn (Get $get): bool => $get('delivery_method') === EngagementDeliveryMethod::Sms->value) - ->columnSpanFull(), + EngagementSmsBodyField::make(context: 'create'), ]), ]) ->action(function (Collection $records, array $data) { @@ -162,7 +156,6 @@ public static function make(string $context) 'deliveryMethod' => $data['delivery_method'], 'subject' => $data['subject'] ?? null, 'body' => $data['body'] ?? null, - 'bodyJson' => $data['body_json'] ?? null, ])); }) ->modalSubmitActionLabel('Send') diff --git a/app-modules/engagement/src/Filament/Actions/CreateOnDemandEngagement.php b/app-modules/engagement/src/Filament/Actions/CreateOnDemandEngagement.php index 93bf8fe01a..944cc247be 100644 --- a/app-modules/engagement/src/Filament/Actions/CreateOnDemandEngagement.php +++ b/app-modules/engagement/src/Filament/Actions/CreateOnDemandEngagement.php @@ -46,7 +46,6 @@ public function __invoke(Model $educatable, array $data): void $engagement = $educatable->engagements()->create([ 'subject' => $data['subject'] ?? null, 'body' => $data['body'] ?? null, - 'body_json' => $data['body_json'] ?? null, 'scheduled' => false, ]); diff --git a/app-modules/engagement/src/Filament/Resources/EngagementResource/Fields/EngagementSmsBodyField.php b/app-modules/engagement/src/Filament/Resources/EngagementResource/Fields/EngagementSmsBodyField.php new file mode 100644 index 0000000000..d8a7a2499b --- /dev/null +++ b/app-modules/engagement/src/Filament/Resources/EngagementResource/Fields/EngagementSmsBodyField.php @@ -0,0 +1,129 @@ + + + Copyright © 2022-2023, Canyon GBS LLC. All rights reserved. + + Advising App™ is licensed under the Elastic License 2.0. For more details, + see https://github.com/canyongbs/advisingapp/blob/main/LICENSE. + + Notice: + + - You may not provide the software to third parties as a hosted or managed + service, where the service provides users with access to any substantial set of + the features or functionality of the software. + - You may not move, change, disable, or circumvent the license key functionality + in the software, and you may not remove or obscure any functionality in the + software that is protected by the license key. + - You may not alter, remove, or obscure any licensing, copyright, or other notices + of the licensor in the software. Any use of the licensor’s trademarks is subject + to applicable law. + - Canyon GBS LLC respects the intellectual property rights of others and expects the + same in return. Canyon GBS™ and Advising App™ are registered trademarks of + Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks + vigorously. + - The software solution, including services, infrastructure, and code, is offered as a + Software as a Service (SaaS) by Canyon GBS LLC. + - Use of this software implies agreement to the license terms and conditions as stated + in the Elastic License 2.0. + + For more information or inquiries please visit our website at + https://www.canyongbs.com or contact us via email at legal@canyongbs.com. + + +*/ + +namespace Assist\Engagement\Filament\Resources\EngagementResource\Fields; + +use Filament\Forms\Get; +use Filament\Forms\Set; +use Filament\Forms\Form; +use Filament\Forms\Components\Field; +use Filament\Forms\Components\Select; +use FilamentTiptapEditor\TiptapEditor; +use Filament\Forms\Components\Checkbox; +use Assist\Engagement\Models\Engagement; +use Assist\Engagement\Models\SmsTemplate; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Query\Expression; +use FilamentTiptapEditor\Enums\TiptapOutput; +use Filament\Forms\Components\Actions\Action; +use Assist\Engagement\Enums\EngagementDeliveryMethod; +use Filament\Resources\RelationManagers\RelationManager; + +class EngagementSmsBodyField +{ + public static function make(string $context, ?Form $form = null) + { + // TODO Implement length validation (320 characters max) + // https://www.twilio.com/docs/glossary/what-sms-character-limit#:~:text=Twilio's%20platform%20supports%20long%20messages,best%20deliverability%20and%20user%20experience. + return TiptapEditor::make('body') + ->label('Body') + ->mergeTags([ + 'student full name', + 'student email', + ]) + ->showMergeTagsInBlocksPanel(is_null($form) ? false : ! ($form->getLivewire() instanceof RelationManager)) + ->profile('sms') + ->output(TiptapOutput::Json) + ->required() + ->hintAction(fn (TiptapEditor $component) => Action::make('loadSmsTemplate') + ->form([ + Select::make('smsTemplate') + ->searchable() + ->options(function (Get $get): array { + return SmsTemplate::query() + ->when( + $get('onlyMyTemplates'), + fn (Builder $query) => $query->whereBelongsTo(auth()->user()) + ) + ->orderBy('name') + ->limit(50) + ->pluck('name', 'id') + ->toArray(); + }) + ->getSearchResultsUsing(function (Get $get, string $search): array { + return SmsTemplate::query() + ->when( + $get('onlyMyTemplates'), + fn (Builder $query) => $query->whereBelongsTo(auth()->user()) + ) + ->when( + $get('onlyMyTeamTemplates'), + fn (Builder $query) => $query->whereIn('user_id', auth()->user()->teams->users->pluck('id')) + ) + ->where(new Expression('lower(name)'), 'like', "%{$search}%") + ->orderBy('name') + ->limit(50) + ->pluck('name', 'id') + ->toArray(); + }), + Checkbox::make('onlyMyTemplates') + ->label('Only show my templates') + ->live() + ->afterStateUpdated(fn (Set $set) => $set('smsTemplate', null)), + Checkbox::make('onlyMyTeamTemplates') + ->label("Only show my team's templates") + ->live() + ->afterStateUpdated(fn (Set $set) => $set('smsTemplate', null)), + ]) + ->action(function (array $data) use ($component) { + $template = SmsTemplate::find($data['smsTemplate']); + + if (! $template) { + return; + } + + $component->state($template->content); + })) + ->when($context === 'create', function (Field $field) { + $field->hidden(fn (Get $get): bool => $get('delivery_method') === EngagementDeliveryMethod::Email->value); + }) + ->when($context === 'edit', function (Field $field) { + $field->visible(fn (Engagement $record): bool => $record->deliverable->channel === EngagementDeliveryMethod::Sms); + }) + ->helperText('You can insert student information by typing {{ and choosing a tag to insert.') + ->columnSpanFull(); + } +} diff --git a/app-modules/engagement/src/Filament/Resources/EngagementResource/Pages/CreateEngagement.php b/app-modules/engagement/src/Filament/Resources/EngagementResource/Pages/CreateEngagement.php index 31bea3923f..76c61296e2 100644 --- a/app-modules/engagement/src/Filament/Resources/EngagementResource/Pages/CreateEngagement.php +++ b/app-modules/engagement/src/Filament/Resources/EngagementResource/Pages/CreateEngagement.php @@ -45,7 +45,6 @@ use FilamentTiptapEditor\TiptapEditor; use Filament\Forms\Components\Checkbox; use Filament\Forms\Components\Fieldset; -use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\Expression; @@ -61,6 +60,7 @@ use Filament\Resources\RelationManagers\RelationManager; use Assist\Engagement\Actions\CreateEngagementDeliverable; use Assist\Engagement\Filament\Resources\EngagementResource; +use Assist\Engagement\Filament\Resources\EngagementResource\Fields\EngagementSmsBodyField; class CreateEngagement extends CreateRecord { @@ -84,7 +84,7 @@ public function form(Form $form): Form ->placeholder(__('Subject')) ->hidden(fn (Get $get): bool => $get('delivery_method') === EngagementDeliveryMethod::Sms->value) ->columnSpanFull(), - TiptapEditor::make('body_json') + TiptapEditor::make('body') ->label('Body') ->mergeTags([ 'student full name', @@ -146,13 +146,7 @@ public function form(Form $form): Form ->hidden(fn (Get $get): bool => $get('delivery_method') === EngagementDeliveryMethod::Sms->value) ->helperText('You can insert student information by typing {{ and choosing a merge value to insert.') ->columnSpanFull(), - Textarea::make('body') - ->placeholder('Body') - ->required() - ->maxLength(320) // https://www.twilio.com/docs/glossary/what-sms-character-limit#:~:text=Twilio's%20platform%20supports%20long%20messages,best%20deliverability%20and%20user%20experience. - ->helperText('The body of your message can be up to 320 characters long.') - ->visible(fn (Get $get): bool => $get('delivery_method') === EngagementDeliveryMethod::Sms->value) - ->columnSpanFull(), + EngagementSmsBodyField::make(context: 'create', form: $form), ]), MorphToSelect::make('recipient') ->label('Recipient') diff --git a/app-modules/engagement/src/Filament/Resources/EngagementResource/Pages/EditEngagement.php b/app-modules/engagement/src/Filament/Resources/EngagementResource/Pages/EditEngagement.php index 16a20af328..f1fd2960d2 100644 --- a/app-modules/engagement/src/Filament/Resources/EngagementResource/Pages/EditEngagement.php +++ b/app-modules/engagement/src/Filament/Resources/EngagementResource/Pages/EditEngagement.php @@ -48,7 +48,6 @@ use FilamentTiptapEditor\TiptapEditor; use Filament\Forms\Components\Checkbox; use Filament\Forms\Components\Fieldset; -use Filament\Forms\Components\Textarea; use Assist\Engagement\Models\Engagement; use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\EditRecord; @@ -60,7 +59,9 @@ use FilamentTiptapEditor\Enums\TiptapOutput; use Filament\Forms\Components\Actions\Action; use Filament\Forms\Components\DateTimePicker; +use Assist\Engagement\Enums\EngagementDeliveryMethod; use Assist\Engagement\Filament\Resources\EngagementResource; +use Assist\Engagement\Filament\Resources\EngagementResource\Fields\EngagementSmsBodyField; class EditEngagement extends EditRecord { @@ -74,8 +75,9 @@ public function form(Form $form): Form ->autofocus() ->required() ->placeholder(__('Subject')) - ->columnSpanFull(), - TiptapEditor::make('body_json') + ->columnSpanFull() + ->visible(fn (Engagement $record): bool => $record->deliverable->channel === EngagementDeliveryMethod::Email), + TiptapEditor::make('body') ->label('Body') ->mergeTags([ 'student full name', @@ -133,17 +135,11 @@ public function form(Form $form): Form $component->state($template->content); })) - ->visible(fn (Engagement $record): bool => filled($record->body_json)) + ->visible(fn (Engagement $record): bool => $record->deliverable->channel === EngagementDeliveryMethod::Email) ->showMergeTagsInBlocksPanel($form->getLivewire() instanceof Page) ->helperText('You can insert student information by typing {{ and choosing a merge value to insert.') ->columnSpanFull(), - Textarea::make('body') - ->placeholder('Body') - ->required() - ->maxLength(320) // https://www.twilio.com/docs/glossary/what-sms-character-limit#:~:text=Twilio's%20platform%20supports%20long%20messages,best%20deliverability%20and%20user%20experience. - ->helperText('The body of your message can be up to 320 characters long.') - ->visible(fn (Engagement $record): bool => blank($record->body_json)) - ->columnSpanFull(), + EngagementSmsBodyField::make(context: 'edit', form: $form), MorphToSelect::make('recipient') ->label('Recipient') ->searchable() diff --git a/app-modules/engagement/src/Filament/Resources/SmsTemplateResource/Pages/CreateSmsTemplate.php b/app-modules/engagement/src/Filament/Resources/SmsTemplateResource/Pages/CreateSmsTemplate.php index 600954b10a..49d6a4e0ea 100644 --- a/app-modules/engagement/src/Filament/Resources/SmsTemplateResource/Pages/CreateSmsTemplate.php +++ b/app-modules/engagement/src/Filament/Resources/SmsTemplateResource/Pages/CreateSmsTemplate.php @@ -38,11 +38,12 @@ use Filament\Forms\Form; use Filament\Resources\Resource; +use FilamentTiptapEditor\TiptapEditor; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; -use Filament\Forms\Components\RichEditor; use App\Filament\Pages\EmailConfiguration; use Filament\Resources\Pages\CreateRecord; +use FilamentTiptapEditor\Enums\TiptapOutput; use Assist\Engagement\Filament\Resources\SmsTemplateResource; class CreateSmsTemplate extends CreateRecord @@ -68,13 +69,17 @@ public function form(Form $form): Form ->autocomplete(false), Textarea::make('description') ->string(), - RichEditor::make('content') - ->toolbarButtons([ - 'link', - 'redo', - 'undo', + // TODO Implement length validation (320 characters max) + // https://www.twilio.com/docs/glossary/what-sms-character-limit#:~:text=Twilio's%20platform%20supports%20long%20messages,best%20deliverability%20and%20user%20experience. + TiptapEditor::make('content') + ->mergeTags([ + 'student full name', + 'student email', ]) - ->maxLength(320) // https://www.twilio.com/docs/glossary/what-sms-character-limit#:~:text=Twilio's%20platform%20supports%20long%20messages,best%20deliverability%20and%20user%20experience. + ->profile('sms') + ->output(TiptapOutput::Json) + ->columnSpanFull() + ->extraInputAttributes(['style' => 'min-height: 12rem;']) ->required(), ]); } diff --git a/app-modules/engagement/src/Filament/Resources/SmsTemplateResource/Pages/EditSmsTemplate.php b/app-modules/engagement/src/Filament/Resources/SmsTemplateResource/Pages/EditSmsTemplate.php index 4653be22f0..085396b144 100644 --- a/app-modules/engagement/src/Filament/Resources/SmsTemplateResource/Pages/EditSmsTemplate.php +++ b/app-modules/engagement/src/Filament/Resources/SmsTemplateResource/Pages/EditSmsTemplate.php @@ -38,11 +38,12 @@ use Filament\Forms\Form; use Filament\Actions\DeleteAction; +use App\Filament\Fields\TiptapEditor; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\EditRecord; -use Filament\Forms\Components\RichEditor; use App\Filament\Pages\EmailConfiguration; +use FilamentTiptapEditor\Enums\TiptapOutput; use Assist\Engagement\Filament\Resources\SmsTemplateResource; class EditSmsTemplate extends EditRecord @@ -68,13 +69,15 @@ public function form(Form $form): Form ->autocomplete(false), Textarea::make('description') ->string(), - RichEditor::make('content') - ->toolbarButtons([ - 'link', - 'redo', - 'undo', + TiptapEditor::make('content') + ->mergeTags([ + 'student full name', + 'student email', ]) - ->maxLength(320) // https://www.twilio.com/docs/glossary/what-sms-character-limit#:~:text=Twilio's%20platform%20supports%20long%20messages,best%20deliverability%20and%20user%20experience. + ->profile('sms') + ->output(TiptapOutput::Json) + ->columnSpanFull() + ->extraInputAttributes(['style' => 'min-height: 12rem;']) ->required(), ]); } diff --git a/app-modules/engagement/src/Models/Engagement.php b/app-modules/engagement/src/Models/Engagement.php index 33656a7aee..d55296ea0b 100644 --- a/app-modules/engagement/src/Models/Engagement.php +++ b/app-modules/engagement/src/Models/Engagement.php @@ -71,7 +71,6 @@ class Engagement extends BaseModel implements Auditable, CanTriggerAutoSubscript 'engagement_batch_id', 'subject', 'body', - 'body_json', 'recipient_id', 'recipient_type', 'scheduled', @@ -79,7 +78,7 @@ class Engagement extends BaseModel implements Auditable, CanTriggerAutoSubscript ]; protected $casts = [ - 'body_json' => 'array', + 'body' => 'array', 'deliver_at' => 'datetime', 'scheduled' => 'boolean', ]; @@ -185,12 +184,8 @@ public function getSubscribable(): ?Subscribable public function getBody(): string { - if (blank($this->body_json)) { - return $this->body; - } - return app(GenerateEmailMarkdownContent::class)( - [$this->body_json], + [$this->body], $this->getMergeData(), ); } diff --git a/app-modules/engagement/src/Models/EngagementBatch.php b/app-modules/engagement/src/Models/EngagementBatch.php index 5af9c928b5..7ca3c8b2b4 100644 --- a/app-modules/engagement/src/Models/EngagementBatch.php +++ b/app-modules/engagement/src/Models/EngagementBatch.php @@ -71,7 +71,6 @@ public static function executeFromCampaignAction(CampaignAction $action): bool|s 'deliveryMethod' => $action->data['delivery_method'], 'subject' => $action->data['subject'] ?? null, 'body' => $action->data['body'] ?? null, - 'bodyJson' => $action->data['bodyJson'] ?? null, ])); return true; diff --git a/app-modules/engagement/src/Models/SmsTemplate.php b/app-modules/engagement/src/Models/SmsTemplate.php index 2081798a55..c087092be6 100644 --- a/app-modules/engagement/src/Models/SmsTemplate.php +++ b/app-modules/engagement/src/Models/SmsTemplate.php @@ -36,7 +36,9 @@ namespace Assist\Engagement\Models; +use App\Models\User; use App\Models\BaseModel; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * @mixin IdeHelperSmsTemplate @@ -48,4 +50,13 @@ class SmsTemplate extends BaseModel 'description', 'content', ]; + + protected $casts = [ + 'content' => 'array', + ]; + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } } diff --git a/app-modules/engagement/src/Observers/SmsTemplateObserver.php b/app-modules/engagement/src/Observers/SmsTemplateObserver.php new file mode 100644 index 0000000000..426aa468d1 --- /dev/null +++ b/app-modules/engagement/src/Observers/SmsTemplateObserver.php @@ -0,0 +1,49 @@ + + + Copyright © 2022-2023, Canyon GBS LLC. All rights reserved. + + Advising App™ is licensed under the Elastic License 2.0. For more details, + see https://github.com/canyongbs/advisingapp/blob/main/LICENSE. + + Notice: + + - You may not provide the software to third parties as a hosted or managed + service, where the service provides users with access to any substantial set of + the features or functionality of the software. + - You may not move, change, disable, or circumvent the license key functionality + in the software, and you may not remove or obscure any functionality in the + software that is protected by the license key. + - You may not alter, remove, or obscure any licensing, copyright, or other notices + of the licensor in the software. Any use of the licensor’s trademarks is subject + to applicable law. + - Canyon GBS LLC respects the intellectual property rights of others and expects the + same in return. Canyon GBS™ and Advising App™ are registered trademarks of + Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks + vigorously. + - The software solution, including services, infrastructure, and code, is offered as a + Software as a Service (SaaS) by Canyon GBS LLC. + - Use of this software implies agreement to the license terms and conditions as stated + in the Elastic License 2.0. + + For more information or inquiries please visit our website at + https://www.canyongbs.com or contact us via email at legal@canyongbs.com. + + +*/ + +namespace Assist\Engagement\Observers; + +use Assist\Engagement\Models\SmsTemplate; + +class SmsTemplateObserver +{ + public function creating(SmsTemplate $smsTemplate): void + { + if (is_null($smsTemplate->user_id) && ! is_null(auth()->user())) { + $smsTemplate->user_id = auth()->user()->id; + } + } +} diff --git a/app-modules/engagement/src/Providers/EngagementServiceProvider.php b/app-modules/engagement/src/Providers/EngagementServiceProvider.php index 4afdf1c786..1d37b34965 100644 --- a/app-modules/engagement/src/Providers/EngagementServiceProvider.php +++ b/app-modules/engagement/src/Providers/EngagementServiceProvider.php @@ -51,6 +51,7 @@ use Assist\Engagement\Models\EngagementDeliverable; use Assist\Engagement\Observers\EngagementObserver; use Assist\Engagement\Models\EngagementFileEntities; +use Assist\Engagement\Observers\SmsTemplateObserver; use Illuminate\Database\Eloquent\Relations\Relation; use Assist\Engagement\Observers\EmailTemplateObserver; use Assist\Engagement\Observers\EngagementBatchObserver; @@ -67,12 +68,12 @@ public function register(): void public function boot(): void { Relation::morphMap([ - 'engagement' => Engagement::class, - 'engagement_deliverable' => EngagementDeliverable::class, + 'email_template' => EmailTemplate::class, 'engagement_batch' => EngagementBatch::class, - 'engagement_response' => EngagementResponse::class, + 'engagement_deliverable' => EngagementDeliverable::class, 'engagement_file' => EngagementFile::class, - 'email_template' => EmailTemplate::class, + 'engagement_response' => EngagementResponse::class, + 'engagement' => Engagement::class, 'sms_template' => SmsTemplate::class, ]); @@ -91,9 +92,10 @@ public function boot(): void public function registerObservers(): void { EmailTemplate::observe(EmailTemplateObserver::class); - EngagementFileEntities::observe(EngagementFileEntitiesObserver::class); Engagement::observe(EngagementObserver::class); EngagementBatch::observe(EngagementBatchObserver::class); + EngagementFileEntities::observe(EngagementFileEntitiesObserver::class); + SmsTemplate::observe(SmsTemplateObserver::class); } protected function registerRolesAndPermissions() diff --git a/app-modules/engagement/tests/Feature/Actions/CreateEngagementBatchTest.php b/app-modules/engagement/tests/Feature/Actions/CreateEngagementBatchTest.php index bb0c1f2dc6..cef09b917f 100644 --- a/app-modules/engagement/tests/Feature/Actions/CreateEngagementBatchTest.php +++ b/app-modules/engagement/tests/Feature/Actions/CreateEngagementBatchTest.php @@ -58,7 +58,7 @@ 'user' => User::factory()->create(), 'records' => Student::factory()->count(1)->create(), 'subject' => 'Test Subject', - 'body' => 'Test Body', + 'body' => ['Test Body'], 'deliveryMethod' => EngagementDeliveryMethod::Email->value, ])); @@ -73,7 +73,7 @@ 'user' => User::factory()->create(), 'records' => Student::factory()->count(3)->create(), 'subject' => 'Test Subject', - 'body' => 'Test Body', + 'body' => ['Test Body'], 'deliveryMethod' => EngagementDeliveryMethod::Email->value, ])); @@ -89,7 +89,7 @@ 'user' => User::factory()->create(), 'records' => Student::factory()->count(4)->create(), 'subject' => 'Test Subject', - 'body' => 'Test Body', + 'body' => ['Test Body'], 'deliveryMethod' => EngagementDeliveryMethod::Email->value, ])); @@ -104,7 +104,7 @@ 'user' => User::factory()->create(), 'records' => Student::factory()->count(1)->create(), 'subject' => 'Test Subject', - 'body' => 'Test Body', + 'body' => ['Test Body'], 'deliveryMethod' => EngagementDeliveryMethod::Email->value, ])); @@ -120,7 +120,7 @@ 'user' => User::factory()->create(), 'records' => Student::factory()->count(5)->create(), 'subject' => 'Test Subject', - 'body' => 'Test Body', + 'body' => ['Test Body'], 'deliveryMethod' => EngagementDeliveryMethod::Email->value, ])); @@ -146,7 +146,7 @@ 'user' => $user, 'records' => Student::factory()->count(1)->create(), 'subject' => 'Test Subject', - 'body' => 'Test Body', + 'body' => ['Test Body'], 'deliveryMethod' => EngagementDeliveryMethod::Email->value, ])); diff --git a/config/filament-tiptap-editor.php b/config/filament-tiptap-editor.php index 5d6d35ec1c..201e8d2c38 100644 --- a/config/filament-tiptap-editor.php +++ b/config/filament-tiptap-editor.php @@ -74,6 +74,7 @@ 'simple' => ['heading', 'hr', 'bullet-list', 'ordered-list', 'checked-list', '|', 'bold', 'italic', 'lead', 'small', '|', 'link', 'media'], 'minimal' => ['bold', 'italic', 'link', 'bullet-list', 'ordered-list'], 'email' => ['bold', 'italic', 'small', 'link', '|', 'heading', 'bullet-list', 'ordered-list', 'hr'], + 'sms' => [], ], /*