diff --git a/app-modules/prospect/src/Filament/Resources/ProspectResource/RelationManagers/ServiceRequestsRelationManager.php b/app-modules/prospect/src/Filament/Resources/ProspectResource/RelationManagers/ServiceRequestsRelationManager.php index 69ef6be567..8c8edd7fbe 100644 --- a/app-modules/prospect/src/Filament/Resources/ProspectResource/RelationManagers/ServiceRequestsRelationManager.php +++ b/app-modules/prospect/src/Filament/Resources/ProspectResource/RelationManagers/ServiceRequestsRelationManager.php @@ -45,7 +45,9 @@ use Filament\Tables\Columns\TextColumn; use Filament\Tables\Actions\CreateAction; use Filament\Tables\Filters\SelectFilter; +use Illuminate\Database\Eloquent\Builder; use App\Filament\Resources\RelationManagers\RelationManager; +use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestResource\Pages\ViewServiceRequest; use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestResource\Pages\CreateServiceRequest; @@ -84,7 +86,8 @@ public function table(Table $table): Table ]) ->filters([ SelectFilter::make('priority') - ->relationship('priority', 'name') + ->relationship('priority', 'name', fn (Builder $query) => $query->with('type')) + ->getOptionLabelFromRecordUsing(fn (ServiceRequestPriority $record) => "{$record->type->name} - {$record->name}") ->multiple() ->preload(), SelectFilter::make('status') diff --git a/app-modules/service-management/database/factories/ServiceRequestFactory.php b/app-modules/service-management/database/factories/ServiceRequestFactory.php index c95e9e0ef2..69f73839c2 100644 --- a/app-modules/service-management/database/factories/ServiceRequestFactory.php +++ b/app-modules/service-management/database/factories/ServiceRequestFactory.php @@ -41,7 +41,6 @@ use AdvisingApp\StudentDataModel\Models\Student; use Illuminate\Database\Eloquent\Factories\Factory; use AdvisingApp\ServiceManagement\Models\ServiceRequest; -use AdvisingApp\ServiceManagement\Models\ServiceRequestType; use AdvisingApp\ServiceManagement\Models\ServiceRequestStatus; use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; @@ -61,7 +60,6 @@ public function definition(): array 'res_details' => $this->faker->sentence(), 'division_id' => Division::inRandomOrder()->first()?->id ?? Division::factory(), 'status_id' => ServiceRequestStatus::inRandomOrder()->first() ?? ServiceRequestStatus::factory(), - 'type_id' => ServiceRequestType::inRandomOrder()->first() ?? ServiceRequestType::factory(), 'priority_id' => ServiceRequestPriority::inRandomOrder()->first() ?? ServiceRequestPriority::factory(), 'created_by_id' => User::factory(), ]; diff --git a/app-modules/service-management/database/factories/ServiceRequestPriorityFactory.php b/app-modules/service-management/database/factories/ServiceRequestPriorityFactory.php index d5e97f0fae..6c43e2d056 100644 --- a/app-modules/service-management/database/factories/ServiceRequestPriorityFactory.php +++ b/app-modules/service-management/database/factories/ServiceRequestPriorityFactory.php @@ -37,6 +37,7 @@ namespace AdvisingApp\ServiceManagement\Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; +use AdvisingApp\ServiceManagement\Models\ServiceRequestType; use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; /** @@ -49,6 +50,7 @@ public function definition(): array return [ 'name' => $this->faker->name, 'order' => $this->faker->randomNumber(1), + 'type_id' => ServiceRequestType::factory(), ]; } diff --git a/app-modules/service-management/database/migrations/2023_09_05_143921_create_service_request_priorities_table.php b/app-modules/service-management/database/migrations/2023_09_05_143921_create_service_request_priorities_table.php index dce927a990..78e8dddc24 100644 --- a/app-modules/service-management/database/migrations/2023_09_05_143921_create_service_request_priorities_table.php +++ b/app-modules/service-management/database/migrations/2023_09_05_143921_create_service_request_priorities_table.php @@ -45,6 +45,7 @@ public function up(): void $table->uuid('id')->primary(); $table->string('name'); $table->integer('order'); + $table->foreignUuid('type_id')->constrained('service_request_types')->cascadeOnDelete(); $table->timestamps(); $table->softDeletes(); }); diff --git a/app-modules/service-management/database/migrations/2023_09_05_144251_create_service_requests_table.php b/app-modules/service-management/database/migrations/2023_09_05_144251_create_service_requests_table.php index 102a818077..d436fa9b8a 100644 --- a/app-modules/service-management/database/migrations/2023_09_05_144251_create_service_requests_table.php +++ b/app-modules/service-management/database/migrations/2023_09_05_144251_create_service_requests_table.php @@ -52,7 +52,6 @@ public function up(): void $table->foreignUuid('division_id')->nullable()->constrained('divisions'); $table->foreignUuid('status_id')->nullable()->constrained('service_request_statuses'); - $table->foreignUuid('type_id')->nullable()->constrained('service_request_types'); $table->foreignUuid('priority_id')->nullable()->constrained('service_request_priorities'); $table->foreignUuid('created_by_id')->nullable()->constrained('users'); diff --git a/app-modules/service-management/database/seeders/ServiceRequestPrioritySeeder.php b/app-modules/service-management/database/seeders/ServiceRequestPrioritySeeder.php deleted file mode 100644 index 6ef6e8da40..0000000000 --- a/app-modules/service-management/database/seeders/ServiceRequestPrioritySeeder.php +++ /dev/null @@ -1,55 +0,0 @@ - - - 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 AdvisingApp\ServiceManagement\Database\Seeders; - -use Illuminate\Database\Seeder; -use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; - -class ServiceRequestPrioritySeeder extends Seeder -{ - public function run(): void - { - ServiceRequestPriority::factory() - ->createMany( - [ - ['name' => 'High', 'order' => 1], - ['name' => 'Medium', 'order' => 2], - ['name' => 'Low', 'order' => 3], - ] - ); - } -} diff --git a/app-modules/service-management/database/seeders/ServiceRequestTypeSeeder.php b/app-modules/service-management/database/seeders/ServiceRequestTypeSeeder.php index fc282aeca1..deba89b9eb 100644 --- a/app-modules/service-management/database/seeders/ServiceRequestTypeSeeder.php +++ b/app-modules/service-management/database/seeders/ServiceRequestTypeSeeder.php @@ -60,6 +60,15 @@ public function run(): void ['name' => 'Tutoring'], ['name' => 'Veterans'], ] - ); + ) + ->each(function (ServiceRequestType $type) { + $type->priorities()->createMany( + [ + ['name' => 'High', 'order' => 1], + ['name' => 'Medium', 'order' => 2], + ['name' => 'Low', 'order' => 3], + ] + ); + }); } } diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource.php deleted file mode 100644 index 14a87b105b..0000000000 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource.php +++ /dev/null @@ -1,68 +0,0 @@ - - - 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 AdvisingApp\ServiceManagement\Filament\Resources; - -use Filament\Resources\Resource; -use App\Filament\Clusters\ServiceManagementAdministration; -use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource\Pages\EditServiceRequestPriority; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource\Pages\ViewServiceRequestPriority; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource\Pages\CreateServiceRequestPriority; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource\Pages\ListServiceRequestPriorities; - -class ServiceRequestPriorityResource extends Resource -{ - protected static ?string $model = ServiceRequestPriority::class; - - protected static ?string $navigationIcon = 'heroicon-o-arrows-up-down'; - - protected static ?string $navigationLabel = 'Priorities'; - - protected static ?int $navigationSort = 1; - - protected static ?string $cluster = ServiceManagementAdministration::class; - - public static function getPages(): array - { - return [ - 'index' => ListServiceRequestPriorities::route('/'), - 'create' => CreateServiceRequestPriority::route('/create'), - 'view' => ViewServiceRequestPriority::route('/{record}'), - 'edit' => EditServiceRequestPriority::route('/{record}/edit'), - ]; - } -} diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/CreateServiceRequestPriority.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/CreateServiceRequestPriority.php deleted file mode 100644 index 19ec5c17bb..0000000000 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/CreateServiceRequestPriority.php +++ /dev/null @@ -1,63 +0,0 @@ - - - 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 AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource\Pages; - -use Filament\Forms\Form; -use Filament\Forms\Components\TextInput; -use Filament\Resources\Pages\CreateRecord; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource; - -class CreateServiceRequestPriority extends CreateRecord -{ - protected static string $resource = ServiceRequestPriorityResource::class; - - public function form(Form $form): Form - { - return $form - ->schema([ - TextInput::make('name') - ->label('Name') - ->required() - ->string(), - TextInput::make('order') - ->label('Priority Order') - ->required() - ->integer() - ->numeric(), - ]); - } -} diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/EditServiceRequestPriority.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/EditServiceRequestPriority.php deleted file mode 100644 index 030fa616a1..0000000000 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/EditServiceRequestPriority.php +++ /dev/null @@ -1,73 +0,0 @@ - - - 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 AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource\Pages; - -use Filament\Actions; -use Filament\Forms\Form; -use Filament\Forms\Components\TextInput; -use Filament\Resources\Pages\EditRecord; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource; - -class EditServiceRequestPriority extends EditRecord -{ - protected static string $resource = ServiceRequestPriorityResource::class; - - public function form(Form $form): Form - { - return $form - ->schema([ - TextInput::make('name') - ->label('Name') - ->required() - ->string(), - TextInput::make('order') - ->label('Priority Order') - ->required() - ->integer() - ->numeric() - ->disabled(), - ]); - } - - protected function getHeaderActions(): array - { - return [ - Actions\ViewAction::make(), - Actions\DeleteAction::make(), - ]; - } -} diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/ViewServiceRequestPriority.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/ViewServiceRequestPriority.php deleted file mode 100644 index 4b1aa52193..0000000000 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/ViewServiceRequestPriority.php +++ /dev/null @@ -1,73 +0,0 @@ - - - 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 AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource\Pages; - -use Filament\Actions; -use Filament\Infolists\Infolist; -use Filament\Resources\Pages\ViewRecord; -use Filament\Infolists\Components\Section; -use Filament\Infolists\Components\TextEntry; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource; - -class ViewServiceRequestPriority extends ViewRecord -{ - protected static string $resource = ServiceRequestPriorityResource::class; - - public function infolist(Infolist $infolist): Infolist - { - return $infolist - ->schema([ - Section::make() - ->schema([ - TextEntry::make('name') - ->label('Name') - ->translateLabel(), - TextEntry::make('order') - ->label('Order') - ->translateLabel(), - ]) - ->columns(), - ]); - } - - protected function getHeaderActions(): array - { - return [ - Actions\EditAction::make(), - ]; - } -} diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/CreateServiceRequest.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/CreateServiceRequest.php index 15f184e43d..34b6b9ab13 100644 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/CreateServiceRequest.php +++ b/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/CreateServiceRequest.php @@ -36,7 +36,10 @@ namespace AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestResource\Pages; +use Filament\Forms\Get; +use Filament\Forms\Set; use Filament\Forms\Form; +use Filament\Forms\Components\Grid; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; use AdvisingApp\Division\Models\Division; @@ -69,21 +72,26 @@ public function form(Form $form): Form ->label('Status') ->required() ->exists((new ServiceRequestStatus())->getTable(), 'id'), - Select::make('priority_id') - ->relationship( - name: 'priority', - titleAttribute: 'name', - modifyQueryUsing: fn (Builder $query) => $query->orderBy('order'), - ) - ->label('Priority') - ->required() - ->exists((new ServiceRequestPriority())->getTable(), 'id'), - Select::make('type_id') - ->relationship('type', 'name') - ->preload() - ->label('Type') - ->required() - ->exists((new ServiceRequestType())->getTable(), 'id'), + Grid::make(2) + ->schema([ + Select::make('type_id') + ->options(ServiceRequestType::query()->pluck('name', 'id')) + ->afterStateUpdated(fn (Set $set) => $set('priority_id', null)) + ->label('Type') + ->required() + ->live() + ->exists(ServiceRequestType::class, 'id'), + Select::make('priority_id') + ->relationship( + name: 'priority', + titleAttribute: 'name', + modifyQueryUsing: fn (Get $get, Builder $query) => $query->where('type_id', $get('type_id'))->orderBy('order'), + ) + ->label('Priority') + ->required() + ->exists(ServiceRequestPriority::class, 'id') + ->visible(fn (Get $get): bool => filled($get('type_id'))), + ]), Textarea::make('close_details') ->label('Close Details/Description') ->nullable() diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/EditServiceRequest.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/EditServiceRequest.php index 57fd4e545e..28c29f7fd3 100644 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/EditServiceRequest.php +++ b/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/EditServiceRequest.php @@ -37,7 +37,10 @@ namespace AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestResource\Pages; use Filament\Actions; +use Filament\Forms\Get; +use Filament\Forms\Set; use Filament\Forms\Form; +use Filament\Forms\Components\Grid; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; use Filament\Resources\Pages\EditRecord; @@ -68,21 +71,26 @@ public function form(Form $form): Form ->label('Status') ->required() ->exists((new ServiceRequestStatus())->getTable(), 'id'), - Select::make('priority_id') - ->relationship( - name: 'priority', - titleAttribute: 'name', - modifyQueryUsing: fn (Builder $query) => $query->orderBy('order'), - ) - ->label('Priority') - ->required() - ->exists((new ServiceRequestPriority())->getTable(), 'id'), - Select::make('type_id') - ->relationship('type', 'name') - ->preload() - ->label('Type') - ->required() - ->exists((new ServiceRequestType())->getTable(), 'id'), + Grid::make(2) + ->schema([ + Select::make('type_id') + ->options(ServiceRequestType::query()->pluck('name', 'id')) + ->afterStateUpdated(fn (Set $set) => $set('priority_id', null)) + ->label('Type') + ->required() + ->live() + ->exists(ServiceRequestType::class, 'id'), + Select::make('priority_id') + ->relationship( + name: 'priority', + titleAttribute: 'name', + modifyQueryUsing: fn (Get $get, Builder $query, $record) => $query->where('type_id', $get('type_id'))->orderBy('order'), + ) + ->label('Priority') + ->required() + ->exists(ServiceRequestPriority::class, 'id') + ->visible(fn (Get $get): bool => filled($get('type_id'))), + ]), Textarea::make('close_details') ->label('Close Details/Description') ->nullable() @@ -103,4 +111,11 @@ protected function getHeaderActions(): array Actions\DeleteAction::make(), ]; } + + protected function mutateFormDataBeforeFill(array $data): array + { + $data['type_id'] = $this->getRecord()->priority->type_id; + + return $data; + } } diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/ListServiceRequests.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/ListServiceRequests.php index bc0c0cff71..0e01455eaf 100644 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/ListServiceRequests.php +++ b/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/ListServiceRequests.php @@ -50,6 +50,7 @@ use Filament\Tables\Actions\DeleteBulkAction; use AdvisingApp\ServiceManagement\Models\ServiceRequest; use AdvisingApp\StudentDataModel\Models\Scopes\EducatableSort; +use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; use AdvisingApp\StudentDataModel\Models\Scopes\EducatableSearch; use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestResource; @@ -104,7 +105,8 @@ public function table(Table $table): Table ]) ->filters([ SelectFilter::make('priority') - ->relationship('priority', 'name') + ->relationship('priority', 'name', fn (Builder $query) => $query->with('type')) + ->getOptionLabelFromRecordUsing(fn (ServiceRequestPriority $record) => "{$record->type->name} - {$record->name}") ->multiple() ->preload(), SelectFilter::make('status') diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/ViewServiceRequest.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/ViewServiceRequest.php index 7542a2a667..07f9d6d62f 100644 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/ViewServiceRequest.php +++ b/app-modules/service-management/src/Filament/Resources/ServiceRequestResource/Pages/ViewServiceRequest.php @@ -70,7 +70,7 @@ public function infolist(Infolist $infolist): Infolist TextEntry::make('priority.name') ->label('Priority') ->translateLabel(), - TextEntry::make('type.name') + TextEntry::make('priority.type.name') ->label('Type') ->translateLabel(), TextEntry::make('close_details') diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource.php index e108c8b151..15f9fbfc0d 100644 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource.php +++ b/app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource.php @@ -43,6 +43,7 @@ use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestTypeResource\Pages\ViewServiceRequestType; use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestTypeResource\Pages\ListServiceRequestTypes; use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestTypeResource\Pages\CreateServiceRequestType; +use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestTypeResource\RelationManagers\ServiceRequestPrioritiesRelationManager; class ServiceRequestTypeResource extends Resource { @@ -56,6 +57,13 @@ class ServiceRequestTypeResource extends Resource protected static ?string $cluster = ServiceManagementAdministration::class; + public static function getRelations(): array + { + return [ + ServiceRequestPrioritiesRelationManager::class, + ]; + } + public static function getPages(): array { return [ diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource/Pages/CreateServiceRequestType.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource/Pages/CreateServiceRequestType.php index 81fb109abb..f4d7b71e5a 100644 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource/Pages/CreateServiceRequestType.php +++ b/app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource/Pages/CreateServiceRequestType.php @@ -55,4 +55,15 @@ public function form(Form $form): Form ->string(), ]); } + + protected function afterCreate(): void + { + $this->getRecord()->priorities()->createMany( + [ + ['name' => 'High', 'order' => 1], + ['name' => 'Medium', 'order' => 2], + ['name' => 'Low', 'order' => 3], + ] + ); + } } diff --git a/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/ListServiceRequestPriorities.php b/app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource/RelationManagers/ServiceRequestPrioritiesRelationManager.php similarity index 68% rename from app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/ListServiceRequestPriorities.php rename to app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource/RelationManagers/ServiceRequestPrioritiesRelationManager.php index fc15e34082..09bb6d3093 100644 --- a/app-modules/service-management/src/Filament/Resources/ServiceRequestPriorityResource/Pages/ListServiceRequestPriorities.php +++ b/app-modules/service-management/src/Filament/Resources/ServiceRequestTypeResource/RelationManagers/ServiceRequestPrioritiesRelationManager.php @@ -34,22 +34,41 @@ */ -namespace AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource\Pages; +namespace AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestTypeResource\RelationManagers; -use Filament\Actions; +use Filament\Forms\Form; use Filament\Tables\Table; use App\Filament\Columns\IdColumn; use Filament\Tables\Actions\EditAction; -use Filament\Tables\Actions\ViewAction; use Filament\Tables\Columns\TextColumn; -use Filament\Resources\Pages\ListRecords; -use Filament\Tables\Actions\BulkActionGroup; +use Filament\Forms\Components\TextInput; +use Filament\Tables\Actions\CreateAction; +use Filament\Tables\Actions\DeleteAction; use Filament\Tables\Actions\DeleteBulkAction; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource; +use App\Filament\Resources\RelationManagers\RelationManager; -class ListServiceRequestPriorities extends ListRecords +class ServiceRequestPrioritiesRelationManager extends RelationManager { - protected static string $resource = ServiceRequestPriorityResource::class; + protected static string $relationship = 'priorities'; + + protected static ?string $recordTitleAttribute = 'name'; + + public function form(Form $form): Form + { + return $form + ->schema([ + TextInput::make('name') + ->label('Name') + ->required() + ->string(), + TextInput::make('order') + ->label('Priority Order') + ->required() + ->integer() + ->numeric() + ->disabledOn('edit'), + ]); + } public function table(Table $table): Table { @@ -69,24 +88,17 @@ public function table(Table $table): Table ->sortable(), ]) ->defaultSort('order') - ->filters([ + ->reorderable('order') + ->paginated(false) + ->headerActions([ + CreateAction::make(), ]) ->actions([ - ViewAction::make(), EditAction::make(), + DeleteAction::make(), ]) - ->bulkActions([ - BulkActionGroup::make([ - DeleteBulkAction::make(), - ]), - ]) - ->reorderable('order'); - } - - protected function getHeaderActions(): array - { - return [ - Actions\CreateAction::make(), - ]; + ->groupedBulkActions([ + DeleteBulkAction::make(), + ]); } } diff --git a/app-modules/service-management/src/Models/ServiceRequest.php b/app-modules/service-management/src/Models/ServiceRequest.php index fb48c12dfc..e81124963a 100644 --- a/app-modules/service-management/src/Models/ServiceRequest.php +++ b/app-modules/service-management/src/Models/ServiceRequest.php @@ -90,7 +90,6 @@ class ServiceRequest extends BaseModel implements Auditable, CanTriggerAutoSubsc 'respondent_id', 'division_id', 'status_id', - 'type_id', 'priority_id', 'assigned_to_id', 'close_details', @@ -169,11 +168,6 @@ public function status(): BelongsTo return $this->belongsTo(ServiceRequestStatus::class); } - public function type(): BelongsTo - { - return $this->belongsTo(ServiceRequestType::class); - } - public function priority(): BelongsTo { return $this->belongsTo(ServiceRequestPriority::class); @@ -226,7 +220,6 @@ public static function executeFromCampaignAction(CampaignAction $action): bool|s 'res_details' => $action->data['res_details'], 'division_id' => $action->data['division_id'], 'status_id' => $action->data['status_id'], - 'type_id' => $action->data['type_id'], 'priority_id' => $action->data['priority_id'], 'created_by_id' => $action->campaign->user->id, ]); diff --git a/app-modules/service-management/src/Models/ServiceRequestPriority.php b/app-modules/service-management/src/Models/ServiceRequestPriority.php index 056d82f846..72e8e10d65 100644 --- a/app-modules/service-management/src/Models/ServiceRequestPriority.php +++ b/app-modules/service-management/src/Models/ServiceRequestPriority.php @@ -42,6 +42,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use AdvisingApp\Audit\Models\Concerns\Auditable as AuditableTrait; /** @@ -63,6 +64,11 @@ public function serviceRequests(): HasMany return $this->hasMany(ServiceRequest::class, 'priority_id'); } + public function type(): BelongsTo + { + return $this->belongsTo(ServiceRequestType::class, 'type_id'); + } + protected function serializeDate(DateTimeInterface $date): string { return $date->format(config('project.datetime_format') ?? 'Y-m-d H:i:s'); diff --git a/app-modules/service-management/src/Models/ServiceRequestType.php b/app-modules/service-management/src/Models/ServiceRequestType.php index 0aff3332e0..e924ce3c97 100644 --- a/app-modules/service-management/src/Models/ServiceRequestType.php +++ b/app-modules/service-management/src/Models/ServiceRequestType.php @@ -42,6 +42,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasManyThrough; use AdvisingApp\Audit\Models\Concerns\Auditable as AuditableTrait; /** @@ -57,9 +58,14 @@ class ServiceRequestType extends BaseModel implements Auditable 'name', ]; - public function serviceRequests(): HasMany + public function serviceRequests(): HasManyThrough { - return $this->hasMany(ServiceRequest::class, 'type_id'); + return $this->through('priorities')->has('serviceRequests'); + } + + public function priorities(): HasMany + { + return $this->hasMany(ServiceRequestPriority::class, 'type_id'); } protected function serializeDate(DateTimeInterface $date): string diff --git a/app-modules/service-management/tests/RequestFactories/CreateServiceRequestRequestFactory.php b/app-modules/service-management/tests/RequestFactories/CreateServiceRequestRequestFactory.php index 6985e1637d..1777e688eb 100644 --- a/app-modules/service-management/tests/RequestFactories/CreateServiceRequestRequestFactory.php +++ b/app-modules/service-management/tests/RequestFactories/CreateServiceRequestRequestFactory.php @@ -39,7 +39,6 @@ use AdvisingApp\Division\Models\Division; use AdvisingApp\Prospect\Models\Prospect; use Worksome\RequestFactories\RequestFactory; -use AdvisingApp\ServiceManagement\Models\ServiceRequestType; use AdvisingApp\ServiceManagement\Models\ServiceRequestStatus; use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; @@ -47,13 +46,15 @@ class CreateServiceRequestRequestFactory extends RequestFactory { public function definition(): array { + $priority = ServiceRequestPriority::factory()->create(); + return [ 'division_id' => Division::inRandomOrder()->first()?->id ?? Division::factory()->create()->id, 'status_id' => ServiceRequestStatus::factory()->create()->id, - 'priority_id' => ServiceRequestPriority::factory()->create()->id, + 'type_id' => $priority->type_id, + 'priority_id' => $priority->id, 'respondent_id' => Prospect::factory()->create()->getKey(), 'respondent_type' => app(Prospect::class)->getMorphClass(), - 'type_id' => ServiceRequestType::factory()->create()->id, 'close_details' => $this->faker->sentence, 'res_details' => $this->faker->sentence, ]; diff --git a/app-modules/service-management/tests/RequestFactories/EditServiceRequestRequestFactory.php b/app-modules/service-management/tests/RequestFactories/EditServiceRequestRequestFactory.php index fe168cc213..467df67e9e 100644 --- a/app-modules/service-management/tests/RequestFactories/EditServiceRequestRequestFactory.php +++ b/app-modules/service-management/tests/RequestFactories/EditServiceRequestRequestFactory.php @@ -38,7 +38,6 @@ use AdvisingApp\Division\Models\Division; use Worksome\RequestFactories\RequestFactory; -use AdvisingApp\ServiceManagement\Models\ServiceRequestType; use AdvisingApp\ServiceManagement\Models\ServiceRequestStatus; use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; @@ -50,7 +49,6 @@ public function definition(): array 'division_id' => Division::inRandomOrder()->first()?->id ?? Division::factory()->create()->id, 'status_id' => ServiceRequestStatus::factory()->create()->id, 'priority_id' => ServiceRequestPriority::factory()->create()->id, - 'type_id' => ServiceRequestType::factory()->create()->id, 'close_details' => $this->faker->sentence, 'res_details' => $this->faker->sentence, ]; diff --git a/app-modules/service-management/tests/ServiceRequest/CreateServiceRequestTest.php b/app-modules/service-management/tests/ServiceRequest/CreateServiceRequestTest.php index 1f3e4d52f9..44ea612632 100644 --- a/app-modules/service-management/tests/ServiceRequest/CreateServiceRequestTest.php +++ b/app-modules/service-management/tests/ServiceRequest/CreateServiceRequestTest.php @@ -83,8 +83,8 @@ 'division_id', 'status_id', 'priority_id', - 'type_id', 'respondent_id', + 'type_id', ] )->toArray() ); @@ -96,9 +96,7 @@ ->and($serviceRequest->status->id) ->toEqual($request->get('status_id')) ->and($serviceRequest->priority->id) - ->toEqual($request->get('priority_id')) - ->and($serviceRequest->type->id) - ->toEqual($request->get('type_id')); + ->toEqual($request->get('priority_id')); }); test('CreateServiceRequest requires valid data', function ($data, $errors, $setup = null) { @@ -115,7 +113,7 @@ ->call('create') ->assertHasFormErrors($errors); - assertDatabaseMissing(ServiceRequest::class, $request->except(['division', 'status', 'priority', 'type'])->toArray()); + assertDatabaseMissing(ServiceRequest::class, $request->except(['division_id', 'status_id', 'priority_id', 'type_id'])->toArray()); })->with( [ 'division_id missing' => [CreateServiceRequestRequestFactory::new()->without('division_id'), ['division_id' => 'required']], @@ -133,11 +131,6 @@ CreateServiceRequestRequestFactory::new()->state(['priority_id' => fake()->uuid()]), ['priority_id' => 'exists'], ], - 'type_id missing' => [CreateServiceRequestRequestFactory::new()->without('type_id'), ['type_id' => 'required']], - 'type_id does not exist' => [ - CreateServiceRequestRequestFactory::new()->state(['type_id' => fake()->uuid()]), - ['type_id' => 'exists'], - ], 'close_details is not a string' => [CreateServiceRequestRequestFactory::new()->state(['close_details' => 1]), ['close_details' => 'string']], 'res_details is not a string' => [CreateServiceRequestRequestFactory::new()->state(['res_details' => 1]), ['res_details' => 'string']], ] @@ -183,8 +176,8 @@ 'division_id', 'status_id', 'priority_id', - 'type_id', 'respondent_id', + 'type_id', ] )->toArray() ); @@ -196,9 +189,7 @@ ->and($serviceRequest->status->id) ->toEqual($request->get('status_id')) ->and($serviceRequest->priority->id) - ->toEqual($request->get('priority_id')) - ->and($serviceRequest->type->id) - ->toEqual($request->get('type_id')); + ->toEqual($request->get('priority_id')); }); test('CreateServiceRequest is gated with proper feature access control', function () { @@ -242,7 +233,7 @@ assertCount(1, ServiceRequest::all()); - assertDatabaseHas(ServiceRequest::class, $request->except(['division_id', 'respondent_id'])->toArray()); + assertDatabaseHas(ServiceRequest::class, $request->except(['division_id', 'respondent_id', 'type_id'])->toArray()); $serviceRequest = ServiceRequest::first(); diff --git a/app-modules/service-management/tests/ServiceRequest/EditServiceRequestTest.php b/app-modules/service-management/tests/ServiceRequest/EditServiceRequestTest.php index 88046f8c1a..9bbc7ff7e1 100644 --- a/app-modules/service-management/tests/ServiceRequest/EditServiceRequestTest.php +++ b/app-modules/service-management/tests/ServiceRequest/EditServiceRequestTest.php @@ -77,7 +77,6 @@ 'division_id', 'status_id', 'priority_id', - 'type_id', ] )->toArray() ); @@ -89,9 +88,7 @@ ->and($serviceRequest->status->id) ->toEqual($request->get('status_id')) ->and($serviceRequest->priority->id) - ->toEqual($request->get('priority_id')) - ->and($serviceRequest->type->id) - ->toEqual($request->get('type_id')); + ->toEqual($request->get('priority_id')); }); test('EditServiceRequest requires valid data', function ($data, $errors) { @@ -115,9 +112,7 @@ ->and($serviceRequest->fresh()->status->id) ->toEqual($serviceRequest->status->id) ->and($serviceRequest->fresh()->priority->id) - ->toEqual($serviceRequest->priority->id) - ->and($serviceRequest->fresh()->type->id) - ->toEqual($serviceRequest->type->id); + ->toEqual($serviceRequest->priority->id); })->with( [ 'division_id missing' => [EditServiceRequestRequestFactory::new()->state(['division_id' => null]), ['division_id' => 'required']], @@ -135,11 +130,6 @@ EditServiceRequestRequestFactory::new()->state(['priority_id' => fake()->uuid()]), ['priority_id' => 'exists'], ], - 'type_id missing' => [EditServiceRequestRequestFactory::new()->state(['type_id' => null]), ['type_id' => 'required']], - 'type_id does not exist' => [ - EditServiceRequestRequestFactory::new()->state(['type_id' => fake()->uuid()]), - ['type_id' => 'exists'], - ], 'close_details is not a string' => [EditServiceRequestRequestFactory::new()->state(['close_details' => 1]), ['close_details' => 'string']], 'res_details is not a string' => [EditServiceRequestRequestFactory::new()->state(['res_details' => 1]), ['res_details' => 'string']], ] @@ -188,9 +178,8 @@ $request->except( [ 'division_id', - 'status', + 'status_id', 'priority', - 'type', ] )->toArray() ); @@ -202,9 +191,7 @@ ->and($serviceRequest->status->id) ->toEqual($request->get('status_id')) ->and($serviceRequest->priority->id) - ->toEqual($request->get('priority_id')) - ->and($serviceRequest->type->id) - ->toEqual($request->get('type_id')); + ->toEqual($request->get('priority_id')); }); test('EditServiceRequest is gated with proper feature access control', function () { diff --git a/app-modules/service-management/tests/ServiceRequest/ViewServiceRequestTest.php b/app-modules/service-management/tests/ServiceRequest/ViewServiceRequestTest.php index 7ead04a87b..fa04ed0d27 100644 --- a/app-modules/service-management/tests/ServiceRequest/ViewServiceRequestTest.php +++ b/app-modules/service-management/tests/ServiceRequest/ViewServiceRequestTest.php @@ -67,7 +67,7 @@ 'Priority', $serviceRequest->priority->name, 'Type', - $serviceRequest->type->name, + $serviceRequest->priority->type->name, 'Close Details/Description', $serviceRequest->close_details, 'Internal Service Request Details', diff --git a/app-modules/service-management/tests/ServiceRequestPriority/CreateServiceRequestPriorityTest.php b/app-modules/service-management/tests/ServiceRequestPriority/CreateServiceRequestPriorityTest.php deleted file mode 100644 index bd0398aaba..0000000000 --- a/app-modules/service-management/tests/ServiceRequestPriority/CreateServiceRequestPriorityTest.php +++ /dev/null @@ -1,167 +0,0 @@ - - - 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. - - -*/ - -use App\Models\User; - -use function Tests\asSuperAdmin; - -use App\Settings\LicenseSettings; - -use function Pest\Laravel\actingAs; -use function Pest\Livewire\livewire; - -use AdvisingApp\Prospect\Models\Prospect; - -use function PHPUnit\Framework\assertCount; -use function PHPUnit\Framework\assertEmpty; -use function Pest\Laravel\assertDatabaseHas; - -use AdvisingApp\StudentDataModel\Models\Student; -use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource; -use AdvisingApp\ServiceManagement\Tests\RequestFactories\CreateServiceRequestPriorityRequestFactory; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource\Pages\CreateServiceRequestPriority; - -test('A successful action on the CreateServiceRequestPriority page', function () { - asSuperAdmin() - ->get( - ServiceRequestPriorityResource::getUrl('create') - ) - ->assertSuccessful(); - - $request = CreateServiceRequestPriorityRequestFactory::new()->create(); - - livewire(ServiceRequestPriorityResource\Pages\CreateServiceRequestPriority::class) - ->fillForm($request) - ->call('create') - ->assertHasNoFormErrors(); - - assertCount(1, ServiceRequestPriority::all()); - - assertDatabaseHas(ServiceRequestPriority::class, $request); -}); - -test('CreateServiceRequestPriority requires valid data', function ($data, $errors) { - asSuperAdmin(); - - livewire(ServiceRequestPriorityResource\Pages\CreateServiceRequestPriority::class) - ->fillForm(CreateServiceRequestPriorityRequestFactory::new($data)->create()) - ->call('create') - ->assertHasFormErrors($errors); - - assertEmpty(ServiceRequestPriority::all()); -})->with( - [ - 'name missing' => [CreateServiceRequestPriorityRequestFactory::new()->without('name'), ['name' => 'required']], - 'name not a string' => [CreateServiceRequestPriorityRequestFactory::new()->state(['name' => 1]), ['name' => 'string']], - 'order missing' => [CreateServiceRequestPriorityRequestFactory::new()->without('order'), ['order' => 'required']], - 'order not a number' => [CreateServiceRequestPriorityRequestFactory::new()->state(['order' => 'a']), ['order' => 'numeric']], - ] -); - -// Permission Tests - -test('CreateServiceRequestPriority is gated with proper access control', function () { - $user = User::factory()->licensed([Student::getLicenseType(), Prospect::getLicenseType()])->create(); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('create') - )->assertForbidden(); - - livewire(ServiceRequestPriorityResource\Pages\CreateServiceRequestPriority::class) - ->assertForbidden(); - - $user->givePermissionTo('service_request_priority.view-any'); - $user->givePermissionTo('service_request_priority.create'); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('create') - )->assertSuccessful(); - - $request = collect(CreateServiceRequestPriorityRequestFactory::new()->create()); - - livewire(ServiceRequestPriorityResource\Pages\CreateServiceRequestPriority::class) - ->fillForm($request->toArray()) - ->call('create') - ->assertHasNoFormErrors(); - - assertCount(1, ServiceRequestPriority::all()); - - assertDatabaseHas(ServiceRequestPriority::class, $request->toArray()); -}); - -test('CreateServiceRequestPriority is gated with proper feature access control', function () { - $settings = app(LicenseSettings::class); - - $settings->data->addons->serviceManagement = false; - - $settings->save(); - - $user = User::factory()->licensed([Student::getLicenseType(), Prospect::getLicenseType()])->create(); - - $user->givePermissionTo('service_request_priority.view-any'); - $user->givePermissionTo('service_request_priority.create'); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('create') - )->assertForbidden(); - - livewire(CreateServiceRequestPriority::class) - ->assertForbidden(); - - $settings->data->addons->serviceManagement = true; - - $settings->save(); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('create') - )->assertSuccessful(); - - $request = collect(CreateServiceRequestPriorityRequestFactory::new()->create()); - - livewire(CreateServiceRequestPriority::class) - ->fillForm($request->toArray()) - ->call('create') - ->assertHasNoFormErrors(); - - assertCount(1, ServiceRequestPriority::all()); - - assertDatabaseHas(ServiceRequestPriority::class, $request->toArray()); -}); diff --git a/app-modules/service-management/tests/ServiceRequestPriority/EditServiceRequestPriorityTest.php b/app-modules/service-management/tests/ServiceRequestPriority/EditServiceRequestPriorityTest.php deleted file mode 100644 index 7f7599109c..0000000000 --- a/app-modules/service-management/tests/ServiceRequestPriority/EditServiceRequestPriorityTest.php +++ /dev/null @@ -1,194 +0,0 @@ - - - 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. - - -*/ - -use App\Models\User; - -use function Tests\asSuperAdmin; - -use App\Settings\LicenseSettings; - -use function Pest\Laravel\actingAs; -use function Pest\Livewire\livewire; - -use AdvisingApp\Prospect\Models\Prospect; - -use function Pest\Laravel\assertDatabaseHas; -use function PHPUnit\Framework\assertEquals; - -use AdvisingApp\StudentDataModel\Models\Student; -use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource; -use AdvisingApp\ServiceManagement\Tests\RequestFactories\EditServiceRequestPriorityRequestFactory; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource\Pages\EditServiceRequestPriority; - -test('A successful action on the EditServiceRequestPriority page', function () { - $serviceRequestPriority = ServiceRequestPriority::factory()->create(); - - asSuperAdmin() - ->get( - ServiceRequestPriorityResource::getUrl('edit', [ - 'record' => $serviceRequestPriority->getRouteKey(), - ]) - ) - ->assertSuccessful(); - - $editRequest = EditServiceRequestPriorityRequestFactory::new()->create(); - - livewire(ServiceRequestPriorityResource\Pages\EditServiceRequestPriority::class, [ - 'record' => $serviceRequestPriority->getRouteKey(), - ]) - ->assertFormSet([ - 'name' => $serviceRequestPriority->name, - ]) - ->fillForm($editRequest) - ->call('save') - ->assertHasNoFormErrors(); - - assertEquals($editRequest['name'], $serviceRequestPriority->fresh()->name); -}); - -test('EditServiceRequestPriority requires valid data', function ($data, $errors) { - asSuperAdmin(); - - $serviceRequestPriority = ServiceRequestPriority::factory()->create(); - - livewire(ServiceRequestPriorityResource\Pages\EditServiceRequestPriority::class, [ - 'record' => $serviceRequestPriority->getRouteKey(), - ]) - ->assertFormSet([ - 'name' => $serviceRequestPriority->name, - ]) - ->fillForm(EditServiceRequestPriorityRequestFactory::new($data)->create()) - ->call('save') - ->assertHasFormErrors($errors); - - assertDatabaseHas(ServiceRequestPriority::class, $serviceRequestPriority->toArray()); -})->with( - [ - 'name missing' => [EditServiceRequestPriorityRequestFactory::new()->state(['name' => null]), ['name' => 'required']], - 'name not a string' => [EditServiceRequestPriorityRequestFactory::new()->state(['name' => 1]), ['name' => 'string']], - ] -); - -// Permission Tests - -test('EditServiceRequestPriority is gated with proper access control', function () { - $user = User::factory()->licensed([Student::getLicenseType(), Prospect::getLicenseType()])->create(); - - $serviceRequestPriority = ServiceRequestPriority::factory()->create(); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('edit', [ - 'record' => $serviceRequestPriority, - ]) - )->assertForbidden(); - - livewire(ServiceRequestPriorityResource\Pages\EditServiceRequestPriority::class, [ - 'record' => $serviceRequestPriority->getRouteKey(), - ]) - ->assertForbidden(); - - $user->givePermissionTo('service_request_priority.view-any'); - $user->givePermissionTo('service_request_priority.*.update'); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('edit', [ - 'record' => $serviceRequestPriority, - ]) - )->assertSuccessful(); - - $request = collect(EditServiceRequestPriorityRequestFactory::new()->create()); - - livewire(ServiceRequestPriorityResource\Pages\EditServiceRequestPriority::class, [ - 'record' => $serviceRequestPriority->getRouteKey(), - ]) - ->fillForm($request->toArray()) - ->call('save') - ->assertHasNoFormErrors(); - - assertEquals($request['name'], $serviceRequestPriority->fresh()->name); -}); - -test('EditServiceRequestPriority is gated with proper feature access control', function () { - $settings = app(LicenseSettings::class); - - $settings->data->addons->serviceManagement = false; - - $settings->save(); - - $user = User::factory()->licensed([Student::getLicenseType(), Prospect::getLicenseType()])->create(); - - $user->givePermissionTo('service_request_priority.view-any'); - $user->givePermissionTo('service_request_priority.*.update'); - - $serviceRequestPriority = ServiceRequestPriority::factory()->create(); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('edit', [ - 'record' => $serviceRequestPriority, - ]) - )->assertForbidden(); - - livewire(EditServiceRequestPriority::class, [ - 'record' => $serviceRequestPriority->getRouteKey(), - ]) - ->assertForbidden(); - - $settings->data->addons->serviceManagement = true; - - $settings->save(); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('edit', [ - 'record' => $serviceRequestPriority, - ]) - )->assertSuccessful(); - - $request = collect(EditServiceRequestPriorityRequestFactory::new()->create()); - - livewire(EditServiceRequestPriority::class, [ - 'record' => $serviceRequestPriority->getRouteKey(), - ]) - ->fillForm($request->toArray()) - ->call('save') - ->assertHasNoFormErrors(); - - assertEquals($request['name'], $serviceRequestPriority->fresh()->name); -}); diff --git a/app-modules/service-management/tests/ServiceRequestPriority/ListServiceRequestPrioritiesTest.php b/app-modules/service-management/tests/ServiceRequestPriority/ListServiceRequestPrioritiesTest.php deleted file mode 100644 index 3865195d1d..0000000000 --- a/app-modules/service-management/tests/ServiceRequestPriority/ListServiceRequestPrioritiesTest.php +++ /dev/null @@ -1,133 +0,0 @@ - - - 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. - - -*/ - -use App\Models\User; - -use function Tests\asSuperAdmin; - -use App\Settings\LicenseSettings; - -use function Pest\Laravel\actingAs; -use function Pest\Livewire\livewire; - -use AdvisingApp\Prospect\Models\Prospect; -use AdvisingApp\StudentDataModel\Models\Student; -use AdvisingApp\ServiceManagement\Models\ServiceRequest; -use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource; - -test('The correct details are displayed on the ListServiceRequestPriorities page', function () { - $serviceRequestPriorities = ServiceRequestPriority::factory() - ->has(ServiceRequest::factory()->count(fake()->randomNumber(1)), 'serviceRequests') - ->count(3) - ->sequence( - ['name' => 'High', 'order' => 1], - ['name' => 'Medium', 'order' => 2], - ['name' => 'Low', 'order' => 3], - ) - ->create(); - - asSuperAdmin(); - - $component = livewire(ServiceRequestPriorityResource\Pages\ListServiceRequestPriorities::class); - - $component - ->assertSuccessful() - ->assertCanSeeTableRecords($serviceRequestPriorities) - ->assertCountTableRecords(3) - ->assertTableColumnExists('service_requests_count'); - - $serviceRequestPriorities->each( - fn (ServiceRequestPriority $serviceRequestPriority) => $component - ->assertTableColumnStateSet( - 'name', - $serviceRequestPriority->name, - $serviceRequestPriority - ) - ->assertTableColumnStateSet( - 'order', - $serviceRequestPriority->order, - $serviceRequestPriority - ) - // Currently setting not test for service_request_count as there is no easy way to check now, relying on underlying package tests - ); -}); - -// TODO: Sorting and Searching tests - -// Permission Tests - -test('ListServiceRequestPriorities is gated with proper access control', function () { - $user = User::factory()->licensed([Student::getLicenseType(), Prospect::getLicenseType()])->create(); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('index') - )->assertForbidden(); - - $user->givePermissionTo('service_request_priority.view-any'); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('index') - )->assertSuccessful(); -}); - -test('ListServiceRequestPriorities is gated with proper feature access control', function () { - $settings = app(LicenseSettings::class); - - $settings->data->addons->serviceManagement = false; - - $settings->save(); - - $user = User::factory()->licensed([Student::getLicenseType(), Prospect::getLicenseType()])->create(); - - $user->givePermissionTo('service_request_priority.view-any'); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl() - )->assertForbidden(); - - $settings->data->addons->serviceManagement = true; - - $settings->save(); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl() - )->assertSuccessful(); -}); diff --git a/app-modules/service-management/tests/ServiceRequestPriority/ViewServiceRequestPriorityTest.php b/app-modules/service-management/tests/ServiceRequestPriority/ViewServiceRequestPriorityTest.php deleted file mode 100644 index 788d6bfcb7..0000000000 --- a/app-modules/service-management/tests/ServiceRequestPriority/ViewServiceRequestPriorityTest.php +++ /dev/null @@ -1,126 +0,0 @@ - - - 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. - - -*/ - -use App\Models\User; - -use function Tests\asSuperAdmin; - -use App\Settings\LicenseSettings; - -use function Pest\Laravel\actingAs; - -use AdvisingApp\Prospect\Models\Prospect; -use AdvisingApp\StudentDataModel\Models\Student; -use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; -use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestPriorityResource; - -test('The correct details are displayed on the ViewServiceRequestPriority page', function () { - $serviceRequestPriority = ServiceRequestPriority::factory()->create(); - - asSuperAdmin() - ->get( - ServiceRequestPriorityResource::getUrl('view', [ - 'record' => $serviceRequestPriority, - ]) - ) - ->assertSuccessful() - ->assertSeeTextInOrder( - [ - 'Name', - $serviceRequestPriority->name, - 'Order', - $serviceRequestPriority->order, - ] - ); -}); - -// Permission Tests - -test('ViewServiceRequestPriority is gated with proper access control', function () { - $user = User::factory()->licensed([Student::getLicenseType(), Prospect::getLicenseType()])->create(); - - $prospectSource = ServiceRequestPriority::factory()->create(); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('view', [ - 'record' => $prospectSource, - ]) - )->assertForbidden(); - - $user->givePermissionTo('service_request_priority.view-any'); - $user->givePermissionTo('service_request_priority.*.view'); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('view', [ - 'record' => $prospectSource, - ]) - )->assertSuccessful(); -}); - -test('ViewServiceRequestPriority is gated with proper feature access control', function () { - $settings = app(LicenseSettings::class); - - $settings->data->addons->serviceManagement = false; - - $settings->save(); - - $user = User::factory()->licensed([Student::getLicenseType(), Prospect::getLicenseType()])->create(); - - $user->givePermissionTo('service_request_priority.view-any'); - $user->givePermissionTo('service_request_priority.*.view'); - - $serviceRequestPriority = ServiceRequestPriority::factory()->create(); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('view', [ - 'record' => $serviceRequestPriority, - ]) - )->assertForbidden(); - - $settings->data->addons->serviceManagement = true; - - $settings->save(); - - actingAs($user) - ->get( - ServiceRequestPriorityResource::getUrl('view', [ - 'record' => $serviceRequestPriority, - ]) - )->assertSuccessful(); -}); diff --git a/app-modules/student-data-model/src/Filament/Resources/StudentResource/RelationManagers/ServiceRequestsRelationManager.php b/app-modules/student-data-model/src/Filament/Resources/StudentResource/RelationManagers/ServiceRequestsRelationManager.php index ee753c69dd..2ba0a23a9f 100644 --- a/app-modules/student-data-model/src/Filament/Resources/StudentResource/RelationManagers/ServiceRequestsRelationManager.php +++ b/app-modules/student-data-model/src/Filament/Resources/StudentResource/RelationManagers/ServiceRequestsRelationManager.php @@ -45,7 +45,9 @@ use Filament\Tables\Columns\TextColumn; use Filament\Tables\Actions\CreateAction; use Filament\Tables\Filters\SelectFilter; +use Illuminate\Database\Eloquent\Builder; use App\Filament\Resources\RelationManagers\RelationManager; +use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestResource\Pages\ViewServiceRequest; use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestResource\Pages\CreateServiceRequest; @@ -84,7 +86,8 @@ public function table(Table $table): Table ]) ->filters([ SelectFilter::make('priority') - ->relationship('priority', 'name') + ->relationship('priority', 'name', fn (Builder $query) => $query->with('type')) + ->getOptionLabelFromRecordUsing(fn (ServiceRequestPriority $record) => "{$record->type->name} - {$record->name}") ->multiple() ->preload(), SelectFilter::make('status') diff --git a/app/Filament/Widgets/MyServiceRequests.php b/app/Filament/Widgets/MyServiceRequests.php index 550d11ed36..bce3b434fd 100644 --- a/app/Filament/Widgets/MyServiceRequests.php +++ b/app/Filament/Widgets/MyServiceRequests.php @@ -46,6 +46,7 @@ use Filament\Widgets\TableWidget as BaseWidget; use AdvisingApp\ServiceManagement\Models\ServiceRequest; use AdvisingApp\StudentDataModel\Models\Scopes\EducatableSort; +use AdvisingApp\ServiceManagement\Models\ServiceRequestPriority; use AdvisingApp\StudentDataModel\Models\Scopes\EducatableSearch; use AdvisingApp\ServiceManagement\Filament\Resources\ServiceRequestResource; @@ -92,7 +93,8 @@ public function table(Table $table): Table ]) ->filters([ SelectFilter::make('priority') - ->relationship('priority', 'name') + ->relationship('priority', 'name', fn (Builder $query) => $query->with('type')) + ->getOptionLabelFromRecordUsing(fn (ServiceRequestPriority $record) => "{$record->type->name} - {$record->name}") ->multiple() ->preload(), SelectFilter::make('status') diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 61c434a860..c684d8edbd 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -65,7 +65,6 @@ use AdvisingApp\ServiceManagement\Database\Seeders\ServiceRequestStatusSeeder; use AdvisingApp\ServiceManagement\Database\Seeders\ServiceRequestUpdateSeeder; use AdvisingApp\InventoryManagement\Database\Seeders\MaintenanceProviderSeeder; -use AdvisingApp\ServiceManagement\Database\Seeders\ServiceRequestPrioritySeeder; class DatabaseSeeder extends Seeder { @@ -80,7 +79,6 @@ public function run(): void SuperAdminProfileSeeder::class, UsersTableSeeder::class, DivisionSeeder::class, - ServiceRequestPrioritySeeder::class, ServiceRequestStatusSeeder::class, ServiceRequestTypeSeeder::class, ProspectStatusSeeder::class, diff --git a/database/seeders/DemoDatabaseSeeder.php b/database/seeders/DemoDatabaseSeeder.php index 3f1eea39df..2c5c14f4e4 100644 --- a/database/seeders/DemoDatabaseSeeder.php +++ b/database/seeders/DemoDatabaseSeeder.php @@ -54,7 +54,6 @@ use AdvisingApp\Application\Database\Seeders\ApplicationSubmissionStateSeeder; use AdvisingApp\ServiceManagement\Database\Seeders\ServiceRequestStatusSeeder; use AdvisingApp\InventoryManagement\Database\Seeders\MaintenanceProviderSeeder; -use AdvisingApp\ServiceManagement\Database\Seeders\ServiceRequestPrioritySeeder; class DemoDatabaseSeeder extends Seeder { @@ -69,7 +68,6 @@ public function run(): void SuperAdminProfileSeeder::class, UsersTableSeeder::class, DivisionSeeder::class, - ServiceRequestPrioritySeeder::class, ServiceRequestStatusSeeder::class, ServiceRequestTypeSeeder::class, ProspectStatusSeeder::class,