Skip to content

Commit

Permalink
Merge branch 'develop' into testing/consumable-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe authored Dec 19, 2024
2 parents d763feb + dc5dedd commit 26264e1
Show file tree
Hide file tree
Showing 328 changed files with 3,708 additions and 2,081 deletions.
2 changes: 2 additions & 0 deletions app/Console/Commands/RestoreFromBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function parse_sql(string $line): string {
/* we *could* have made the ^INSERT INTO blah VALUES$ turn on the capturing state, and closed it with
a ^(blahblah);$ but it's cleaner to not have to manage the state machine. We're just going to
assume that (blahblah), or (blahblah); are values for INSERT and are always acceptable. */
"<^/\*!40101 SET NAMES '?[a-zA-Z0-9_-]+'? \*/;$>" => false, //using weird delimiters (<,>) for readability. allow quoted or unquoted charsets
"<^/\*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' \*/;$>" => false, //same, now handle zero-values
];

foreach($allowed_statements as $statement => $statechange) {
Expand Down
11 changes: 7 additions & 4 deletions app/Http/Controllers/Accessories/AccessoryCheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,23 @@ public function store(AccessoryCheckoutRequest $request, Accessory $accessory) :
$accessory->checkout_qty = $request->input('checkout_qty', 1);

for ($i = 0; $i < $accessory->checkout_qty; $i++) {
AccessoryCheckout::create([

$accessory_checkout = new AccessoryCheckout([
'accessory_id' => $accessory->id,
'created_at' => Carbon::now(),
'created_by' => auth()->id(),
'assigned_to' => $target->id,
'assigned_type' => $target::class,
'note' => $request->input('note'),
]);

$accessory_checkout->created_by = auth()->id();
$accessory_checkout->save();
}

event(new CheckoutableCheckedOut($accessory, $target, auth()->user(), $request->input('note')));

// Set this as user since we only allow checkout to user for this item type
$request->request->add(['checkout_to_type' => request('checkout_to_type')]);
$request->request->add(['assigned_user' => $target->id]);
$request->request->add(['assigned_to' => $target->id]);

session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);

Expand Down
40 changes: 19 additions & 21 deletions app/Http/Controllers/Api/AccessoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Models\Accessory;
use App\Models\Company;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -184,39 +185,33 @@ public function accessory_detail($id)


/**
* Display the specified resource.
* Get the list of checkouts for a specific accessory
*
* @author [A. Gianotto] [<[email protected]>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
* @return | array
*/
public function checkedout($id, Request $request)
public function checkedout(Request $request, $id)
{
$this->authorize('view', Accessory::class);

$accessory = Accessory::with('lastCheckout')->findOrFail($id);

$offset = request('offset', 0);
$limit = request('limit', 50);

$accessory_checkouts = $accessory->checkouts;
$total = $accessory_checkouts->count();

if ($total < $offset) {
$offset = 0;
}

$accessory_checkouts = $accessory->checkouts()->skip($offset)->take($limit)->get();
// Total count of all checkouts for this asset
$accessory_checkouts = $accessory->checkouts();

// Check for search text in the request
if ($request->filled('search')) {

$accessory_checkouts = $accessory->checkouts()->TextSearch($request->input('search'))
->get();
$total = $accessory_checkouts->count();
$accessory_checkouts = $accessory_checkouts->TextSearch($request->input('search'));
}

return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory, $accessory_checkouts, $total);
$total = $accessory_checkouts->count();
$accessory_checkouts = $accessory_checkouts->skip($offset)->take($limit)->get();

return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory_checkouts, $total);
}


