Skip to content

Commit

Permalink
Merge pull request #15519 from snipe/features/add_created_at_created_by
Browse files Browse the repository at this point in the history
Change `user_id` to `created_by`
  • Loading branch information
snipe authored Sep 20, 2024
2 parents cdb7ccb + b21c303 commit b83d1a0
Show file tree
Hide file tree
Showing 151 changed files with 1,172 additions and 407 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/SendAcceptanceReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function handle()
$query->where('accepted_at', null)
->where('declined_at', null);
})
->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.admin'])
->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.adminuser'])
->get();

$count = 0;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Accessories/AccessoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function store(ImageUploadRequest $request) : RedirectResponse
$accessory->purchase_date = request('purchase_date');
$accessory->purchase_cost = request('purchase_cost');
$accessory->qty = request('qty');
$accessory->user_id = auth()->id();
$accessory->created_by = auth()->id();
$accessory->supplier_id = request('supplier_id');
$accessory->notes = request('notes');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function store(AccessoryCheckoutRequest $request, Accessory $accessory) :
AccessoryCheckout::create([
'accessory_id' => $accessory->id,
'created_at' => Carbon::now(),
'user_id' => Auth::id(),
'created_by' => auth()->id(),
'assigned_to' => $target->id,
'assigned_type' => $target::class,
'note' => $request->input('note'),
Expand Down
12 changes: 8 additions & 4 deletions app/Http/Controllers/Api/AccessoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public function index(Request $request)
];


$accessories = Accessory::select('accessories.*')->with('category', 'company', 'manufacturer', 'checkouts', 'location', 'supplier')
->withCount('checkouts as checkouts_count');
$accessories = Accessory::select('accessories.*')
->with('category', 'company', 'manufacturer', 'checkouts', 'location', 'supplier', 'adminuser')
->withCount('checkouts as checkouts_count');

if ($request->filled('search')) {
$accessories = $accessories->TextSearch($request->input('search'));
Expand Down Expand Up @@ -110,7 +111,10 @@ public function index(Request $request)
break;
case 'supplier':
$accessories = $accessories->OrderSupplier($order);
break;
break;
case 'created_by':
$accessories = $accessories->OrderByCreatedByName($order);
break;
default:
$accessories = $accessories->orderBy($column_sort, $order);
break;
Expand Down Expand Up @@ -287,7 +291,7 @@ public function checkout(AccessoryCheckoutRequest $request, Accessory $accessory
AccessoryCheckout::create([
'accessory_id' => $accessory->id,
'created_at' => Carbon::now(),
'user_id' => Auth::id(),
'created_by' => auth()->id(),
'assigned_to' => $target->id,
'assigned_type' => $target::class,
'note' => $request->input('note'),
Expand Down
15 changes: 10 additions & 5 deletions app/Http/Controllers/Api/AssetMaintenancesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function index(Request $request) : JsonResponse | array
$this->authorize('view', Asset::class);

$maintenances = AssetMaintenance::select('asset_maintenances.*')
->with('asset', 'asset.model', 'asset.location', 'asset.defaultLoc', 'supplier', 'asset.company', 'asset.assetstatus', 'admin');
->with('asset', 'asset.model', 'asset.location', 'asset.defaultLoc', 'supplier', 'asset.company', 'asset.assetstatus', 'adminuser');

if ($request->filled('search')) {
$maintenances = $maintenances->TextSearch($request->input('search'));
Expand All @@ -48,6 +48,10 @@ public function index(Request $request) : JsonResponse | array
$maintenances->where('asset_maintenances.supplier_id', '=', $request->input('supplier_id'));
}

if ($request->filled('created_by')) {
$maintenances->where('asset_maintenances.created_by', '=', $request->input('created_by'));
}

if ($request->filled('asset_maintenance_type')) {
$maintenances->where('asset_maintenance_type', '=', $request->input('asset_maintenance_type'));
}
Expand All @@ -69,7 +73,7 @@ public function index(Request $request) : JsonResponse | array
'asset_tag',
'asset_name',
'serial',
'user_id',
'created_by',
'supplier',
'is_warranty',
'status_label',
Expand All @@ -79,8 +83,8 @@ public function index(Request $request) : JsonResponse | array
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';

switch ($sort) {
case 'user_id':
$maintenances = $maintenances->OrderAdmin($order);
case 'created_by':
$maintenances = $maintenances->OrderByCreatedBy($order);
break;
case 'supplier':
$maintenances = $maintenances->OrderBySupplier($order);
Expand Down Expand Up @@ -124,7 +128,7 @@ public function store(Request $request) : JsonResponse
// create a new model instance
$maintenance = new AssetMaintenance();
$maintenance->fill($request->all());
$maintenance->user_id = Auth::id();
$maintenance->created_by = auth()->id();

// Was the asset maintenance created?
if ($maintenance->save()) {
Expand Down Expand Up @@ -186,6 +190,7 @@ public function destroy($assetMaintenanceId) : JsonResponse
{
$this->authorize('update', Asset::class);
// Check if the asset maintenance exists

$assetMaintenance = AssetMaintenance::findOrFail($assetMaintenanceId);

$assetMaintenance->delete();
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/Api/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function index(Request $request, $action = null, $upcoming_status = null)
}

$assets = Asset::select('assets.*')
->with('location', 'assetstatus', 'company', 'defaultLoc','assignedTo',
->with('location', 'assetstatus', 'company', 'defaultLoc','assignedTo', 'adminuser','model.depreciation',
'model.category', 'model.manufacturer', 'model.fieldset','supplier'); //it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users.


Expand Down Expand Up @@ -371,6 +371,9 @@ public function index(Request $request, $action = null, $upcoming_status = null)
case 'assigned_to':
$assets->OrderAssigned($order);
break;
case 'created_by':
$assets->OrderByCreatedByName($order);
break;
default:
$numeric_sort = false;

Expand Down Expand Up @@ -590,7 +593,7 @@ public function store(StoreAssetRequest $request): JsonResponse
$asset->model()->associate(AssetModel::find((int) $request->get('model_id')));

$asset->fill($request->validated());
$asset->user_id = Auth::id();
$asset->created_by = auth()->id();

/**
* this is here just legacy reasons. Api\AssetController
Expand Down
33 changes: 28 additions & 5 deletions app/Http/Controllers/Api/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ public function index(Request $request) : array

$categories = Category::select([
'id',
'created_by',
'created_at',
'updated_at',
'name', 'category_type',
'use_default_eula',
'eula_text',
'require_acceptance',
'checkin_email',
'image'
])->withCount('accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count');
'image',
])
->with('adminuser')
->withCount('accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count');


/*
Expand Down Expand Up @@ -91,13 +94,33 @@ public function index(Request $request) : array
$categories->where('checkin_email', '=', $request->input('checkin_email'));
}

if ($request->filled('created_by')) {
$categories->where('created_by', '=', $request->input('created_by'));
}

if ($request->filled('created_at')) {
$categories->where('created_at', '=', $request->input('created_at'));
}

if ($request->filled('updated_at')) {
$categories->where('updated_at', '=', $request->input('updated_at'));
}

// Make sure the offset and limit are actually integers and do not exceed system limits
$offset = ($request->input('offset') > $categories->count()) ? $categories->count() : app('api_offset_value');
$limit = app('api_limit_value');

$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'assets_count';
$categories->orderBy($sort, $order);
$sort_override = $request->input('sort');
$column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'assets_count';

switch ($sort_override) {
case 'created_by':
$categories = $categories->OrderByCreatedBy($order);
break;
default:
$categories = $categories->orderBy($column_sort, $order);
break;
}

$total = $categories->count();
$categories = $categories->skip($offset)->take($limit)->get();
Expand Down
22 changes: 17 additions & 5 deletions app/Http/Controllers/Api/CompaniesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function index(Request $request) : JsonResponse | array

$companies = Company::withCount(['assets as assets_count' => function ($query) {
$query->AssetsForShow();
}])->withCount('licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'users as users_count');
}])->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'users as users_count');

if ($request->filled('search')) {
$companies->TextSearch($request->input('search'));
Expand All @@ -56,17 +56,29 @@ public function index(Request $request) : JsonResponse | array
$companies->where('email', '=', $request->input('email'));
}

if ($request->filled('created_by')) {
$companies->where('created_by', '=', $request->input('created_by'));
}


// Make sure the offset and limit are actually integers and do not exceed system limits
$offset = ($request->input('offset') > $companies->count()) ? $companies->count() : app('api_offset_value');
$limit = app('api_limit_value');


$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
$companies->orderBy($sort, $order);
$sort_override = $request->input('sort');
$column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at';

switch ($sort_override) {
case 'created_by':
$companies = $companies->OrderByCreatedBy($order);
break;
default:
$companies = $companies->orderBy($column_sort, $order);
break;
}

$total = $companies->count();

$companies = $companies->skip($offset)->take($limit)->get();
return (new CompaniesTransformer)->transformCompanies($companies, $total);

Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/Api/ComponentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function index(Request $request) : JsonResponse | array
];

$components = Component::select('components.*')
->with('company', 'location', 'category', 'assets', 'supplier');
->with('company', 'location', 'category', 'assets', 'supplier', 'adminuser');

if ($request->filled('search')) {
$components = $components->TextSearch($request->input('search'));
Expand Down Expand Up @@ -98,6 +98,9 @@ public function index(Request $request) : JsonResponse | array
case 'supplier':
$components = $components->OrderSupplier($order);
break;
case 'created_by':
$components = $components->OrderByCreatedBy($order);
break;
default:
$components = $components->orderBy($column_sort, $order);
break;
Expand Down Expand Up @@ -270,7 +273,7 @@ public function checkout(Request $request, $componentId) : JsonResponse
'component_id' => $component->id,
'created_at' => Carbon::now(),
'assigned_qty' => $request->get('assigned_qty', 1),
'user_id' => auth()->id(),
'created_by' => auth()->id(),
'asset_id' => $request->get('assigned_to'),
'note' => $request->get('note'),
]);
Expand Down
8 changes: 6 additions & 2 deletions app/Http/Controllers/Api/ConsumablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public function index(Request $request) : array
case 'supplier':
$consumables = $consumables->OrderSupplier($order);
break;
case 'created_by':
$consumables = $consumables->OrderByCreatedBy($order);
break;
default:
// This array is what determines which fields should be allowed to be sorted on ON the table itself.
// These must match a column on the consumables table directly.
Expand Down Expand Up @@ -228,7 +231,8 @@ public function getDataView($consumableId) : array
'name' => ($consumable_assignment->user) ? $consumable_assignment->user->present()->nameUrl() : 'Deleted User',
'created_at' => Helper::getFormattedDateObject($consumable_assignment->created_at, 'datetime'),
'note' => ($consumable_assignment->note) ? e($consumable_assignment->note) : null,
'admin' => ($consumable_assignment->admin) ? $consumable_assignment->admin->present()->nameUrl() : null,
'admin' => ($consumable_assignment->admin) ? $consumable_assignment->admin->present()->nameUrl() : null, // legacy, so we don't change the shape of the response
'created_by' => ($consumable_assignment->admin) ? $consumable_assignment->admin->present()->nameUrl() : null,
];
}

Expand Down Expand Up @@ -277,7 +281,7 @@ public function checkout(Request $request, $id) : JsonResponse
$consumable->users()->attach($consumable->id,
[
'consumable_id' => $consumable->id,
'user_id' => $user->id,
'created_by' => $user->id,
'assigned_to' => $request->input('assigned_to'),
'note' => $request->input('note'),
]
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/DepartmentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function store(ImageUploadRequest $request) : JsonResponse
$department->fill($request->all());
$department = $request->handleImages($department);

$department->user_id = auth()->id();
$department->created_by = auth()->id();
$department->manager_id = ($request->filled('manager_id') ? $request->input('manager_id') : null);

if ($department->save()) {
Expand Down
17 changes: 13 additions & 4 deletions app/Http/Controllers/Api/DepreciationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function index(Request $request) : JsonResponse | array
'licenses_count',
];

$depreciations = Depreciation::select('id','name','months','depreciation_min','depreciation_type','user_id','created_at','updated_at')
$depreciations = Depreciation::select('id','name','months','depreciation_min','depreciation_type','created_at','updated_at', 'created_by')
->with('adminuser')
->withCount('assets as assets_count')
->withCount('models as models_count')
->withCount('licenses as licenses_count');
Expand All @@ -44,10 +45,18 @@ public function index(Request $request) : JsonResponse | array
// Make sure the offset and limit are actually integers and do not exceed system limits
$offset = ($request->input('offset') > $depreciations->count()) ? $depreciations->count() : app('api_offset_value');
$limit = app('api_limit_value');

$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
$depreciations->orderBy($sort, $order);
$sort_override = $request->input('sort');
$column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at';

switch ($sort_override) {
case 'created_by':
$depreciations = $depreciations->OrderByCreatedBy($order);
break;
default:
$depreciations = $depreciations->orderBy($column_sort, $order);
break;
}

$total = $depreciations->count();
$depreciations = $depreciations->skip($offset)->take($limit)->get();
Expand Down
27 changes: 21 additions & 6 deletions app/Http/Controllers/Api/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public function index(Request $request) : JsonResponse | array
$this->authorize('superadmin');

$this->authorize('view', Group::class);
$allowed_columns = ['id', 'name', 'created_at', 'users_count'];

$groups = Group::select('id', 'name', 'permissions', 'created_at', 'updated_at', 'created_by')->with('admin')->withCount('users as users_count');
$groups = Group::select('id', 'name', 'permissions', 'created_at', 'updated_at', 'created_by')->with('adminuser')->withCount('users as users_count');

if ($request->filled('search')) {
$groups = $groups->TextSearch($request->input('search'));
Expand All @@ -35,13 +34,29 @@ public function index(Request $request) : JsonResponse | array
$groups->where('name', '=', $request->input('name'));
}

// Make sure the offset and limit are actually integers and do not exceed system limits

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

$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
$groups->orderBy($sort, $order);

switch ($request->input('sort')) {
case 'created_by':
$groups = $groups->OrderByCreatedBy($order);
break;
default:
// This array is what determines which fields should be allowed to be sorted on ON the table itself.
// These must match a column on the consumables table directly.
$allowed_columns = [
'id',
'name',
'created_at',
'users_count',
];

$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
$groups = $groups->orderBy($sort, $order);
break;
}

$total = $groups->count();
$groups = $groups->skip($offset)->take($limit)->get();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/LicenseSeatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function update(Request $request, $licenseId, $seatId) : JsonResponse | a

// attempt to update the license seat
$licenseSeat->fill($request->all());
$licenseSeat->user_id = auth()->id();
$licenseSeat->created_by = auth()->id();

// check if this update is a checkin operation
// 1. are relevant fields touched at all?
Expand Down
Loading

0 comments on commit b83d1a0

Please sign in to comment.