[ticket/354] Do not show portal link if user is not authed to see it
B3P-354
This commit is contained in:
@@ -82,6 +82,7 @@ services:
|
||||
board3.portal.listener:
|
||||
class: board3\portal\event\listener
|
||||
arguments:
|
||||
- @auth
|
||||
- @controller.helper
|
||||
- @path_helper
|
||||
- @template
|
||||
|
||||
@@ -13,6 +13,9 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class listener implements EventSubscriberInterface
|
||||
{
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbb\controller\helper */
|
||||
protected $controller_helper;
|
||||
|
||||
@@ -31,14 +34,16 @@ class listener implements EventSubscriberInterface
|
||||
/**
|
||||
* Constructor of Board3 Portal event listener
|
||||
*
|
||||
* @param \phpbb\auth\auth $auth phpBB auth object
|
||||
* @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\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\controller\helper $controller_helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\user $user, $php_ext)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->controller_helper = $controller_helper;
|
||||
$this->path_helper = $path_helper;
|
||||
$this->template = $template;
|
||||
@@ -92,12 +97,17 @@ class listener implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Add portal link
|
||||
* Add portal link if user is authed to see it
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function add_portal_link()
|
||||
{
|
||||
if (!$this->auth->acl_get('u_view_portal'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (strpos($this->user->data['session_page'], '/portal') === false)
|
||||
{
|
||||
$portal_link = $this->controller_helper->route('board3_portal_controller');
|
||||
|
||||
@@ -15,6 +15,7 @@ class listener_test extends \phpbb_template_template_test_case
|
||||
{
|
||||
/** @var \board3\portal\event\listener */
|
||||
protected $listener;
|
||||
protected $auth;
|
||||
|
||||
static public $hidden_fields = array();
|
||||
|
||||
@@ -32,6 +33,19 @@ class listener_test extends \phpbb_template_template_test_case
|
||||
|
||||
public function setup_listener()
|
||||
{
|
||||
global $cache, $db;
|
||||
|
||||
$cache = $this->getMock('\phpbb\cache\cache', array('obtain_word_list', 'get', 'sql_exists', 'put', 'obtain_attach_extensions'));
|
||||
$cache->expects($this->any())
|
||||
->method('obtain_word_list')
|
||||
->with()
|
||||
->will($this->returnValue(array()));
|
||||
$cache->expects($this->any())
|
||||
->method('get')
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(false));
|
||||
$db = $this->getMock('\phpbb\db\driver\driver_interface');
|
||||
|
||||
$this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
|
||||
$this->user->expects($this->any())
|
||||
->method('lang')
|
||||
@@ -61,7 +75,17 @@ class listener_test extends \phpbb_template_template_test_case
|
||||
$this->php_ext
|
||||
);
|
||||
|
||||
$this->auth = new \phpbb\auth\auth();
|
||||
$userdata = array(
|
||||
'user_id' => 2,
|
||||
);
|
||||
$this->auth->acl($userdata);
|
||||
// Pretend to allow downloads
|
||||
$this->auth->acl_options['global']['u_view_portal'] = 0;
|
||||
$this->auth->acl[0][0] = true;
|
||||
|
||||
$this->listener = new \board3\portal\event\listener(
|
||||
$this->auth,
|
||||
$this->controller_helper,
|
||||
$this->path_helper,
|
||||
$this->template,
|
||||
@@ -124,6 +148,13 @@ class listener_test extends \phpbb_template_template_test_case
|
||||
$result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars));
|
||||
|
||||
$this->assertEmpty($result);
|
||||
|
||||
// Make sure user shouldn't see link
|
||||
unset($this->auth->cache[0]['u_view_portal']);
|
||||
$this->auth->acl[0][0] = false;
|
||||
$result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars));
|
||||
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function test_load_portal_language()
|
||||
|
||||
Reference in New Issue
Block a user