From 5a91942bb5afdd510626897ef87c452e1fccee3b Mon Sep 17 00:00:00 2001 From: Mosen Date: Wed, 3 Jan 2024 10:27:08 +1100 Subject: [PATCH] Minor change to MachineGroupMembership.php which uses BU config enabled/disabled instead of session var to determine whether to check for machine group business units --- app/Auth/Listeners/MachineGroupMembership.php | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/Auth/Listeners/MachineGroupMembership.php b/app/Auth/Listeners/MachineGroupMembership.php index aaaf31729..a58c5353e 100644 --- a/app/Auth/Listeners/MachineGroupMembership.php +++ b/app/Auth/Listeners/MachineGroupMembership.php @@ -18,17 +18,9 @@ class MachineGroupMembership { public function handle(Login $event) { - Log::info('evaluating machinegroup memberships'); - if( session()->has('business_unit')){ - // Only retrieve machinegroups for this business unit - $businessUnitId = session()->get('business_unit'); - $machineGroups = BusinessUnit::where('unitid', $businessUnitId) - ->where('property', 'machine_group') - ->get() - ->pluck('value') - ->toArray(); - } - else{ + Log::debug('evaluating machinegroup memberships'); + + if (!config('_munkireport.enable_business_units', false) || $event->user->role === 'admin') { // Can access all defined groups (from machine_group) // and used groups (from reportdata) $mg = new Machine_group; @@ -39,8 +31,17 @@ public function handle(Login $event) { ->toArray(); $reportedMachineGroups = $reportedMachineGroups ? $reportedMachineGroups : [0]; $machineGroups = array_unique(array_merge($reportedMachineGroups, $mg->get_group_ids())); + } else { + // Only retrieve machinegroups for this business unit + $businessUnitId = session()->get('business_unit'); + $machineGroups = BusinessUnit::where('unitid', $businessUnitId) + ->where('property', 'machine_group') + ->get() + ->pluck('value') + ->toArray(); } - Log::info('found machinegroup memberships: ', $machineGroups); + + Log::debug('found machinegroup memberships: ', $machineGroups); session()->put('machine_groups', $machineGroups); } }