Fix bug with permissions including more than one dash, closes #727

This commit is contained in:
Dane Everitt 2017-11-05 13:42:57 -06:00
parent 30ab6ed692
commit 2f42396317
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 8 additions and 6 deletions

View file

@ -86,7 +86,7 @@ class KeyCreationService
$nodes = $this->permissionService->getPermissions(); $nodes = $this->permissionService->getPermissions();
foreach ($permissions as $permission) { foreach ($permissions as $permission) {
@list($block, $search) = explode('-', $permission); @list($block, $search) = explode('-', $permission, 2);
if ( if (
(empty($block) || empty($search)) || (empty($block) || empty($search)) ||
@ -100,7 +100,7 @@ class KeyCreationService
} }
foreach ($administrative as $permission) { foreach ($administrative as $permission) {
@list($block, $search) = explode('-', $permission); @list($block, $search) = explode('-', $permission, 2);
if ( if (
(empty($block) || empty($search)) || (empty($block) || empty($search)) ||

View file

@ -82,19 +82,21 @@ class KeyCreationServiceTest extends TestCase
], true, true)->once()->andReturn((object) ['id' => 1]); ], true, true)->once()->andReturn((object) ['id' => 1]);
$this->permissions->shouldReceive('getPermissions')->withNoArgs()->once()->andReturn([ $this->permissions->shouldReceive('getPermissions')->withNoArgs()->once()->andReturn([
'_user' => ['server' => ['list']], '_user' => ['server' => ['list', 'multiple-dash-test']],
'server' => ['create'], 'server' => ['create', 'admin-dash-test'],
]); ]);
$this->permissions->shouldReceive('create')->with(1, 'user.server-list')->once()->andReturnNull(); $this->permissions->shouldReceive('create')->with(1, 'user.server-list')->once()->andReturnNull();
$this->permissions->shouldReceive('create')->with(1, 'user.server-multiple-dash-test')->once()->andReturnNull();
$this->permissions->shouldReceive('create')->with(1, 'server-create')->once()->andReturnNull(); $this->permissions->shouldReceive('create')->with(1, 'server-create')->once()->andReturnNull();
$this->permissions->shouldReceive('create')->with(1, 'server-admin-dash-test')->once()->andReturnNull();
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull(); $this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
$response = $this->service->handle( $response = $this->service->handle(
['test-data' => 'test'], ['test-data' => 'test'],
['invalid-node', 'server-list'], ['invalid-node', 'server-list', 'server-multiple-dash-test'],
['invalid-node', 'server-create'] ['invalid-node', 'server-create', 'server-admin-dash-test']
); );
$this->assertNotEmpty($response); $this->assertNotEmpty($response);