Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADVAPP-131]: Reviewing and Approving Change Requests #466

Merged
merged 16 commits into from
Jan 24, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CreateEvent extends Command

public function handle(): int
{
$user = User::where('email', 'sampleadmin@advising.app')->first();
$user = User::where('email', config('local_development.super_admin.email'))->first();

$user->calendar
->events()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SyncEvents extends Command

public function handle(): int
{
$user = User::where('email', 'sampleadmin@advising.app')->first();
$user = User::where('email', config('local_development.super_admin.email'))->first();

resolve(CalendarManager::class)
->driver($user->calendar->provider_type->value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function definition(): array
'change_request_status_id' => ChangeRequestStatus::factory(),
'title' => fake()->sentence(),
'description' => fake()->text(),
'reason' => fake()->paragraphs(1),
'backout_strategy' => fake()->paragraphs(1),
'reason' => fake()->paragraphs(1, true),
'backout_strategy' => fake()->paragraphs(1, true),
'impact' => fake()->numberBetween(1, 5),
'likelihood' => fake()->numberBetween(1, 5),
'start_time' => fake()->dateTime(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/*
<COPYRIGHT>

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.

</COPYRIGHT>
*/

namespace AdvisingApp\ServiceManagement\Database\Factories;

use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use AdvisingApp\ServiceManagement\Models\ChangeRequest;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\AdvisingApp\ServiceManagement\Models\ChangeRequestResponse>
*/
class ChangeRequestResponseFactory extends Factory
{
public function definition(): array
{
return [
'change_request_id' => ChangeRequest::factory(),
'user_id' => User::factory(),
'approved' => $this->faker->boolean,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function definition(): array
{
return [
'name' => fake()->word(),
'number_of_required_approvals' => fake()->numberBetween(0, 2),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function up(): void
Schema::create('change_request_types', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('name');
$table->integer('number_of_required_approvals');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
<COPYRIGHT>

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.

</COPYRIGHT>
*/

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class () extends Migration {
public function up(): void
{
Schema::create('change_request_responses', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->foreignUuid('change_request_id')->constrained('change_requests')->cascadeOnDelete();
$table->foreignUuid('user_id')->constrained('users');
$table->boolean('approved');
$table->timestamps();
$table->softDeletes();
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,30 @@

namespace AdvisingApp\ServiceManagement\Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;
use AdvisingApp\ServiceManagement\Models\ChangeRequestType;

class ChangeRequestTypeSeeder extends Seeder
{
public function run(): void
{
$types = ['Standard Change', 'Normal Change', 'Emergency Change'];
$types = [
['Normal Change', 0],
['Standard Change', 1],
['Emergency Change', 2],
];

foreach ($types as $type) {
ChangeRequestType::factory()
$changeRequestType = ChangeRequestType::factory()
->create([
'name' => $type,
'name' => $type[0],
'number_of_required_approvals' => $type[1],
]);

if (! app()->environment('production')) {
$changeRequestType->userApprovers()->attach(User::where('email', config('local_development.super_admin.email'))->first()->id);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ServiceRequestSeeder extends Seeder
{
public function run(): void
{
$superAdmin = User::where('email', 'sampleadmin@advising.app')->first();
$superAdmin = User::where('email', config('local_development.super_admin.email'))->first();

ServiceRequest::factory()
->has(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/*
<COPYRIGHT>

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.

</COPYRIGHT>
*/

namespace AdvisingApp\ServiceManagement\Actions\ChangeRequest;

use App\Models\User;
use AdvisingApp\ServiceManagement\Models\ChangeRequest;
use AdvisingApp\ServiceManagement\Models\ChangeRequestStatus;
use AdvisingApp\ServiceManagement\Models\Scopes\ClassifiedAs;
use AdvisingApp\ServiceManagement\Enums\SystemChangeRequestClassification;

class ApproveChangeRequest
{
public function __construct(
public ChangeRequest $changeRequest,
public User $user,
) {}

public function handle(): void
{
if ($this->changeRequest->isApproved() || $this->changeRequest->hasApproval()) {
return;
}

if ($this->changeRequest->canBeApprovedBy($this->user)) {
$this->changeRequest->responses()->create([
'user_id' => $this->user->id,
'approved' => true,
]);
}

if ($this->changeRequest->hasApproval()) {
$this->changeRequest->getStateMachine(SystemChangeRequestClassification::class, 'status.classification')
->transitionTo(
relatedModel: ChangeRequestStatus::tap(new ClassifiedAs(SystemChangeRequestClassification::Approved))->first(),
newState: SystemChangeRequestClassification::Approved
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,29 @@
namespace AdvisingApp\ServiceManagement\Enums;

use Filament\Support\Contracts\HasLabel;
use Bvtterfly\ModelStateMachine\Attributes\InitialState;
use Bvtterfly\ModelStateMachine\Attributes\AllowTransitionTo;

enum SystemChangeRequestClassification: string implements HasLabel
{
#[InitialState]
#[AllowTransitionTo(self::Approved)]
case New = 'new';

#[AllowTransitionTo(self::InProgress)]
case Approved = 'approved';

#[AllowTransitionTo(self::Completed)]
#[AllowTransitionTo(self::FailedOrReverted)]
#[AllowTransitionTo(self::Custom)]
case InProgress = 'in_progress';

case Completed = 'completed';

case FailedOrReverted = 'failed_or_reverted';

#[AllowTransitionTo(self::Completed)]
#[AllowTransitionTo(self::FailedOrReverted)]
case Custom = 'custom';

public function getLabel(): ?string
Expand All @@ -60,4 +70,16 @@ public function getLabel(): ?string
default => $this->name,
};
}

public function getDescription(): ?string
{
return match ($this) {
SystemChangeRequestClassification::Approved => 'has been approved',
SystemChangeRequestClassification::InProgress => 'is in progress',
SystemChangeRequestClassification::Completed => 'has been completed',
SystemChangeRequestClassification::FailedOrReverted => 'has failed or been reverted',
SystemChangeRequestClassification::Custom => 'is in a custom state',
default => null,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@

namespace AdvisingApp\ServiceManagement\Filament\Resources;

use Carbon\CarbonInterface;
use Filament\Infolists\Infolist;
use Filament\Resources\Resource;
use Filament\Infolists\Components\Section;
use App\Filament\Clusters\ServiceManagement;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Components\ViewEntry;
use AdvisingApp\ServiceManagement\Models\ChangeRequest;
use AdvisingApp\ServiceManagement\Filament\Resources\ChangeRequestResource\Pages\EditChangeRequest;
use AdvisingApp\ServiceManagement\Filament\Resources\ChangeRequestResource\Pages\ViewChangeRequest;
use AdvisingApp\ServiceManagement\Filament\Resources\ChangeRequestResource\Pages\ListChangeRequests;
use AdvisingApp\ServiceManagement\Filament\Resources\ChangeRequestResource\Pages\CreateChangeRequest;

Expand All @@ -62,58 +58,12 @@ class ChangeRequestResource extends Resource

protected static ?string $cluster = ServiceManagement::class;

public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Section::make('Change Request Details')
->schema([
TextEntry::make('title')
->columnSpan(3),
TextEntry::make('description')
->columnSpan(3),
TextEntry::make('type.name')
->label('Type')
->columnSpan(3),
TextEntry::make('status.name')
->label('Status')
->columnSpan(3),
TextEntry::make('reason')
->label('Reason for change')
->columnSpanFull(),
TextEntry::make('backout_strategy')
->columnSpanFull(),
TextEntry::make('start_time')
->dateTime()
->columnSpan(2),
TextEntry::make('end_time')
->dateTime()
->columnSpan(2),
TextEntry::make('created_at')
->label('Duration')
->state(fn ($record) => $record->end_time->diffForHumans($record->start_time, CarbonInterface::DIFF_ABSOLUTE, true, 6))
->columnSpan(2),
])
->columns(6),
Section::make('Risk Management')
->schema([
TextEntry::make('impact')
->columnSpan(1),
TextEntry::make('likelihood')
->columnSpan(1),
ViewEntry::make('risk_score')
->view('filament.infolists.entries.change-request.risk-score')
->columnSpan(1),
])
->columns(3),
]);
}

public static function getPages(): array
{
return [
'index' => ListChangeRequests::route('/'),
'create' => CreateChangeRequest::route('/create'),
'view' => ViewChangeRequest::route('/{record}'),
'edit' => EditChangeRequest::route('/{record}/edit'),
];
}
Expand Down
Loading