Merge pull request #380 from marc1706/ticket/378
[ticket/378] Hide portal link if it's disabled
This commit is contained in:
@@ -82,6 +82,7 @@ services:
|
||||
class: board3\portal\event\listener
|
||||
arguments:
|
||||
- @auth
|
||||
- @config
|
||||
- @controller.helper
|
||||
- @path_helper
|
||||
- @template
|
||||
|
||||
@@ -16,6 +16,9 @@ class listener implements EventSubscriberInterface
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\controller\helper */
|
||||
protected $controller_helper;
|
||||
|
||||
@@ -35,15 +38,17 @@ class listener implements EventSubscriberInterface
|
||||
* Constructor of Board3 Portal event listener
|
||||
*
|
||||
* @param \phpbb\auth\auth $auth phpBB auth object
|
||||
* @param \phpbb\config\config $config phpBB config
|
||||
* @param \phpbb\controller\helper $controller_helper Controller helper object
|
||||
* @param \phpbb\path_helper $path_helper phpBB path helper
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
* @param string $php_ext phpEx
|
||||
*/
|
||||
public function __construct(\phpbb\auth\auth $auth, \phpbb\controller\helper $controller_helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\user $user, $php_ext)
|
||||
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\controller\helper $controller_helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\user $user, $php_ext)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->config = $config;
|
||||
$this->controller_helper = $controller_helper;
|
||||
$this->path_helper = $path_helper;
|
||||
$this->template = $template;
|
||||
@@ -103,7 +108,7 @@ class listener implements EventSubscriberInterface
|
||||
*/
|
||||
public function add_portal_link()
|
||||
{
|
||||
if (!$this->auth->acl_get('u_view_portal'))
|
||||
if (!$this->has_portal_access())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -121,4 +126,14 @@ class listener implements EventSubscriberInterface
|
||||
'U_PORTAL' => $portal_link,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user should be able to access portal
|
||||
*
|
||||
* @return bool True of user should be able to access it, false if not
|
||||
*/
|
||||
protected function has_portal_access()
|
||||
{
|
||||
return $this->auth->acl_get('u_view_portal') && $this->config['board3_enable'];
|
||||
}
|
||||
}
|
||||
|
||||
70
tests/functional/portal_link_test.php
Normal file
70
tests/functional/portal_link_test.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 Board3 Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_portal_link_test extends \board3\portal\tests\testframework\functional_test_case
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
}
|
||||
|
||||
public function test_portal_link()
|
||||
{
|
||||
$crawler = self::request('GET', 'index.php?sid=' . $this->sid);
|
||||
$this->assertContains('Portal', $crawler->text());
|
||||
}
|
||||
|
||||
public function test_disabled_portal_link()
|
||||
{
|
||||
// Disable portal
|
||||
$crawler = self::request('GET', 'adm/index.php?i=-board3-portal-acp-portal_module&mode=config&sid=' . $this->sid);
|
||||
$form = $crawler->selectButton('Submit')->form();
|
||||
$form->setValues(array(
|
||||
'config[board3_enable]' => 0,
|
||||
));
|
||||
$crawler = self::submit($form);
|
||||
|
||||
// Should be updated
|
||||
$this->assertContainsLang('CONFIG_UPDATED', $crawler->text());
|
||||
|
||||
// Look for portal link on index
|
||||
$crawler = self::request('GET', 'index.php?sid=' . $this->sid);
|
||||
$vals = $crawler->filter('#nav-breadcrumbs')->each(function (\Symfony\Component\DomCrawler\Crawler $node, $i) {
|
||||
return $node->text();
|
||||
});
|
||||
foreach ($vals as $val)
|
||||
{
|
||||
$this->assertNotContains('Portal', $val);
|
||||
}
|
||||
|
||||
// Try to access portal directly
|
||||
$crawler = self::request('GET', 'app.php/portal?sid=' . $this->sid);
|
||||
$vals = $crawler->filter('#nav-breadcrumbs')->each(function (\Symfony\Component\DomCrawler\Crawler $node, $i) {
|
||||
return $node->text();
|
||||
});
|
||||
foreach ($vals as $val)
|
||||
{
|
||||
$this->assertNotContains('Portal', $val);
|
||||
}
|
||||
|
||||
// Enable portal again
|
||||
$crawler = self::request('GET', 'adm/index.php?i=-board3-portal-acp-portal_module&mode=config&sid=' . $this->sid);
|
||||
$form = $crawler->selectButton('Submit')->form();
|
||||
$form->setValues(array(
|
||||
'config[board3_enable]' => 1,
|
||||
));
|
||||
self::submit($form);
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,10 @@ class listener_test extends \phpbb_template_template_test_case
|
||||
$request->overwrite('SCRIPT_FILENAME', 'app.php', \phpbb\request\request_interface::SERVER);
|
||||
$request->overwrite('REQUEST_URI', 'app.php', \phpbb\request\request_interface::SERVER);
|
||||
|
||||
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
|
||||
$this->config = new \phpbb\config\config(array(
|
||||
'enable_mod_rewrite' => '1',
|
||||
'board3_portal_enable' => '1',
|
||||
));
|
||||
$provider = new \phpbb\controller\provider();
|
||||
$provider->find_routing_files($finder);
|
||||
$provider->find(dirname(__FILE__) . '/');
|
||||
@@ -90,6 +93,7 @@ class listener_test extends \phpbb_template_template_test_case
|
||||
|
||||
$this->listener = new \board3\portal\event\listener(
|
||||
$this->auth,
|
||||
$this->config,
|
||||
$this->controller_helper,
|
||||
$this->path_helper,
|
||||
$this->template,
|
||||
|
||||
Reference in New Issue
Block a user