Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
snipe committed May 8, 2024
2 parents 6f40b21 + 46779ca commit c8fbf76
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 48 deletions.
33 changes: 20 additions & 13 deletions app/Http/Controllers/Api/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public function index(Request $request)
'users.autoassign_licenses',
'users.website',

])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy',)
->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count');
])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy')
->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');


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

if ($request->filled('manages_users_count')) {
$users->has('manages_users_count', '=', $request->input('manages_users_count'));
}

if ($request->filled('manages_locations_count')) {
$users->has('manages_locations_count', '=', $request->input('manages_locations_count'));
}

if ($request->filled('autoassign_licenses')) {
$users->where('autoassign_licenses', '=', $request->input('autoassign_licenses'));
}
Expand Down Expand Up @@ -244,6 +252,8 @@ public function index(Request $request)
'licenses_count',
'consumables_count',
'accessories_count',
'manages_user_count',
'manages_locations_count',
'phone',
'address',
'city',
Expand Down Expand Up @@ -405,11 +415,15 @@ public function show($id)
{
$this->authorize('view', User::class);

$user = User::withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count')->findOrFail($id);
$user = Company::scopeCompanyables($user)->find($id);
$this->authorize('update', $user);
$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');

if ($user = Company::scopeCompanyables($user)->find($id)) {
$this->authorize('view', $user);
return (new UsersTransformer)->transformUser($user);
}

return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_not_found', compact('id'))));

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


Expand Down Expand Up @@ -470,7 +484,6 @@ public function update(SaveUserRequest $request, $id)
}



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

if ($user->save()) {

// Sync group memberships:
// This was changed in Snipe-IT v4.6.x to 4.7, since we upgraded to Laravel 5.5
// which changes the behavior of has vs filled.
// The $request->has method will now return true even if the input value is an empty string or null.
// A new $request->filled method has was added that provides the previous behavior of the has method.

// Check if the request has groups passed and has a value
if ($request->filled('groups')) {

Expand Down
24 changes: 14 additions & 10 deletions app/Http/Middleware/AssetCountForSidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,36 @@ public function handle($request, Closure $next)
/**
* This needs to be set for the /setup process, since the tables might not exist yet
*/
$total_assets = 0;
$total_due_for_checkin = 0;
$total_overdue_for_checkin = 0;
$total_due_for_audit = 0;
$total_overdue_for_audit = 0;

try {
$total_rtd_sidebar = Asset::RTD()->count();
view()->share('total_rtd_sidebar', $total_rtd_sidebar);
$settings = Setting::getSettings();
view()->share('settings', $settings);
} catch (\Exception $e) {
\Log::debug($e);
}

try {
$total_assets = Asset::RTD()->count();
$total_assets = Asset::all()->count();
if ($settings->show_archived_in_list != '1') {
$total_assets -= Asset::Archived()->count();
}
view()->share('total_assets', $total_assets);
} catch (\Exception $e) {
\Log::debug($e);
}

try {
$total_rtd_sidebar = Asset::RTD()->count();
view()->share('total_rtd_sidebar', $total_rtd_sidebar);
} catch (\Exception $e) {
\Log::debug($e);
}

try {
$total_deployed_sidebar = Asset::Deployed()->count();
view()->share('total_deployed_sidebar', $total_deployed_sidebar);
Expand Down Expand Up @@ -75,13 +86,6 @@ public function handle($request, Closure $next)
\Log::debug($e);
}

try {
$settings = Setting::getSettings();
view()->share('settings', $settings);
} catch (\Exception $e) {
\Log::debug($e);
}

try {
$total_due_for_audit = Asset::DueForAudit($settings)->count();
view()->share('total_due_for_audit', $total_due_for_audit);
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Transformers/UsersTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function transformUsers(Collection $users, $total)

public function transformUser(User $user)
{

$array = [
'id' => (int) $user->id,
'avatar' => e($user->present()->gravatar),
Expand Down Expand Up @@ -64,6 +65,8 @@ public function transformUser(User $user)
'licenses_count' => (int) $user->licenses_count,
'accessories_count' => (int) $user->accessories_count,
'consumables_count' => (int) $user->consumables_count,
'manages_users_count' => (int) $user->manages_users_count,
'manages_locations_count' => (int) $user->manages_locations_count,
'company' => ($user->company) ? ['id' => (int) $user->company->id, 'name'=> e($user->company->name)] : null,
'created_by' => ($user->createdBy) ? [
'id' => (int) $user->createdBy->id,
Expand Down
23 changes: 19 additions & 4 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@ public function isSuperUser()
public function isDeletable()
{
return Gate::allows('delete', $this)
&& ($this->assets()->count() === 0)
&& ($this->licenses()->count() === 0)
&& ($this->consumables()->count() === 0)
&& ($this->accessories()->count() === 0)
&& ($this->assets->count() === 0)
&& ($this->licenses->count() === 0)
&& ($this->consumables->count() === 0)
&& ($this->accessories->count() === 0)
&& ($this->managedLocations->count() === 0)
&& ($this->managesUsers->count() === 0)
&& ($this->deleted_at == '');
}

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

/**
* Establishes the user -> managed users relationship
*
* @author A. Gianotto <[email protected]>
* @since [v6.4.1]
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function managesUsers()
{
return $this->hasMany(\App\Models\User::class, 'manager_id');
}


/**
* Establishes the user -> managed locations relationship
*
Expand Down
26 changes: 22 additions & 4 deletions app/Presenters/UserPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static function dataTableLayout()
'switchable' => true,
'escape' => true,
'class' => 'css-barcode',
'title' => 'Assets',
'title' => trans('general.assets'),
'visible' => true,
],
[
Expand All @@ -230,7 +230,7 @@ public static function dataTableLayout()
'sortable' => true,
'switchable' => true,
'class' => 'css-license',
'title' => 'License',
'title' => trans('general.licenses'),
'visible' => true,
],
[
Expand All @@ -239,7 +239,7 @@ public static function dataTableLayout()
'sortable' => true,
'switchable' => true,
'class' => 'css-consumable',
'title' => 'Consumables',
'title' => trans('general.consumables'),
'visible' => true,
],
[
Expand All @@ -248,7 +248,25 @@ public static function dataTableLayout()
'sortable' => true,
'switchable' => true,
'class' => 'css-accessory',
'title' => 'Accessories',
'title' => trans('general.accessories'),
'visible' => true,
],
[
'field' => 'manages_users_count',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'class' => 'css-users',
'title' => trans('admin/users/table.managed_users'),
'visible' => true,
],
[
'field' => 'manages_locations_count',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'class' => 'css-location',
'title' => trans('admin/users/table.managed_locations'),
'visible' => true,
],
[
Expand Down
Loading

0 comments on commit c8fbf76

Please sign in to comment.