Skip to content

Commit c8fbf76

Browse files
committed
Merge remote-tracking branch 'origin/develop'
Signed-off-by: snipe <[email protected]> # Conflicts: # public/css/build/app.css # public/css/build/overrides.css # public/css/dist/all.css # public/mix-manifest.json
2 parents 6f40b21 + 46779ca commit c8fbf76

File tree

13 files changed

+200
-48
lines changed

13 files changed

+200
-48
lines changed

app/Http/Controllers/Api/UsersController.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public function index(Request $request)
7575
'users.autoassign_licenses',
7676
'users.website',
7777

78-
])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy',)
79-
->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count');
78+
])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy')
79+
->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'managesUsers as manages_users_count', 'managedLocations as manages_locations_count');
8080

8181

8282
if ($request->filled('activated')) {
@@ -187,6 +187,14 @@ public function index(Request $request)
187187
$users->has('accessories', '=', $request->input('accessories_count'));
188188
}
189189

190+
if ($request->filled('manages_users_count')) {
191+
$users->has('manages_users_count', '=', $request->input('manages_users_count'));
192+
}
193+
194+
if ($request->filled('manages_locations_count')) {
195+
$users->has('manages_locations_count', '=', $request->input('manages_locations_count'));
196+
}
197+
190198
if ($request->filled('autoassign_licenses')) {
191199
$users->where('autoassign_licenses', '=', $request->input('autoassign_licenses'));
192200
}
@@ -244,6 +252,8 @@ public function index(Request $request)
244252
'licenses_count',
245253
'consumables_count',
246254
'accessories_count',
255+
'manages_user_count',
256+
'manages_locations_count',
247257
'phone',
248258
'address',
249259
'city',
@@ -405,11 +415,15 @@ public function show($id)
405415
{
406416
$this->authorize('view', User::class);
407417

408-
$user = User::withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count')->findOrFail($id);
409-
$user = Company::scopeCompanyables($user)->find($id);
410-
$this->authorize('update', $user);
418+
$user = User::withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'managesUsers as manages_users_count', 'managedLocations as manages_locations_count');
419+
420+
if ($user = Company::scopeCompanyables($user)->find($id)) {
421+
$this->authorize('view', $user);
422+
return (new UsersTransformer)->transformUser($user);
423+
}
424+
425+
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_not_found', compact('id'))));
411426

412-
return (new UsersTransformer)->transformUser($user);
413427
}
414428

415429

@@ -470,7 +484,6 @@ public function update(SaveUserRequest $request, $id)
470484
}
471485

472486

473-
474487
// Update the location of any assets checked out to this user
475488
Asset::where('assigned_type', User::class)
476489
->where('assigned_to', $user->id)->update(['location_id' => $request->input('location_id', null)]);
@@ -480,12 +493,6 @@ public function update(SaveUserRequest $request, $id)
480493

