Skip to content

Commit b483eed

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 3ff5161 + fab85da commit b483eed

35 files changed

+721
-84
lines changed

app/Http/Controllers/Account/AcceptanceController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ public function store(Request $request, $id) : RedirectResponse
157157
'accepted_date' => Helper::getFormattedDateObject(now()->format('Y-m-d H:i:s'), 'datetime', false),
158158
'declined_date' => Helper::getFormattedDateObject(now()->format('Y-m-d H:i:s'), 'datetime', false),
159159
'assigned_to' => $assigned_user->display_name,
160+
'email' => $assigned_user->email,
161+
'employee_num' => $assigned_user->employee_num,
160162
'site_name' => $settings->site_name,
161163
'company_name' => $item->company?->name?? $settings->site_name,
162164
'signature' => (($sig_filename && array_key_exists('1', $encoded_image))) ? $encoded_image[1] : null,

app/Http/Controllers/Api/AccessoriesController.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,39 @@ public function index(Request $request)
5454
'notes',
5555
'checkouts_count',
5656
'qty',
57+
// These are *relationships* so we wouldn't normally include them in this array,
58+
// since they would normally create a `column not found` error,
59+
// BUT we account for them in the ordering switch down at the end of this method
60+
// DO NOT ADD ANYTHING TO THIS LIST WITHOUT CHECKING THE ORDERING SWITCH BELOW!
61+
'company',
62+
'location',
63+
'category',
64+
'supplier',
65+
'manufacturer',
5766
];
5867

5968

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

64-
if ($request->filled('search')) {
65-
$accessories = $accessories->TextSearch($request->input('search'));
73+
$filter = [];
74+
75+
if ($request->filled('filter')) {
76+
$filter = json_decode($request->input('filter'), true);
77+
$filter = array_filter($filter, function ($key) use ($allowed_columns) {
78+
return in_array($key, $allowed_columns);
79+
}, ARRAY_FILTER_USE_KEY);
80+
6681
}
6782

83+
if ((! is_null($filter)) && (count($filter)) > 0) {
84+
$accessories->ByFilter($filter);
85+
} elseif ($request->filled('search')) {
86+
$accessories->TextSearch($request->input('search'));
87+
}
88+
89+
6890
if ($request->filled('company_id')) {
6991
$accessories->where('accessories.company_id', '=', $request->input('company_id'));
7092
}

app/Http/Controllers/Api/AssetModelsController.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public function index(Request $request) : JsonResponse | array
5454
'deleted_at',
5555
'updated_at',
5656
'require_serial',
57+
// These are *relationships* so we wouldn't normally include them in this array,
58+
// since they would normally create a `column not found` error,
59+
// BUT we account for them in the ordering switch down at the end of this method
60+
// DO NOT ADD ANYTHING TO THIS LIST WITHOUT CHECKING THE ORDERING SWITCH BELOW!
61+
'manufacturer',
62+
'category',
5763
];
5864

