[ticket/291] Add modules_helper and use for permission checks
B3P-291
This commit is contained in:
@@ -8,6 +8,7 @@ services:
|
||||
- @template
|
||||
- @dbal.conn
|
||||
- @pagination
|
||||
- @board3.portal.modules_helper
|
||||
- @request
|
||||
- %core.php_ext%
|
||||
- %core.root_path%
|
||||
@@ -179,6 +180,7 @@ services:
|
||||
- @config
|
||||
- @dbal.conn
|
||||
- @pagination
|
||||
- @board3.portal.modules_helper
|
||||
- @request
|
||||
- @template
|
||||
- %core.root_path%
|
||||
|
||||
@@ -49,5 +49,9 @@ services:
|
||||
board3.portal.helper:
|
||||
class: board3\portal\includes\helper
|
||||
arguments:
|
||||
- @auth
|
||||
- @board3.module_collection
|
||||
|
||||
board3.portal.modules_helper:
|
||||
class: board3\portal\includes\modules_helper
|
||||
arguments:
|
||||
- @auth
|
||||
|
||||
@@ -93,7 +93,7 @@ function obtain_portal_modules()
|
||||
// fetch post for news & announce
|
||||
function phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start = 0, $invert = false)
|
||||
{
|
||||
global $db, $phpbb_root_path, $auth, $user, $bbcode_bitfield, $bbcode, $portal_config, $config, $cache;
|
||||
global $db, $phpbb_root_path, $auth, $user, $bbcode_bitfield, $bbcode, $portal_config, $config, $cache, $phpbb_container;
|
||||
|
||||
$posts = $update_count = array();
|
||||
$post_time = ($time == 0) ? '' : 'AND t.topic_time > ' . (time() - $time * 86400);
|
||||
@@ -101,15 +101,10 @@ function phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_pos
|
||||
$str_where = '';
|
||||
$topic_icons = array(0);
|
||||
$have_icons = 0;
|
||||
$modules_helper = $phpbb_container->get('board3.portal.modules_helper');
|
||||
|
||||
if ($permissions == true)
|
||||
{
|
||||
$disallow_access = array_unique(array_keys($auth->acl_getf('!f_read', true)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$disallow_access = array();
|
||||
}
|
||||
// Get disallowed forums
|
||||
$disallow_access = $modules_helper->get_disallowed_forums($permissions);
|
||||
|
||||
if ($invert == true)
|
||||
{
|
||||
|
||||
@@ -11,12 +11,6 @@ namespace board3\portal\includes;
|
||||
|
||||
class helper
|
||||
{
|
||||
/**
|
||||
* Auth object
|
||||
* @var \phpbb\auth\auth
|
||||
*/
|
||||
private $auth;
|
||||
|
||||
/**
|
||||
* Board3 Modules service collection
|
||||
* @var \phpbb\di\service_collection
|
||||
@@ -27,13 +21,11 @@ class helper
|
||||
* Constructor
|
||||
* NOTE: The parameters of this method must match in order and type with
|
||||
* the dependencies defined in the services.yml file for this service.
|
||||
* @param \phpbb\auth\auth $auth Auth object
|
||||
* @param \phpbb\di\service_collection $modules Board3 Modules service
|
||||
* collection
|
||||
*/
|
||||
public function __construct($auth, $modules)
|
||||
public function __construct($modules)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->register_modules($modules);
|
||||
}
|
||||
|
||||
@@ -72,24 +64,4 @@ class helper
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of disallowed forums
|
||||
*
|
||||
* @param bool $disallow_access Whether the array for disallowing access
|
||||
* should be filled
|
||||
*/
|
||||
public function get_disallowed_forums($disallow_access)
|
||||
{
|
||||
if ($disallow_access == true)
|
||||
{
|
||||
$disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$disallow_access = array();
|
||||
}
|
||||
|
||||
return $disallow_access;
|
||||
}
|
||||
}
|
||||
|
||||
50
includes/modules_helper.php
Normal file
50
includes/modules_helper.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package Board3 Portal v2.1
|
||||
* @copyright (c) 2014 Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace board3\portal\includes;
|
||||
|
||||
class modules_helper
|
||||
{
|
||||
/**
|
||||
* Auth object
|
||||
* @var \phpbb\auth\auth
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* NOTE: The parameters of this method must match in order and type with
|
||||
* the dependencies defined in the services.yml file for this service.
|
||||
* @param \phpbb\auth\auth $auth Auth object
|
||||
*/
|
||||
public function __construct($auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of disallowed forums
|
||||
*
|
||||
* @param bool $disallow_access Whether the array for disallowing access
|
||||
* should be filled
|
||||
*/
|
||||
public function get_disallowed_forums($disallow_access)
|
||||
{
|
||||
if ($disallow_access == true)
|
||||
{
|
||||
$disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$disallow_access = array();
|
||||
}
|
||||
|
||||
return $disallow_access;
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,9 @@ class announcements extends module_base
|
||||
/** @var \phpbb\pagination */
|
||||
protected $pagination;
|
||||
|
||||
/** @var \board3\portal\includes\modules_helper */
|
||||
protected $modules_helper;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
protected $request;
|
||||
|
||||
@@ -80,12 +83,13 @@ class announcements extends module_base
|
||||
* @param \phpbb\template $template phpBB template
|
||||
* @param \phpbb\db\driver $db Database driver
|
||||
* @param \phpbb\pagination $pagination phpBB pagination
|
||||
* @param \board3\portal\includes\modules_helper $modules_helper Portal modules helper
|
||||
* @param \phpbb\request\request $request phpBB request
|
||||
* @param string $phpEx php file extension
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param \phpbb\user $user phpBB user object
|
||||
*/
|
||||
public function __construct($auth, $cache, $config, $template, $db, $pagination, $request, $phpEx, $phpbb_root_path, $user)
|
||||
public function __construct($auth, $cache, $config, $template, $db, $pagination, $modules_helper, $request, $phpEx, $phpbb_root_path, $user)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
@@ -93,6 +97,7 @@ class announcements extends module_base
|
||||
$this->template = $template;
|
||||
$this->db = $db;
|
||||
$this->pagination = $pagination;
|
||||
$this->modules_helper = $modules_helper;
|
||||
$this->request = $request;
|
||||
$this->php_ext = $phpEx;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
@@ -137,14 +142,8 @@ class announcements extends module_base
|
||||
|
||||
$str_where = '';
|
||||
|
||||
if($permissions == true)
|
||||
{
|
||||
$disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$disallow_access = array();
|
||||
}
|
||||
// Get disallowed forums
|
||||
$disallow_access = $this->modules_helper->get_disallowed_forums($permissions);
|
||||
|
||||
if($this->config['board3_announcements_forum_exclude_' . $module_id] == true)
|
||||
{
|
||||
|
||||
@@ -56,6 +56,9 @@ class news extends module_base
|
||||
/** @var \phpbb\pagination */
|
||||
protected $pagination;
|
||||
|
||||
/** @var \board3\portal\includes\modules_helper */
|
||||
protected $modules_helper;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
protected $request;
|
||||
|
||||
@@ -79,19 +82,21 @@ class news extends module_base
|
||||
* @param \phpbb\config\config $config phpBB config
|
||||
* @param \phpbb\db\driver $db phpBB db driver
|
||||
* @param \phpbb\pagination $pagination phpBB pagination
|
||||
* @param \board3\portal\includes\modules_helper $modules_helper Portal modules helper
|
||||
* @param \phpbb\request\request $request phpBB request
|
||||
* @param \phpbb\template $template phpBB template
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param string $phpEx php file extension
|
||||
* @param \phpbb\user $user phpBB user object
|
||||
*/
|
||||
public function __construct($auth, $cache, $config, $db, $pagination, $request, $template, $phpbb_root_path, $phpEx, $user)
|
||||
public function __construct($auth, $cache, $config, $db, $pagination, $modules_helper, $request, $template, $phpbb_root_path, $phpEx, $user)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->pagination = $pagination;
|
||||
$this->modules_helper = $modules_helper;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
@@ -134,14 +139,8 @@ class news extends module_base
|
||||
|
||||
$str_where = '';
|
||||
|
||||
if($permissions == true)
|
||||
{
|
||||
$disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$disallow_access = array();
|
||||
}
|
||||
// Get disallowed forums
|
||||
$disallow_access = $this->modules_helper->get_disallowed_forums($permissions);
|
||||
|
||||
if($this->config['board3_news_exclude_' . $module_id] == true)
|
||||
{
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class board3_includes_helper_database_test extends \board3\portal\tests\testframework\database_test_case
|
||||
{
|
||||
protected $portal_helper;
|
||||
|
||||
protected $modules;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/auth.xml');
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$config = new \phpbb\config\config(array());
|
||||
$this->modules = array(
|
||||
'\board3\portal\modules\link_us' => new \board3\portal\modules\link_us($config, new \board3\portal\tests\mock\template($this), new \board3\portal\tests\mock\user),
|
||||
);
|
||||
$auth = new \phpbb\auth\auth();
|
||||
|
||||
$this->portal_helper = $this->get_portal_helper($auth, $this->modules);
|
||||
}
|
||||
|
||||
protected function get_portal_helper($auth, $modules)
|
||||
{
|
||||
$this->portal_helper = new \board3\portal\includes\helper($auth, $modules);
|
||||
|
||||
return $this->portal_helper;
|
||||
}
|
||||
|
||||
public function data_get_disallowed_forums()
|
||||
{
|
||||
return array(
|
||||
array(array(), false),
|
||||
array(array(0 => 1, 1 => 2), true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_get_disallowed_forums
|
||||
*/
|
||||
public function test_get_disallowed_forums($expected, $input)
|
||||
{
|
||||
$this->assertEquals($expected, $this->portal_helper->get_disallowed_forums($input));
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class board3_includes_helper_test extends \board3\portal\tests\testframework\tes
|
||||
|
||||
protected function get_portal_helper($modules)
|
||||
{
|
||||
$this->portal_helper = new \board3\portal\includes\helper(array(), $modules);
|
||||
$this->portal_helper = new \board3\portal\includes\helper($modules);
|
||||
|
||||
return $this->portal_helper;
|
||||
}
|
||||
|
||||
46
tests/unit/includes/modules_helper_test.php
Normal file
46
tests/unit/includes/modules_helper_test.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class board3_includes_modules_helper_test extends \board3\portal\tests\testframework\database_test_case
|
||||
{
|
||||
protected $modules_helper;
|
||||
|
||||
protected $modules;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/auth.xml');
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$auth = new \phpbb\auth\auth();
|
||||
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth);
|
||||
}
|
||||
|
||||
public function data_get_disallowed_forums()
|
||||
{
|
||||
return array(
|
||||
array(array(), false),
|
||||
array(array(0 => 1, 1 => 2), true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_get_disallowed_forums
|
||||
*/
|
||||
public function test_get_disallowed_forums($expected, $input)
|
||||
{
|
||||
$this->assertEquals($expected, $this->modules_helper->get_disallowed_forums($input));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user