481494
if ($user->save()) {
482495

483-
// Sync group memberships:
484-
// This was changed in Snipe-IT v4.6.x to 4.7, since we upgraded to Laravel 5.5
485-
// which changes the behavior of has vs filled.
486-
// The $request->has method will now return true even if the input value is an empty string or null.
487-
// A new $request->filled method has was added that provides the previous behavior of the has method.
488-
489496
// Check if the request has groups passed and has a value
490497
if ($request->filled('groups')) {
491498

app/Http/Middleware/AssetCountForSidebar.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,36 @@ public function handle($request, Closure $next)
2121
/**
2222
* This needs to be set for the /setup process, since the tables might not exist yet
2323
*/
24+
$total_assets = 0;
2425
$total_due_for_checkin = 0;
2526
$total_overdue_for_checkin = 0;
2627
$total_due_for_audit = 0;
2728
$total_overdue_for_audit = 0;
2829

2930
try {
30-
$total_rtd_sidebar = Asset::RTD()->count();
31-
view()->share('total_rtd_sidebar', $total_rtd_sidebar);
31+
$settings = Setting::getSettings();
32+
view()->share('settings', $settings);
3233
} catch (\Exception $e) {
3334
\Log::debug($e);
3435
}
3536

3637
try {
37-
$total_assets = Asset::RTD()->count();
38+
$total_assets = Asset::all()->count();
39+
if ($settings->show_archived_in_list != '1') {
40+
$total_assets -= Asset::Archived()->count();
41+
}
3842
view()->share('total_assets', $total_assets);
3943
} catch (\Exception $e) {
4044
\Log::debug($e);
4145
}
4246

47+
try {
48+
$total_rtd_sidebar = Asset::RTD()->count();
49+
view()->share('total_rtd_sidebar', $total_rtd_sidebar);
50+
} catch (\Exception $e) {
51+
\Log::debug($e);
52+
}
53+
4354
try {
4455
$total_deployed_sidebar = Asset::Deployed()->count();
4556
view()->share('total_deployed_sidebar', $total_deployed_sidebar);
@@ -75,13 +86,6 @@ public function handle($request, Closure $next)
7586
\Log::debug($e);
7687
}
7788

78-
try {
79-
$settings = Setting::getSettings();
80-
view()->share('settings', $settings);
81-
} catch (\Exception $e) {
82-
\Log::debug($e);
83-
}
84-
8589
try {
8690
$total_due_for_audit = Asset::DueForAudit($settings)->count();
8791
view()->share('total_due_for_audit', $total_due_for_audit);

app/Http/Transformers/UsersTransformer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function transformUsers(Collection $users, $total)
2121

2222
public function transformUser(User $user)
2323
{
24+
2425
$array = [
2526
'id' => (int) $user->id,
2627
'avatar' => e($user->present()->gravatar),
@@ -64,6 +65,8 @@ public function transformUser(User $user)
6465
'licenses_count' => (int) $user->licenses_count,
6566
'accessories_count' => (int) $user->accessories_count,
6667
'consumables_count' => (int) $user->consumables_count,
68+
'manages_users_count' => (int) $user->manages_users_count,
69+
'manages_locations_count' => (int) $user->manages_locations_count,
6770
'company' => ($user->company) ? ['id' => (int) $user->company->id, 'name'=> e($user->company->name)] : null,
6871
'created_by' => ($user->createdBy) ? [
6972
'id' => (int) $user->createdBy->id,

app/Models/User.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,12 @@ public function isSuperUser()
214214
public function isDeletable()
215215
{
216216
return Gate::allows('delete', $this)
217-
&& ($this->assets()->count() === 0)
218-
&& ($this->licenses()->count() === 0)
219-
&& ($this->consumables()->count() === 0)
220-
&& ($this->accessories()->count() === 0)
217+
&& ($this->assets->count() === 0)
218+
&& ($this->licenses->count() === 0)
219+
&& ($this->consumables->count() === 0)
220+
&& ($this->accessories->count() === 0)
221+
&& ($this->managedLocations->count() === 0)
222+
&& ($this->managesUsers->count() === 0)
221223
&& ($this->deleted_at == '');
222224
}
223225

@@ -410,6 +412,19 @@ public function manager()
410412
return $this->belongsTo(self::class, 'manager_id')->withTrashed();
411413
}
412414

415+
/**
416+
* Establishes the user -> managed users relationship
417+
*
418+
* @author A. Gianotto <[email protected]>
419+
* @since [v6.4.1]
420+
* @return \Illuminate\Database\Eloquent\Relations\Relation
421+
*/
422+
public function managesUsers()
423+
{
424+
return $this->hasMany(\App\Models\User::class, 'manager_id');
425+
}
426+
427+
413428
/**
414429
* Establishes the user -> managed locations relationship
415430
*

app/Presenters/UserPresenter.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static function dataTableLayout()
221221
'switchable' => true,
222222
'escape' => true,
223223
'class' => 'css-barcode',
224-
'title' => 'Assets',
224+
'title' => trans('general.assets'),
225225
'visible' => true,
226226
],
227227
[
@@ -230,7 +230,7 @@ public static function dataTableLayout()
230230
'sortable' => true,
231231
'switchable' => true,
232232
'class' => 'css-license',
233-
'title' => 'License',
233+
'title' => trans('general.licenses'),
234234
'visible' => true,
235235
],
236236
[
@@ -239,7 +239,7 @@ public static function dataTableLayout()
239239
'sortable' => true,
240240
'switchable' => true,
241241
'class' => 'css-consumable',
242-
'title' => 'Consumables',
242+
'title' => trans('general.consumables'),
243243
'visible' => true,
244244
],
245245
[
@@ -248,7 +248,25 @@ public static function dataTableLayout()
248248
'sortable' => true,
249249
'switchable' => true,
250250
'class' => 'css-accessory',
251-
'title' => 'Accessories',
251+
'title' => trans('general.accessories'),
252+
'visible' => true,
253+
],
254+
[
255+
'field' => 'manages_users_count',
256+
'searchable' => false,
257+
'sortable' => true,
258+
'switchable' => true,
259+
'class' => 'css-users',
260+
'title' => trans('admin/users/table.managed_users'),
261+
'visible' => true,
262+
],
263+
[
264+
'field' => 'manages_locations_count',
265+
'searchable' => false,
266+
'sortable' => true,
267+
'switchable' => true,
268+
'class' => 'css-location',
269+
'title' => trans('admin/users/table.managed_locations'),
252270
'visible' => true,
253271
],
254272
[

0 commit comments

Comments
 (0)