Skip to content

Commit

Permalink
Merge pull request #159 from canyongbs/features/aidapp-137
Browse files Browse the repository at this point in the history
[AIDAPP-137]: Prevent Ticket Reopening in Aiding App
  • Loading branch information
Orrison authored Jul 3, 2024
2 parents 0defc90 + 74d274a commit 4411211
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,37 @@
namespace AidingApp\ServiceManagement\Enums;

use Filament\Support\Contracts\HasLabel;
use Bvtterfly\ModelStateMachine\Attributes\InitialState;
use Bvtterfly\ModelStateMachine\Attributes\AllowTransitionTo;
use AidingApp\ServiceManagement\Models\Contracts\ClassificationInterface;

enum SystemServiceRequestClassification: string implements HasLabel, ClassificationInterface
{
#[InitialState]
#[AllowTransitionTo(self::InProgress)]
#[AllowTransitionTo(self::Closed)]
#[AllowTransitionTo(self::Waiting)]
#[AllowTransitionTo(self::Custom)]
case Open = 'open';

#[AllowTransitionTo(self::Open)]
#[AllowTransitionTo(self::Closed)]
#[AllowTransitionTo(self::Waiting)]
#[AllowTransitionTo(self::Custom)]
case InProgress = 'in_progress';

case Closed = 'closed';

#[AllowTransitionTo(self::Open)]
#[AllowTransitionTo(self::Closed)]
#[AllowTransitionTo(self::InProgress)]
#[AllowTransitionTo(self::Custom)]
case Waiting = 'waiting';

#[AllowTransitionTo(self::Open)]
#[AllowTransitionTo(self::InProgress)]
#[AllowTransitionTo(self::Closed)]
#[AllowTransitionTo(self::Waiting)]
case Custom = 'custom';

public function getLabel(): ?string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
use AidingApp\ServiceManagement\Models\ServiceRequest;
use AidingApp\ServiceManagement\Enums\SlaComplianceStatus;
use AidingApp\ServiceManagement\Models\ServiceRequestPriority;
use AidingApp\ServiceManagement\Enums\SystemServiceRequestClassification;
use AidingApp\ServiceManagement\Filament\Resources\ServiceRequestResource;

class ListServiceRequests extends ListRecords
Expand Down Expand Up @@ -116,7 +117,8 @@ public function table(Table $table): Table
])
->actions([
ViewAction::make(),
EditAction::make(),
EditAction::make()
->visible(fn (ServiceRequest $record) => $record->status?->classification === SystemServiceRequestClassification::Closed ? false : true),
])
->bulkActions([
BulkActionGroup::make([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
namespace AidingApp\ServiceManagement\Filament\Resources\ServiceRequestResource\Pages;

use Carbon\CarbonInterval;
use Filament\Actions\Action;
use Laravel\Pennant\Feature;
use Filament\Actions\EditAction;
use Filament\Infolists\Infolist;
Expand All @@ -47,12 +48,12 @@
use Filament\Infolists\Components\IconEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Components\ViewEntry;
use Filament\Infolists\Components\Actions\Action;
use AidingApp\ServiceManagement\Models\ServiceRequest;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use AidingApp\Contact\Filament\Resources\ContactResource;
use AidingApp\ServiceManagement\Enums\SlaComplianceStatus;
use Filament\Infolists\Components\IconEntry\IconEntrySize;
use AidingApp\ServiceManagement\Enums\SystemServiceRequestClassification;
use AidingApp\ServiceManagement\Filament\Resources\ServiceRequestResource;
use AidingApp\ServiceManagement\Actions\ResolveUploadsMediaCollectionForServiceRequest;

Expand Down Expand Up @@ -215,6 +216,13 @@ protected function getHeaderActions(): array
{
return [
EditAction::make(),
Action::make('locked_service_request')
->icon('heroicon-o-lock-closed')
->color('gray')
->tooltip('This service request is locked as status is closed.')
->disabled()
->visible(fn (ServiceRequest $record) => fn (ServiceRequest $record) => $record->status?->classification === SystemServiceRequestClassification::Closed ? false : true)
->iconButton(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

namespace AidingApp\ServiceManagement\Notifications;

use Illuminate\Support\Str;
use App\Models\NotificationSetting;
use AidingApp\Notification\Models\OutboundDeliverable;
use AidingApp\ServiceManagement\Models\ServiceRequest;
Expand All @@ -60,10 +61,15 @@ public function toEmail(object $notifiable): MailMessage

return MailMessage::make()
->settings($this->resolveNotificationSetting($notifiable))
->subject("{$this->serviceRequest->service_request_number} - is now {$status->name}")
->greeting("Hi {$name},")
->line("Your request {$this->serviceRequest->service_request_number} for service is now {$status->name}.")
->salutation('Thank you.');
->subject(__('[Ticket #:ticketno]: Your Issue Has Been Resolved', ['ticketno' => $this->serviceRequest->service_request_number]))
->greeting("Dear {$name},")
->line(__('We wanted to update you that the issue you reported in Ticket #:ticketNo regarding :shortDescription has been :status.', [
'ticketNo' => $this->serviceRequest->service_request_number,
'status' => $status->name,
'shortDescription' => Str::limit($this->serviceRequest->res_details, 10, '...'),
]))
->line('If you experience any further issues or have additional questions, please do not hesitate to open a new ticket.')
->salutation('Thank you for giving us a chance to help you with your issue.');
}

protected function beforeSendHook(object $notifiable, OutboundDeliverable $deliverable, string $channel): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use AidingApp\Contact\Models\Contact;
use App\Support\FeatureAccessResponse;
use AidingApp\ServiceManagement\Models\ServiceRequest;
use AidingApp\ServiceManagement\Enums\SystemServiceRequestClassification;

class ServiceRequestPolicy
{
Expand Down Expand Up @@ -95,6 +96,10 @@ public function update(Authenticatable $authenticatable, ServiceRequest $service
return Response::deny('You do not have permission to update this service request.');
}

if ($serviceRequest?->status?->classification === SystemServiceRequestClassification::Closed) {
return Response::deny('Closed service request cannot be edited.');
}

return $authenticatable->canOrElse(
abilities: ['service_request.*.update', "service_request.{$serviceRequest->id}.update"],
denyResponse: 'You do not have permission to update this service request.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
use AidingApp\ServiceManagement\Filament\Resources\ServiceRequestResource\Pages\EditServiceRequest;

test('A successful action on the EditServiceRequest page', function () {
$serviceRequest = ServiceRequest::factory()->create();
$serviceRequest = ServiceRequest::factory([
'status_id' => ServiceRequestStatus::factory()->create([
'classification' => SystemServiceRequestClassification::Open,
])->id,
])->create();

asSuperAdmin()
->get(
Expand All @@ -67,7 +71,11 @@
)
->assertSuccessful();

$request = collect(EditServiceRequestRequestFactory::new()->create());
$request = collect(EditServiceRequestRequestFactory::new([
'status_id' => ServiceRequestStatus::factory()->create([
'classification' => SystemServiceRequestClassification::InProgress,
])->id,
])->create());

livewire(EditServiceRequest::class, [
'record' => $serviceRequest->getRouteKey(),
Expand Down Expand Up @@ -98,7 +106,11 @@
});

test('EditServiceRequest requires valid data', function ($data, $errors) {
$serviceRequest = ServiceRequest::factory()->create();
$serviceRequest = ServiceRequest::factory([
'status_id' => ServiceRequestStatus::factory()->create([
'classification' => SystemServiceRequestClassification::Open,
])->id,
])->create();

asSuperAdmin();

Expand Down Expand Up @@ -146,7 +158,11 @@
test('EditServiceRequest is gated with proper access control', function () {
$user = User::factory()->licensed(LicenseType::cases())->create();

$serviceRequest = ServiceRequest::factory()->create();
$serviceRequest = ServiceRequest::factory([
'status_id' => ServiceRequestStatus::factory()->create([
'classification' => SystemServiceRequestClassification::Waiting,
])->id,
])->create();

actingAs($user)
->get(
Expand All @@ -170,7 +186,11 @@
])
)->assertSuccessful();

$request = collect(EditServiceRequestRequestFactory::new()->create());
$request = collect(EditServiceRequestRequestFactory::new([
'status_id' => ServiceRequestStatus::factory()->create([
'classification' => SystemServiceRequestClassification::Open,
])->id,
])->create());

livewire(EditServiceRequest::class, [
'record' => $serviceRequest->getRouteKey(),
Expand Down Expand Up @@ -262,7 +282,11 @@

$user = User::factory()->licensed(LicenseType::cases())->create();

$serviceRequest = ServiceRequest::factory()->create();
$serviceRequest = ServiceRequest::factory([
'status_id' => ServiceRequestStatus::factory()->create([
'classification' => SystemServiceRequestClassification::Open,
])->id,
])->create();

$user->givePermissionTo('service_request.view-any');
$user->givePermissionTo('service_request.*.update');
Expand Down

0 comments on commit 4411211

Please sign in to comment.