5965
$assetmodels = AssetModel::select([
@@ -81,6 +87,24 @@ public function index(Request $request) : JsonResponse | array
8187
->withCount('assignedAssets as assets_assigned_count')
8288
->withCount('archivedAssets as assets_archived_count');
8389

90+
$filter = [];
91+
92+
if ($request->filled('filter')) {
93+
$filter = json_decode($request->input('filter'), true);
94+
95+
$filter = array_filter($filter, function ($key) use ($allowed_columns) {
96+
return in_array($key, $allowed_columns);
97+
}, ARRAY_FILTER_USE_KEY);
98+
99+
}
100+
101+
if ((! is_null($filter)) && (count($filter)) > 0) {
102+
$assetmodels->ByFilter($filter);
103+
} elseif ($request->filled('search')) {
104+
$assetmodels->TextSearch($request->input('search'));
105+
}
106+
107+
84108
if ($request->input('status')=='deleted') {
85109
$assetmodels->onlyTrashed();
86110
}

app/Http/Controllers/Api/CategoriesController.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ public function index(Request $request) : array
6161
->withCount('accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count', 'models as models_count');
6262

6363

64+
$filter = [];
65+
66+
if ($request->filled('filter')) {
67+
$filter = json_decode($request->input('filter'), true);
68+
69+
$filter = array_filter($filter, function ($key) use ($allowed_columns) {
70+
return in_array($key, $allowed_columns);
71+
}, ARRAY_FILTER_USE_KEY);
72+
73+
}
74+
75+
if ((! is_null($filter)) && (count($filter)) > 0) {
76+
$categories->ByFilter($filter);
77+
} elseif ($request->filled('search')) {
78+
$categories->TextSearch($request->input('search'));
79+
}
80+
6481
/*
6582
* This checks to see if we should override the Admin Setting to show archived assets in list.
6683
* We don't currently use it within the Snipe-IT GUI, but will be useful for API integrations where they
@@ -74,10 +91,6 @@ public function index(Request $request) : array
7491
$categories = $categories->withCount('showableAssets as assets_count');
7592
}
7693

77-
if ($request->filled('search')) {
78-
$categories = $categories->TextSearch($request->input('search'));
79-
}
80-
8194
if ($request->filled('name')) {
8295
$categories->where('name', '=', $request->input('name'));
8396
}

app/Http/Controllers/Api/ComponentsController.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,40 @@ public function index(Request $request) : JsonResponse | array
4545
'qty',
4646
'image',
4747
'notes',
48+
// These are *relationships* so we wouldn't normally include them in this array,
49+
// since they would normally create a `column not found` error,
50+
// BUT we account for them in the ordering switch down at the end of this method
51+
// DO NOT ADD ANYTHING TO THIS LIST WITHOUT CHECKING THE ORDERING SWITCH BELOW!
52+
'company',
53+
'location',
54+
'category',
55+
'manufacturer',
56+
'supplier',
57+
4858
];
4959

5060
$components = Component::select('components.*')
5161
->with('company', 'location', 'category', 'assets', 'supplier', 'adminuser', 'manufacturer', 'uncontrainedAssets')
5262
->withSum('uncontrainedAssets', 'components_assets.assigned_qty');
5363

54-
if ($request->filled('search')) {
55-
$components = $components->TextSearch($request->input('search'));
64+
$filter = [];
65+
66+
if ($request->filled('filter')) {
67+
$filter = json_decode($request->input('filter'), true);
68+
69+
$filter = array_filter($filter, function ($key) use ($allowed_columns) {
70+
return in_array($key, $allowed_columns);
71+
}, ARRAY_FILTER_USE_KEY);
72+
73+
}
74+
75+
if ((! is_null($filter)) && (count($filter)) > 0) {
76+
$components->ByFilter($filter);
77+
} elseif ($request->filled('search')) {
78+
$components->TextSearch($request->input('search'));
5679
}
5780

81+
5882
if ($request->filled('name')) {
5983
$components->where('name', '=', $request->input('name'));
6084
}

app/Http/Controllers/Api/ConsumablesController.php

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,53 @@ public function index(Request $request) : array
3131
$consumables = Consumable::with('company', 'location', 'category', 'supplier', 'manufacturer')
3232
->withCount('users as consumables_users_count');
3333

34-
if ($request->filled('search')) {
35-
$consumables = $consumables->TextSearch(e($request->input('search')));
34+
// This array is what determines which fields should be allowed to be sorted on ON the table itself.
35+
// These must match a column on the consumables table directly.
36+
$allowed_columns = [
37+
'id',
38+
'name',
39+
'order_number',
40+
'min_amt',
41+
'purchase_date',
42+
'purchase_cost',
43+
'company',
44+
'category',
45+
'model_number',
46+
'item_no',
47+
'manufacturer',
48+
'location',
49+
'qty',
50+
'image',
51+
// These are *relationships* so we wouldn't normally include them in this array,
52+
// since they would normally create a `column not found` error,
53+
// BUT we account for them in the ordering switch down at the end of this method
54+
// DO NOT ADD ANYTHING TO THIS LIST WITHOUT CHECKING THE ORDERING SWITCH BELOW!
55+
'company',
56+
'location',
57+
'category',
58+
'supplier',
59+
'manufacturer',
60+
];
61+
62+
63+
$filter = [];
64+
65+
if ($request->filled('filter')) {
66+
$filter = json_decode($request->input('filter'), true);
67+
68+
$filter = array_filter($filter, function ($key) use ($allowed_columns) {
69+
return in_array($key, $allowed_columns);
70+
}, ARRAY_FILTER_USE_KEY);
71+
72+
}
73+
74+
if ((! is_null($filter)) && (count($filter)) > 0) {
75+
$consumables->ByFilter($filter);
76+
} elseif ($request->filled('search')) {
77+
$consumables->TextSearch($request->input('search'));
3678
}
3779

80+
3881
if ($request->filled('name')) {
3982
$consumables->where('name', '=', $request->input('name'));
4083
}
@@ -96,25 +139,6 @@ public function index(Request $request) : array
96139
$consumables = $consumables->OrderByCreatedBy($order);
97140
break;
98141
default:
99-
// This array is what determines which fields should be allowed to be sorted on ON the table itself.
100-
// These must match a column on the consumables table directly.
101-
$allowed_columns = [
102-
'id',
103-
'name',
104-
'order_number',
105-
'min_amt',
106-
'purchase_date',
107-
'purchase_cost',
108-
'company',
109-
'category',
110-
'model_number',
111-
'item_no',
112-
'manufacturer',
113-
'location',
114-
'qty',
115-
'image'
116-
];
117-
118142
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
119143
$consumables = $consumables->orderBy($sort, $order);
120144
break;

app/Http/Controllers/Api/UsersController.php

Lines changed: 69 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,75 @@ public function index(Request $request) : array
103103
'managedLocations as manages_locations_count'
104104
]);
105105

106-
107-
if ($request->filled('search') != '') {
108-
$users = $users->TextSearch($request->input('search'));
106+
$allowed_columns =
107+
[
108+
'last_name',
109+
'first_name',
110+
'display_name',
111+
'email',
112+
'jobtitle',
113+
'username',
114+
'employee_num',
115+
'groups',
116+
'activated',
117+
'created_at',
118+
'updated_at',
119+
'two_factor_enrolled',
120+
'two_factor_optin',
121+
'last_login',
122+
'assets_count',
123+
'licenses_count',
124+
'consumables_count',
125+
'accessories_count',
126+
'manages_users_count',
127+
'manages_locations_count',
128+
'phone',
129+
'mobile',
130+
'address',
131+
'city',
132+
'state',
133+
'country',
134+
'zip',
135+
'id',
136+
'ldap_import',
137+
'two_factor_optin',
138+
'two_factor_enrolled',
139+
'remote',
140+
'vip',
141+
'start_date',
142+
'end_date',
143+
'autoassign_licenses',
144+
'website',
145+
'locale',
146+
'notes',
147+
'employee_num',
148+
149+
// These are *relationships* so we wouldn't normally include them in this array,
150+
// since they would normally create a `column not found` error,
151+
// BUT we account for them in the ordering switch down at the end of this method
152+
// DO NOT ADD ANYTHING TO THIS LIST WITHOUT CHECKING THE ORDERING SWITCH BELOW!
153+
'company',
154+
'location',
155+
'department',
156+
'manager',
157+
'created_by',
158+
159+
];
160+
161+
$filter = [];
162+
163+
if ($request->filled('filter')) {
164+
$filter = json_decode($request->input('filter'), true);
165+
$filter = array_filter($filter, function ($key) use ($allowed_columns) {
166+
return in_array($key, $allowed_columns);
167+
}, ARRAY_FILTER_USE_KEY);
168+
169+
}
170+
171+
if ((! is_null($filter)) && (count($filter)) > 0) {
172+
$users->ByFilter($filter);
173+
} elseif ($request->filled('search')) {
174+
$users->TextSearch($request->input('search'));
109175
}
110176

111177
if ($request->filled('activated')) {
@@ -286,49 +352,6 @@ public function index(Request $request) : array
286352
$users->orderBy('first_name', $order);
287353
break;
288354
default:
289-
$allowed_columns =
290-
[
291-
'last_name',
292-
'first_name',
293-
'display_name',
294-
'email',
295-
'jobtitle',
296-
'username',
297-
'employee_num',
298-
'groups',
299-
'activated',
300-
'created_at',
301-
'updated_at',
302-
'two_factor_enrolled',
303-
'two_factor_optin',
304-
'last_login',
305-
'assets_count',
306-
'licenses_count',
307-
'consumables_count',
308-
'accessories_count',
309-
'manages_users_count',
310-
'manages_locations_count',
311-
'phone',
312-
'mobile',
313-
'address',
314-
'city',
315-
'state',
316-
'country',
317-
'zip',
318-
'id',
319-
'ldap_import',
320-
'two_factor_optin',
321-
'two_factor_enrolled',
322-
'remote',
323-
'vip',
324-
'start_date',
325-
'end_date',
326-
'autoassign_licenses',
327-
'website',
328-
'locale',
329-
'notes',
330-
];
331-
332355
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'first_name';
333356
$users = $users->orderBy($sort, $order);
334357
break;

0 commit comments

Comments
 (0)