Expand All @@ -227,7 +222,7 @@ public function checkedout($id, Request $request)
* @since [v4.0]
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function update(ImageUploadRequest $request, $id)
{
Expand All @@ -249,7 +244,7 @@ public function update(ImageUploadRequest $request, $id)
* @author [A. Gianotto] [<[email protected]>]
* @since [v4.0]
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function destroy($id)
{
Expand Down Expand Up @@ -284,14 +279,17 @@ public function checkout(AccessoryCheckoutRequest $request, Accessory $accessory
$accessory->checkout_qty = $request->input('checkout_qty', 1);

for ($i = 0; $i < $accessory->checkout_qty; $i++) {
AccessoryCheckout::create([

$accessory_checkout = new AccessoryCheckout([
'accessory_id' => $accessory->id,
'created_at' => Carbon::now(),
'created_by' => auth()->id(),
'assigned_to' => $target->id,
'assigned_type' => $target::class,
'note' => $request->input('note'),
]);

$accessory_checkout->created_by = auth()->id();
$accessory_checkout->save();
}

// Set this value to be able to pass the qty through to the event
Expand Down
27 changes: 24 additions & 3 deletions app/Http/Controllers/Api/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Requests\StoreAssetRequest;
use App\Http\Requests\UpdateAssetRequest;
use App\Http\Traits\MigratesLegacyAssetLocations;
use App\Models\AccessoryCheckout;
use App\Models\CheckoutAcceptance;
use App\Models\LicenseSeat;
use Illuminate\Database\Eloquent\Builder;
Expand All @@ -26,11 +27,9 @@
use App\Models\Location;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;
use App\View\Label;
Expand Down Expand Up @@ -129,6 +128,7 @@ public function index(Request $request, $action = null, $upcoming_status = null)

$assets = Asset::select('assets.*')
->with(
'model',
'location',
'assetstatus',
'company',
Expand All @@ -140,7 +140,7 @@ public function index(Request $request, $action = null, $upcoming_status = null)
'model.manufacturer',
'model.fieldset',
'supplier'
); //it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users.
); // it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users.


if ($filter_non_deprecable_assets) {
Expand Down Expand Up @@ -1214,6 +1214,27 @@ public function requestable(Request $request): JsonResponse | array
return (new AssetsTransformer)->transformRequestedAssets($assets, $total);
}


public function assignedAssets(Request $request, Asset $asset) : JsonResponse | array
{

return [];
// to do
}

public function assignedAccessories(Request $request, Asset $asset) : JsonResponse | array
{
$this->authorize('view', Asset::class);
$this->authorize('view', $asset);
$accessory_checkouts = AccessoryCheckout::AssetsAssigned()->with('adminuser')->with('accessories');

$offset = ($request->input('offset') > $accessory_checkouts->count()) ? $accessory_checkouts->count() : app('api_offset_value');
$limit = app('api_limit_value');

$total = $accessory_checkouts->count();
$accessory_checkouts = $accessory_checkouts->skip($offset)->take($limit)->get();
return (new AssetsTransformer)->transformCheckedoutAccessories($accessory_checkouts, $total);
}
/**
* Generate asset labels by tag
*
Expand Down
64 changes: 48 additions & 16 deletions app/Http/Controllers/Api/LocationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
namespace App\Http\Controllers\Api;

use App\Helpers\Helper;
use App\Http\Requests\ImageUploadRequest;
use App\Http\Controllers\Controller;
use App\Http\Requests\ImageUploadRequest;
use App\Http\Transformers\AccessoriesTransformer;
use App\Http\Transformers\AssetsTransformer;
use App\Http\Transformers\LocationsTransformer;
use App\Http\Transformers\SelectlistTransformer;
use App\Models\Accessory;
use App\Models\AccessoryCheckout;
use App\Models\Asset;
use App\Models\Location;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Http\JsonResponse;

class LocationsController extends Controller
{
Expand All @@ -28,26 +31,28 @@ public function index(Request $request) : JsonResponse | array
{
$this->authorize('view', Location::class);
$allowed_columns = [
'id',
'name',
'accessories_count',
'address',
'address2',
'assets_count',
'assets_count',
'assigned_accessories_count',
'assigned_assets_count',
'assigned_assets_count',
'city',
'state',
'country',
'zip',
'created_at',
'updated_at',
'manager_id',
'image',
'assigned_assets_count',
'users_count',
'assets_count',
'assigned_assets_count',
'assets_count',
'rtd_assets_count',
'currency',
'id',
'image',
'ldap_ou',
'manager_id',
'name',
'rtd_assets_count',
'state',
'updated_at',
'users_count',
'zip',
];

$locations = Location::with('parent', 'manager', 'children')->select([
Expand All @@ -68,8 +73,11 @@ public function index(Request $request) : JsonResponse | array
'locations.image',
'locations.ldap_ou',
'locations.currency',
])->withCount('assignedAssets as assigned_assets_count')
])
->withCount('assignedAssets as assigned_assets_count')
->withCount('assets as assets_count')
->withCount('assignedAccessories as assigned_accessories_count')
->withCount('accessories as accessories_count')
->withCount('rtd_assets as rtd_assets_count')
->withCount('children as children_count')
->withCount('users as users_count');
Expand Down Expand Up @@ -224,7 +232,17 @@ public function update(ImageUploadRequest $request, $id) : JsonResponse
return response()->json(Helper::formatStandardApiResponse('error', null, $location->getErrors()));
}


public function assets(Request $request, Location $location) : JsonResponse | array
{
$this->authorize('view', Asset::class);
$this->authorize('view', $location);
$assets = Asset::where('location_id', '=', $location->id)->with('model', 'model.category', 'assetstatus', 'location', 'company', 'defaultLoc');
$assets = $assets->get();
return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request);
}

public function assignedAssets(Request $request, Location $location) : JsonResponse | array
{
$this->authorize('view', Asset::class);
$this->authorize('view', $location);
Expand All @@ -233,6 +251,20 @@ public function assets(Request $request, Location $location) : JsonResponse | ar
return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request);
}

public function assignedAccessories(Request $request, Location $location) : JsonResponse | array
{
$this->authorize('view', Accessory::class);
$this->authorize('view', $location);
$accessory_checkouts = AccessoryCheckout::LocationAssigned()->with('adminuser')->with('accessories');

$offset = ($request->input('offset') > $accessory_checkouts->count()) ? $accessory_checkouts->count() : app('api_offset_value');
$limit = app('api_limit_value');

$total = $accessory_checkouts->count();
$accessory_checkouts = $accessory_checkouts->skip($offset)->take($limit)->get();
return (new LocationsTransformer)->transformCheckedoutAccessories($accessory_checkouts, $total);
}

/**
* Remove the specified resource from storage.
*
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public function getQrCode($assetId = null) : Response | BinaryFileResponse | str
if ($settings->qr_code == '1') {
$asset = Asset::withTrashed()->find($assetId);
if ($asset) {
$size = Helper::barcodeDimensions($settings->barcode_type);
$size = Helper::barcodeDimensions($settings->label2_2d_type);
$qr_file = public_path().'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png';

if (isset($asset->id, $asset->asset_tag)) {
Expand All @@ -548,7 +548,7 @@ public function getQrCode($assetId = null) : Response | BinaryFileResponse | str
return response()->file($qr_file, $header);
} else {
$barcode = new \Com\Tecnick\Barcode\Barcode();
$barcode_obj = $barcode->getBarcodeObj($settings->barcode_type, route('hardware.show', $asset->id), $size['height'], $size['width'], 'black', [-2, -2, -2, -2]);
$barcode_obj = $barcode->getBarcodeObj($settings->label2_2d_type, route('hardware.show', $asset->id), $size['height'], $size['width'], 'black', [-2, -2, -2, -2]);
file_put_contents($qr_file, $barcode_obj->getPngData());

return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
Expand All @@ -573,7 +573,7 @@ public function getBarCode($assetId = null)
{
$settings = Setting::getSettings();
if ($asset = Asset::withTrashed()->find($assetId)) {
$barcode_file = public_path().'/uploads/barcodes/'.str_slug($settings->alt_barcode).'-'.str_slug($asset->asset_tag).'.png';
$barcode_file = public_path().'/uploads/barcodes/'.str_slug($settings->label2_1d_type).'-'.str_slug($asset->asset_tag).'.png';

if (isset($asset->id, $asset->asset_tag)) {
if (file_exists($barcode_file)) {
Expand All @@ -586,7 +586,7 @@ public function getBarCode($assetId = null)

$barcode = new \Com\Tecnick\Barcode\Barcode();
try {
$barcode_obj = $barcode->getBarcodeObj($settings->alt_barcode, $asset->asset_tag, ($barcode_width < 300 ? $barcode_width : 300), 50);
$barcode_obj = $barcode->getBarcodeObj($settings->label2_1d_type, $asset->asset_tag, ($barcode_width < 300 ? $barcode_width : 300), 50);
file_put_contents($barcode_file, $barcode_obj->getPngData());

return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public function getEmailSubject()
*/
public function sendResetLinkEmail(Request $request)
{

/**
* Let's set a max character count here to prevent potential
* buffer overflow issues with attackers sending very large
* payloads through.
* payloads through. The addition of the string rule prevents attackers
* sending arrays through and causing 500s
*/
$request->validate([
'username' => ['required', 'max:255'],
'username' => ['required', 'max:255', 'string'],
]);

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/CustomFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function store(CustomFieldRequest $request) : RedirectResponse
"auto_add_to_fieldsets" => $request->get("auto_add_to_fieldsets", 0),
"show_in_listview" => $request->get("show_in_listview", 0),
"show_in_requestable_list" => $request->get("show_in_requestable_list", 0),
"user_id" => auth()->id()
"created_by" => auth()->id()
]);


Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Licenses/LicenseCheckinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function store(Request $request, $seatId = null, $backTo = null)

if (! $license->reassignable) {
// Not allowed to checkin
Session::flash('error', 'License not reassignable.');
Session::flash('error', trans('admin/licenses/message.checkin.not_reassignable') . '.');

return redirect()->back()->withInput();
}
Expand Down
Loading

0 comments on commit 26264e1

Please sign in to comment.