Skip to content

Commit 21baea2

Browse files
authored
Merge pull request #18141 from uberbrady/actiontype_enum_redux
Actiontype enum redux
2 parents e1d3714 + 27d7449 commit 21baea2

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

app/Enums/ActionType.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
enum ActionType: string
5+
{
6+
// General
7+
case Create = 'create';
8+
case Update = 'update';
9+
case Delete = 'delete';
10+
case Restore = 'restore';
11+
12+
// Assets/Accessories/Components/Licenses/Consumables
13+
case Checkout = 'checkout';
14+
case CheckinFrom = 'checkin from';
15+
case Requested = 'requested';
16+
case RequestCanceled = 'request canceled';
17+
case Accepted = 'accepted';
18+
case Declined = 'declined';
19+
case Audit = 'audit';
20+
case NoteAdded = 'note added';
21+
22+
// Users
23+
case TwoFactorReset = '2FA reset';
24+
case Merged = 'merged';
25+
26+
// Licenses
27+
case DeleteSeats = 'delete seats';
28+
case AddSeats = 'add seats';
29+
30+
// File Uploads
31+
case Uploaded = 'uploaded';
32+
case UploadDeleted = 'upload deleted';
33+
}

app/Http/Controllers/ViewAssetsController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Actions\CheckoutRequests\CancelCheckoutRequestAction;
66
use App\Actions\CheckoutRequests\CreateCheckoutRequestAction;
7+
use App\Enums\ActionType;
78
use App\Exceptions\AssetNotRequestable;
89
use App\Models\Actionlog;
910
use App\Models\Asset;
@@ -201,7 +202,7 @@ public function getRequestItem(Request $request, $itemType, $itemId = null, $can
201202
if (($item_request = $item->isRequestedBy($user)) || $cancel_by_admin) {
202203
$item->cancelRequest($requestingUser);
203204
$data['item_quantity'] = ($item_request) ? $item_request->qty : 1;
204-
$logaction->logaction('request_canceled');
205+
$logaction->logaction(ActionType::RequestCanceled);
205206

206207
if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) {
207208
$settings->notify(new RequestAssetCancelation($data));

app/Models/Actionlog.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Database\Eloquent\Factories\HasFactory;
1010
use Illuminate\Database\Eloquent\SoftDeletes;
1111
use Illuminate\Support\Str;
12+
use App\Enums\ActionType;
1213

1314
/**
1415
* Model for the Actionlog (the table that keeps a historical log of
@@ -335,9 +336,12 @@ public function get_src($type = 'assets', $fieldname = 'filename')
335336
* @since [v3.0]
336337
* @return bool
337338
*/
338-
public function logaction($actiontype)
339+
public function logaction(string|ActionType $actiontype)
339340
{
340-
$this->action_type = $actiontype;
341+
if (is_string($actiontype)) {
342+
$actiontype = ActionType::from($actiontype);
343+
}
344+
$this->action_type = $actiontype->value;
341345
$this->remote_ip = request()->ip();
342346
$this->user_agent = request()->header('User-Agent');
343347
$this->action_source = $this->determineActionSource();

app/Presenters/ActionlogPresenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function icon()
102102
return 'fa-solid fa-rotate-right';
103103
}
104104

105-
if ($this->action_type == 'note_added') {
105+
if ($this->action_type == 'note added') {
106106
return 'fas fa-sticky-note';
107107
}
108108

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
15+
/**
16+
* We actually *do* have an index on action_type, so this query shouldn't take too terribly long. I don't know
17+
* that we have a ton of people canceling requests (and only certain types of request-cancellation use this
18+
* erroneous action_type), so I feel pretty comfortable with this fixup. Fingers crossed!
19+
* */
20+
21+
DB::table('action_logs')->where('action_type', 'request_canceled')->update(['action_type' => 'request canceled']);
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*/
27+
public function down(): void
28+
{
29+
// no down migration for this one
30+
}
31+
};

0 commit comments

Comments
 (0)