Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/Enums/ActionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Enums;
enum ActionType: string
{
// General
case Create = 'create';
case Update = 'update';
case Delete = 'delete';
case Restore = 'restore';

// Assets/Accessories/Components/Licenses/Consumables
case Checkout = 'checkout';
case CheckinFrom = 'checkin from';
case Requested = 'requested';
case RequestCanceled = 'request canceled';
case Accepted = 'accepted';
case Declined = 'declined';
case Audit = 'audit';
case NoteAdded = 'note added';

// Users
case TwoFactorReset = '2FA reset';
case Merged = 'merged';

// Licenses
case DeleteSeats = 'delete seats';
case AddSeats = 'add seats';

// File Uploads
case Uploaded = 'uploaded';
case UploadDeleted = 'upload deleted';
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/ViewAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) {
$settings->notify(new RequestAssetCancelation($data));
Expand Down
8 changes: 6 additions & 2 deletions app/Models/Actionlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use App\Enums\ActionType;

/**
* Model for the Actionlog (the table that keeps a historical log of
Expand Down Expand Up @@ -335,9 +336,12 @@ public function get_src($type = 'assets', $fieldname = 'filename')
* @since [v3.0]
* @return bool
*/
public function logaction($actiontype)
public function logaction(string|ActionType $actiontype)
{
$this->action_type = $actiontype;
if (is_string($actiontype)) {
$actiontype = ActionType::from($actiontype);
}
$this->action_type = $actiontype->value;
Comment on lines +341 to +344
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we're keeping the existing behavior around (passing in a string) while also checking that the string is a valid type using ::from 👍🏾

$this->remote_ip = request()->ip();
$this->user_agent = request()->header('User-Agent');
$this->action_source = $this->determineActionSource();
Expand Down
2 changes: 1 addition & 1 deletion app/Presenters/ActionlogPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function icon()
return 'fa-solid fa-rotate-right';
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

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

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{

/**
* We actually *do* have an index on action_type, so this query shouldn't take too terribly long. I don't know
* that we have a ton of people canceling requests (and only certain types of request-cancellation use this
* erroneous action_type), so I feel pretty comfortable with this fixup. Fingers crossed!
* */

DB::table('action_logs')->where('action_type', 'request_canceled')->update(['action_type' => 'request canceled']);
}

/**
* Reverse the migrations.
*/
public function down(): void
{
// no down migration for this one
}
};
Loading