diff --git a/LibreNMS/Permissions.php b/LibreNMS/Cache/PermissionsCache.php similarity index 98% rename from LibreNMS/Permissions.php rename to LibreNMS/Cache/PermissionsCache.php index 54817d5f2d..fc97299aed 100644 --- a/LibreNMS/Permissions.php +++ b/LibreNMS/Cache/PermissionsCache.php @@ -1,6 +1,6 @@ . * * @link http://librenms.org - * @copyright 2019 Tony Murray + * @copyright 2019-2020 Tony Murray * @author Tony Murray */ -namespace LibreNMS; +namespace LibreNMS\Cache; use App\Models\Bill; use App\Models\Device; @@ -31,7 +31,7 @@ use App\Models\User; use Auth; use DB; -class Permissions +class PermissionsCache { private $devicePermissions; private $portPermissions; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6642327054..c4a6115535 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -7,8 +7,8 @@ use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Log; use Illuminate\Support\ServiceProvider; +use LibreNMS\Cache\PermissionsCache; use LibreNMS\Config; -use LibreNMS\Permissions; use LibreNMS\Util\IP; use LibreNMS\Util\Validate; use Validator; @@ -26,7 +26,7 @@ class AppServiceProvider extends ServiceProvider $this->registerGeocoder(); $this->app->singleton('permissions', function ($app) { - return new Permissions(); + return new PermissionsCache(); }); $this->app->singleton('device-cache', function ($app) { return new \LibreNMS\Cache\Device(); diff --git a/tests/Unit/PermissionsTest.php b/tests/Unit/PermissionsTest.php index ec99b7cc2c..4ea84a8779 100644 --- a/tests/Unit/PermissionsTest.php +++ b/tests/Unit/PermissionsTest.php @@ -58,7 +58,7 @@ class PermissionsTest extends TestCase public function testUserCanAccessDevice() { - $perms = \Mockery::mock(\LibreNMS\Permissions::class)->makePartial(); + $perms = \Mockery::mock(\LibreNMS\Cache\PermissionsCache::class)->makePartial(); $perms->shouldReceive('getDevicePermissions')->andReturnUsing(function ($user) { return self::devicePermissionData($user); }); @@ -82,7 +82,7 @@ class PermissionsTest extends TestCase public function testDevicesForUser() { - $perms = \Mockery::mock(\LibreNMS\Permissions::class)->makePartial(); + $perms = \Mockery::mock(\LibreNMS\Cache\PermissionsCache::class)->makePartial(); $perms->shouldReceive('getDevicePermissions')->andReturnUsing(function ($user) { return self::devicePermissionData($user); }); @@ -115,7 +115,7 @@ class PermissionsTest extends TestCase */ public function testUserCanAccessPort() { - $perms = \Mockery::mock(\LibreNMS\Permissions::class)->makePartial(); + $perms = \Mockery::mock(\LibreNMS\Cache\PermissionsCache::class)->makePartial(); $perms->shouldReceive('getPortPermissions')->andReturn(collect([ (object) ['user_id' => 43, 'port_id' => 54], (object) ['user_id' => 43, 'port_id' => 32], @@ -141,7 +141,7 @@ class PermissionsTest extends TestCase public function testPortsForUser() { - $perms = \Mockery::mock(\LibreNMS\Permissions::class)->makePartial(); + $perms = \Mockery::mock(\LibreNMS\Cache\PermissionsCache::class)->makePartial(); $perms->shouldReceive('getPortPermissions')->andReturn(collect([ (object) ['user_id' => 3, 'port_id' => 7], (object) ['user_id' => 3, 'port_id' => 2], @@ -159,7 +159,7 @@ class PermissionsTest extends TestCase public function testUsersForPort() { - $perms = \Mockery::mock(\LibreNMS\Permissions::class)->makePartial(); + $perms = \Mockery::mock(\LibreNMS\Cache\PermissionsCache::class)->makePartial(); $perms->shouldReceive('getPortPermissions')->andReturn(collect([ (object) ['user_id' => 3, 'port_id' => 7], (object) ['user_id' => 3, 'port_id' => 2], @@ -175,7 +175,7 @@ class PermissionsTest extends TestCase public function testUserCanAccessBill() { - $perms = \Mockery::mock(\LibreNMS\Permissions::class)->makePartial(); + $perms = \Mockery::mock(\LibreNMS\Cache\PermissionsCache::class)->makePartial(); $perms->shouldReceive('getBillPermissions')->andReturn(collect([ (object) ['user_id' => 43, 'bill_id' => 54], (object) ['user_id' => 43, 'bill_id' => 32], @@ -201,7 +201,7 @@ class PermissionsTest extends TestCase public function testBillsForUser() { - $perms = \Mockery::mock(\LibreNMS\Permissions::class)->makePartial(); + $perms = \Mockery::mock(\LibreNMS\Cache\PermissionsCache::class)->makePartial(); $perms->shouldReceive('getBillPermissions')->andReturn(collect([ (object) ['user_id' => 3, 'bill_id' => 7], (object) ['user_id' => 3, 'bill_id' => 2], @@ -219,7 +219,7 @@ class PermissionsTest extends TestCase public function testUsersForBill() { - $perms = \Mockery::mock(\LibreNMS\Permissions::class)->makePartial(); + $perms = \Mockery::mock(\LibreNMS\Cache\PermissionsCache::class)->makePartial(); $perms->shouldReceive('getBillPermissions')->andReturn(collect([ (object) ['user_id' => 3, 'bill_id' => 7], (object) ['user_id' => 3, 'bill_id' => 2],