Fix permissions bug in IRC (#12266)

* Fix permissions bug in IRC
Rename Permissions class to remove confusion with the Facade

* Fix style
This commit is contained in:
Tony Murray
2020-10-28 16:07:03 -05:00
committed by GitHub
parent 1bc868e781
commit 4746c3f9d0
3 changed files with 15 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
<?php
/**
* Permissions.php
/*
* PermissionsCache.php
*
* Class to check the direct permissions on devices, ports, and bills for normal users (not global read only and admin)
*
@@ -18,11 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://librenms.org
* @copyright 2019 Tony Murray
* @copyright 2019-2020 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
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;

View File

@@ -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();

View File

@@ -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],