Skip to content

A free open source IT asset/license management system

Added archived to transformer

snipe059e14b434f4
diff --git a/app/Http/Transformers/AccessoriesTransformer.php b/app/Http/Transformers/AccessoriesTransformer.php
index da49af7d55..675648a770 100644
--- a/app/Http/Transformers/AccessoriesTransformer.php
+++ b/app/Http/Transformers/AccessoriesTransformer.php
@@ -63,6 +63,7 @@ class AccessoriesTransformer
] : null,
'notes' => ($accessory->notes) ? Helper::parseEscapedMarkedownInline($accessory->notes) : null,
'requestable' => (bool) $accessory->requestable,
+ 'archived' => (bool) $accessory->archived,
'qty' => ($accessory->qty) ? (int) $accessory->qty : null,
'percent_remaining' => round($accessory->percentRemaining()),
'purchase_date' => ($lastDefaults['purchase_date'] ?? null) ? Helper::getFormattedDateObject($lastDefaults['purchase_date'], 'date') : null,
@@ -87,6 +88,7 @@ class AccessoriesTransformer
] : null,
'created_at' => Helper::getFormattedDateObject($accessory->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($accessory->updated_at, 'datetime'),
+ 'deleted_at' => Helper::getFormattedDateObject($accessory->deleted_at, 'datetime'),
];
@@ -103,21 +105,39 @@ class AccessoriesTransformer
$permissions_array = [];
$permissions_array['assigned_to_self'] = $userHasOpenRequest;
+ // Soft-deleted rows surface in the Deleted index view with
+ // their write-ish actions rendered disabled, not hidden, by
+ // the per-row formatter. Keep the policy-gated flags true so
+ // the disabled stand-ins render. The formatter inspects
+ // row.deleted_at to flip them to their disabled state.
+ $isDeleted = $accessory->deleted_at !== null;
+ $canUpdate = Gate::allows('update', $accessory);
+ $canDelete = $accessory->checkouts_count === 0 && Gate::allows('delete', $accessory);
+
$permissions_array['available_actions'] = [
'checkout' => Gate::allows('checkout', $accessory),
'checkin' => false,
- 'update' => Gate::allows('update', $accessory),
- 'adjust_quantity' => Gate::allows('update', $accessory),
- 'delete' => $accessory->checkouts_count === 0 && Gate::allows('delete', $accessory),
+ 'update' => $canUpdate && ! $isDeleted,
+ 'adjust_quantity' => $canUpdate,
+ 'delete' => $canDelete,
+ // Cloning a deleted accessory is explicitly allowed. It
+ // produces a brand-new row and leaves the deleted parent
+ // untouched, so it's safe as a restore-and-tweak shortcut.
'clone' => Gate::allows('clone', $accessory),
// Request / cancel: if the requestable flag is off the row
// never surfaces on /account/requestable anyway (scoped out
// by Requestable()), but honor it here too for
// any consumer hitting the standard index endpoint.
- 'request' => (bool) $accessory->requestable && ! $userHasOpenRequest,
+ 'request' => (bool) $accessory->requestable && ! $isDeleted && ! $userHasOpenRequest,
'cancel' => (bool) $accessory->requestable && $userHasOpenRequest,
'bulk_selectable' => [
- 'delete' => $accessory->checkouts_count === 0,
+ // Edit/delete only make sense for live rows. On soft-
+ // deleted rows the bulk-actions dropdown offers Restore.
+ 'edit' => $canUpdate && ! $isDeleted,
+ 'delete' => $canDelete && ! $isDeleted,
+ // Restore is only meaningful on the Deleted index.
+ // Delete-tier action (matches postRestore pattern).
+ 'restore' => $isDeleted && Gate::allows('delete', $accessory),
],
];
@@ -184,7 +204,9 @@ class AccessoriesTransformer
'name' => e($checkout->adminuser->present()->fullName),
] : null,
'created_at' => Helper::getFormattedDateObject($checkout->created_at, 'datetime'),
- 'available_actions' => Gate::allows('checkout', $checkout->accessory) ? ['checkin' => true] : ['checkin' => false],
+ 'available_actions' => Gate::allows('checkin', $checkout->accessory)
+ ? ['checkin' => true, 'bulk_selectable' => ['checkin' => true]]
+ : ['checkin' => false],
];
}