Fixed PHP error in UserHelper when having no user session
This commit is contained in:
@@ -107,6 +107,10 @@ class UserHelper extends Base
|
|||||||
*/
|
*/
|
||||||
public function hasAccess($controller, $action)
|
public function hasAccess($controller, $action)
|
||||||
{
|
{
|
||||||
|
if (! $this->userSession->isLogged()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$key = 'app_access:'.$controller.$action;
|
$key = 'app_access:'.$controller.$action;
|
||||||
$result = $this->memoryCache->get($key);
|
$result = $this->memoryCache->get($key);
|
||||||
|
|
||||||
@@ -128,6 +132,10 @@ class UserHelper extends Base
|
|||||||
*/
|
*/
|
||||||
public function hasProjectAccess($controller, $action, $project_id)
|
public function hasProjectAccess($controller, $action, $project_id)
|
||||||
{
|
{
|
||||||
|
if (! $this->userSession->isLogged()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->userSession->isAdmin()) {
|
if ($this->userSession->isAdmin()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ class UserHelperTest extends Base
|
|||||||
$this->assertEquals('Project Viewer', $helper->getRoleName(Role::PROJECT_VIEWER));
|
$this->assertEquals('Project Viewer', $helper->getRoleName(Role::PROJECT_VIEWER));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHasAccessWithoutSession()
|
||||||
|
{
|
||||||
|
$helper = new UserHelper($this->container);
|
||||||
|
$this->assertFalse($helper->hasAccess('UserCreationController', 'create'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testHasAccessForAdmins()
|
public function testHasAccessForAdmins()
|
||||||
{
|
{
|
||||||
$helper = new UserHelper($this->container);
|
$helper = new UserHelper($this->container);
|
||||||
@@ -73,6 +79,15 @@ class UserHelperTest extends Base
|
|||||||
$this->assertTrue($helper->hasAccess('ProjectCreationController', 'createPrivate'));
|
$this->assertTrue($helper->hasAccess('ProjectCreationController', 'createPrivate'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHasProjectAccessWithoutSession()
|
||||||
|
{
|
||||||
|
$helper = new UserHelper($this->container);
|
||||||
|
$project = new ProjectModel($this->container);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $project->create(array('name' => 'My project')));
|
||||||
|
$this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1));
|
||||||
|
}
|
||||||
|
|
||||||
public function testHasProjectAccessForAdmins()
|
public function testHasProjectAccessForAdmins()
|
||||||
{
|
{
|
||||||
$helper = new UserHelper($this->container);
|
$helper = new UserHelper($this->container);
|
||||||
|
|||||||
Reference in New Issue
Block a user