Remove more _SESSION calls in classes, test updates
Admin\EditBase now has ACL\Login class as mandatory class parameter Output\Form\Generate has loginAcl array parameter as mandatory
This commit is contained in:
@@ -7,6 +7,14 @@ namespace tests;
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Not yet covered tests:
|
||||||
|
- loginGetLocale
|
||||||
|
- loginGetHeaderColor
|
||||||
|
- loginGetPages
|
||||||
|
- loginGetEuid
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for ACL\Login
|
* Test class for ACL\Login
|
||||||
* @coversDefaultClass \CoreLibs\ACL\Login
|
* @coversDefaultClass \CoreLibs\ACL\Login
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ $form = new CoreLibs\Output\Form\Generate(
|
|||||||
DB_CONFIG,
|
DB_CONFIG,
|
||||||
$log,
|
$log,
|
||||||
$l10n,
|
$l10n,
|
||||||
|
[
|
||||||
|
'base' => 10,
|
||||||
|
'admin' => 0
|
||||||
|
],
|
||||||
table_arrays: $table_arrays
|
table_arrays: $table_arrays
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ $edit_base = new CoreLibs\Admin\EditBase(
|
|||||||
DB_CONFIG,
|
DB_CONFIG,
|
||||||
$log,
|
$log,
|
||||||
$l10n,
|
$l10n,
|
||||||
|
$login,
|
||||||
[
|
[
|
||||||
'default_acl_level' => DEFAULT_ACL_LEVEL,
|
|
||||||
'cache_id' => CACHE_ID,
|
'cache_id' => CACHE_ID,
|
||||||
'compile_id' => COMPILE_ID
|
'compile_id' => COMPILE_ID
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function pop(theURL, winName, features) {
|
|||||||
<form method="post">
|
<form method="post">
|
||||||
<tr>
|
<tr>
|
||||||
<td bgcolor="{$HEADER_COLOR}" class="normal">
|
<td bgcolor="{$HEADER_COLOR}" class="normal">
|
||||||
Hello <b>{$USER_NAME|upper}</b> [{$EUID}] from the group <b>{$GROUP_NAME}</b> with Access Level <b>{$GROUP_LEVEL}</b>
|
Hello <b>{$USER_NAME|upper}</b> [{$EUID}] from the group <b>{$GROUP_NAME}</b> with Access Level <b>{$ACCESS_LEVEL}</b>
|
||||||
</td>
|
</td>
|
||||||
<td bgcolor="{$HEADER_COLOR}" class="normal" align="right">
|
<td bgcolor="{$HEADER_COLOR}" class="normal" align="right">
|
||||||
<input type="submit" name="login_logout" value="Logout">
|
<input type="submit" name="login_logout" value="Logout">
|
||||||
|
|||||||
@@ -2464,6 +2464,37 @@ EOM;
|
|||||||
{
|
{
|
||||||
return $this->locale;
|
return $this->locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return header color or null for not set
|
||||||
|
*
|
||||||
|
* @return string|null Header color in RGB hex with leading sharp
|
||||||
|
*/
|
||||||
|
public function loginGetHeaderColor(): ?string
|
||||||
|
{
|
||||||
|
return $_SESSION['HEADER_COLOR'] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current loaded list of pages the user can access
|
||||||
|
*
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function loginGetPages(): array
|
||||||
|
{
|
||||||
|
|
||||||
|
return $_SESSION['PAGES'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current set EUID (edit user id)
|
||||||
|
*
|
||||||
|
* @return string EUID as string
|
||||||
|
*/
|
||||||
|
public function loginGetEuid(): string
|
||||||
|
{
|
||||||
|
return $this->euid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ class EditBase
|
|||||||
private $form;
|
private $form;
|
||||||
/** @var \CoreLibs\Debug\Logging */
|
/** @var \CoreLibs\Debug\Logging */
|
||||||
public $log;
|
public $log;
|
||||||
|
/** @var \CoreLibs\ACL\Login */
|
||||||
|
public $login;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* construct form generator
|
* construct form generator
|
||||||
@@ -42,15 +44,18 @@ class EditBase
|
|||||||
* @param array<mixed> $db_config db config array, mandatory
|
* @param array<mixed> $db_config db config array, mandatory
|
||||||
* @param \CoreLibs\Debug\Logging $log Logging class, null auto set
|
* @param \CoreLibs\Debug\Logging $log Logging class, null auto set
|
||||||
* @param \CoreLibs\Language\L10n $l10n l10n language class, null auto set
|
* @param \CoreLibs\Language\L10n $l10n l10n language class, null auto set
|
||||||
|
* @param \CoreLibs\ACL\Login $login login class for ACL settings
|
||||||
* @param array<string,mixed> $options Various settings options
|
* @param array<string,mixed> $options Various settings options
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
array $db_config,
|
array $db_config,
|
||||||
\CoreLibs\Debug\Logging $log,
|
\CoreLibs\Debug\Logging $log,
|
||||||
\CoreLibs\Language\L10n $l10n,
|
\CoreLibs\Language\L10n $l10n,
|
||||||
|
\CoreLibs\ACL\Login $login,
|
||||||
array $options
|
array $options
|
||||||
) {
|
) {
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
|
$this->login = $login;
|
||||||
// smarty template engine (extended Translation version)
|
// smarty template engine (extended Translation version)
|
||||||
$this->smarty = new \CoreLibs\Template\SmartyExtend(
|
$this->smarty = new \CoreLibs\Template\SmartyExtend(
|
||||||
$l10n,
|
$l10n,
|
||||||
@@ -64,7 +69,8 @@ class EditBase
|
|||||||
$this->form = new \CoreLibs\Output\Form\Generate(
|
$this->form = new \CoreLibs\Output\Form\Generate(
|
||||||
$db_config,
|
$db_config,
|
||||||
$log,
|
$log,
|
||||||
$l10n
|
$l10n,
|
||||||
|
$this->login->loginGetAcl()
|
||||||
);
|
);
|
||||||
if ($this->form->mobile_phone) {
|
if ($this->form->mobile_phone) {
|
||||||
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
||||||
@@ -274,23 +280,16 @@ class EditBase
|
|||||||
|
|
||||||
// MENU START
|
// MENU START
|
||||||
// request some session vars
|
// request some session vars
|
||||||
if (empty($_SESSION['HEADER_COLOR'])) {
|
$this->DATA['HEADER_COLOR'] = $this->login->loginGetHeaderColor() ?? '#E0E2FF';
|
||||||
$this->DATA['HEADER_COLOR'] = '#E0E2FF';
|
$this->DATA['USER_NAME'] = $this->login->loginGetAcl()['user_name'] ?? '';
|
||||||
} else {
|
$this->DATA['EUID'] = $this->login->loginGetEuid();
|
||||||
$this->DATA['HEADER_COLOR'] = $_SESSION['HEADER_COLOR'];
|
$this->DATA['GROUP_NAME'] = $this->login->loginGetAcl()['group_name'] ?? '';
|
||||||
}
|
$this->DATA['ACCESS_LEVEL'] = $this->login->loginGetAcl()['base'] ?? '';
|
||||||
$this->DATA['USER_NAME'] = $_SESSION['USER_NAME'];
|
// below is old and to removed when edit_body.tpl is updates
|
||||||
$this->DATA['EUID'] = $_SESSION['EUID'];
|
$this->DATA['GROUP_LEVEL'] = $this->DATA['ACCESS_LEVEL'];
|
||||||
$this->DATA['GROUP_NAME'] = $_SESSION['GROUP_NAME'];
|
$PAGES = $this->login->loginGetPages();
|
||||||
$this->DATA['GROUP_LEVEL'] = $_SESSION['GROUP_ACL_LEVEL'];
|
|
||||||
$PAGES = $_SESSION['PAGES'];
|
|
||||||
|
|
||||||
//$this->form->log->debug('menu', $this->form->log->prAr($PAGES));
|
//$this->form->log->debug('menu', $this->form->log->prAr($PAGES));
|
||||||
|
|
||||||
// build nav from $PAGES ...
|
|
||||||
if (!isset($PAGES) || !is_array($PAGES)) {
|
|
||||||
$PAGES = [];
|
|
||||||
}
|
|
||||||
$menuarray = [];
|
$menuarray = [];
|
||||||
foreach ($PAGES as $PAGE_CUID => $PAGE_DATA) {
|
foreach ($PAGES as $PAGE_CUID => $PAGE_DATA) {
|
||||||
if ($PAGE_DATA['menu'] && $PAGE_DATA['online']) {
|
if ($PAGE_DATA['menu'] && $PAGE_DATA['online']) {
|
||||||
|
|||||||
@@ -405,9 +405,9 @@ class IO
|
|||||||
$db_debug_override ??
|
$db_debug_override ??
|
||||||
// from db config setting
|
// from db config setting
|
||||||
$db_config['db_debug'] ??
|
$db_config['db_debug'] ??
|
||||||
// should be handled from outside
|
// [DEPRECATED] should be handled from outside
|
||||||
$_SESSION['DB_DEBUG'] ??
|
$_SESSION['DB_DEBUG'] ??
|
||||||
// globals should be deprecated
|
// [DEPRECATED] globals should be deprecated
|
||||||
$GLOBALS['DB_DEBUG'] ??
|
$GLOBALS['DB_DEBUG'] ??
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -251,22 +251,22 @@ class Logging
|
|||||||
'debug',
|
'debug',
|
||||||
$this->options['debug_all'] ??
|
$this->options['debug_all'] ??
|
||||||
// for user login, should be handled outside like globals
|
// for user login, should be handled outside like globals
|
||||||
$_SESSION['DEBUG_ALL'] ??
|
$_SESSION['DEBUG_ALL'] ?? // DEPRECATED
|
||||||
$GLOBALS['DEBUG_ALL'] ??
|
$GLOBALS['DEBUG_ALL'] ?? // DEPRECATED
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
$this->setLogLevelAll(
|
$this->setLogLevelAll(
|
||||||
'print',
|
'print',
|
||||||
$this->options['print_all'] ??
|
$this->options['print_all'] ??
|
||||||
// for user login, should be handled outside like globals
|
// for user login, should be handled outside like globals
|
||||||
$_SESSION['DEBUG_ALL'] ??
|
$_SESSION['DEBUG_ALL'] ?? // DEPRECATED
|
||||||
$GLOBALS['PRINT_ALL'] ??
|
$GLOBALS['PRINT_ALL'] ?? // DEPRECATED
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
$this->setLogLevelAll(
|
$this->setLogLevelAll(
|
||||||
'echo',
|
'echo',
|
||||||
$this->options['echo_all'] ??
|
$this->options['echo_all'] ??
|
||||||
$GLOBALS['ECHO_ALL'] ??
|
$GLOBALS['ECHO_ALL'] ?? // DEPRECATED
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -274,32 +274,32 @@ class Logging
|
|||||||
// add file date is default on
|
// add file date is default on
|
||||||
$this->setGetLogPrintFileDate(
|
$this->setGetLogPrintFileDate(
|
||||||
$this->options['print_file_date'] ??
|
$this->options['print_file_date'] ??
|
||||||
$GLOBALS['LOG_PRINT_FILE_DATE'] ??
|
$GLOBALS['LOG_PRINT_FILE_DATE'] ?? // DEPRECATED
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
// all other logging file name flags are off
|
// all other logging file name flags are off
|
||||||
$this->setLogPer(
|
$this->setLogPer(
|
||||||
'level',
|
'level',
|
||||||
$this->options['per_level'] ??
|
$this->options['per_level'] ??
|
||||||
$GLOBALS['LOG_PER_LEVEL'] ??
|
$GLOBALS['LOG_PER_LEVEL'] ?? // DEPRECATED
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
$this->setLogPer(
|
$this->setLogPer(
|
||||||
'class',
|
'class',
|
||||||
$this->options['per_class'] ??
|
$this->options['per_class'] ??
|
||||||
$GLOBALS['LOG_PER_CLASS'] ??
|
$GLOBALS['LOG_PER_CLASS'] ?? // DEPRECATED
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
$this->setLogPer(
|
$this->setLogPer(
|
||||||
'page',
|
'page',
|
||||||
$this->options['per_page'] ??
|
$this->options['per_page'] ??
|
||||||
$GLOBALS['LOG_PER_PAGE'] ??
|
$GLOBALS['LOG_PER_PAGE'] ?? // DEPRECATED
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
$this->setLogPer(
|
$this->setLogPer(
|
||||||
'run',
|
'run',
|
||||||
$this->options['per_run'] ??
|
$this->options['per_run'] ??
|
||||||
$GLOBALS['LOG_PER_RUN'] ??
|
$GLOBALS['LOG_PER_RUN'] ?? // DEPRECATED
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
// set log per date
|
// set log per date
|
||||||
|
|||||||
@@ -277,6 +277,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
|||||||
private $acl_admin = 0;
|
private $acl_admin = 0;
|
||||||
/** @var array<mixed> */
|
/** @var array<mixed> */
|
||||||
public $security_level;
|
public $security_level;
|
||||||
|
/** @var array<string,mixed> Login ACL */
|
||||||
|
public $login_acl = [];
|
||||||
// layout publics
|
// layout publics
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public $table_width;
|
public $table_width;
|
||||||
@@ -308,6 +310,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
|||||||
* @param array<mixed> $db_config db config array, mandatory
|
* @param array<mixed> $db_config db config array, mandatory
|
||||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||||
|
* @param array<string,mixed> $login_acl Login ACL array,
|
||||||
|
* at least base/admin should be set
|
||||||
* @param array<mixed>|null $table_arrays Override table array data
|
* @param array<mixed>|null $table_arrays Override table array data
|
||||||
* instead of try to load from
|
* instead of try to load from
|
||||||
* include file
|
* include file
|
||||||
@@ -317,6 +321,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
|||||||
array $db_config,
|
array $db_config,
|
||||||
\CoreLibs\Debug\Logging $log,
|
\CoreLibs\Debug\Logging $log,
|
||||||
\CoreLibs\Language\L10n $l10n,
|
\CoreLibs\Language\L10n $l10n,
|
||||||
|
array $login_acl,
|
||||||
?array $table_arrays = null,
|
?array $table_arrays = null,
|
||||||
) {
|
) {
|
||||||
// init logger if not set
|
// init logger if not set
|
||||||
@@ -334,10 +339,10 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
|||||||
$this->lang_dir = $locale['path'];
|
$this->lang_dir = $locale['path'];
|
||||||
// load config array
|
// load config array
|
||||||
// get table array definitions for current page name
|
// get table array definitions for current page name
|
||||||
|
$this->login_acl = $login_acl;
|
||||||
// security settings
|
// security settings
|
||||||
$this->base_acl_level = (int)$_SESSION['BASE_ACL_LEVEL'];
|
$this->base_acl_level = $this->login_acl['base'] ?? 0;
|
||||||
$this->acl_admin = (int)$_SESSION['ADMIN'];
|
$this->acl_admin = $this->login_acl['admin'] ?? 0;
|
||||||
|
|
||||||
// replace any non valid variable names and set my page name
|
// replace any non valid variable names and set my page name
|
||||||
$this->my_page_name = str_replace(
|
$this->my_page_name = str_replace(
|
||||||
@@ -375,7 +380,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
|||||||
$this->base_acl_level,
|
$this->base_acl_level,
|
||||||
$this->acl_admin
|
$this->acl_admin
|
||||||
);
|
);
|
||||||
// $this->log->debug('SESSION FORM', 'sessin: ' . $this->log->prAr($_SESSION));
|
|
||||||
// here should be a check if the config_array is correct ...
|
// here should be a check if the config_array is correct ...
|
||||||
if (isset($config_array['show_fields']) && is_array($config_array['show_fields'])) {
|
if (isset($config_array['show_fields']) && is_array($config_array['show_fields'])) {
|
||||||
$this->field_array = $config_array['show_fields'];
|
$this->field_array = $config_array['show_fields'];
|
||||||
|
|||||||
@@ -563,6 +563,7 @@ class SmartyExtend extends \Smarty
|
|||||||
* @param string|null $set_page_width PAGE_WIDTH
|
* @param string|null $set_page_width PAGE_WIDTH
|
||||||
* @param string|null $set_stylesheet STYLESHEET
|
* @param string|null $set_stylesheet STYLESHEET
|
||||||
* @param string|null $set_javascript JAVASCRIPT
|
* @param string|null $set_javascript JAVASCRIPT
|
||||||
|
* @param string|null $set_user_name _SESSION['USER_NAME']
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function setSmartyVars(
|
private function setSmartyVars(
|
||||||
@@ -579,7 +580,8 @@ class SmartyExtend extends \Smarty
|
|||||||
?string $set_admin_javascript = null,
|
?string $set_admin_javascript = null,
|
||||||
?string $set_page_width = null,
|
?string $set_page_width = null,
|
||||||
?string $set_stylesheet = null,
|
?string $set_stylesheet = null,
|
||||||
?string $set_javascript = null
|
?string $set_javascript = null,
|
||||||
|
?string $set_user_name = null,
|
||||||
): void {
|
): void {
|
||||||
// trigger deprecation
|
// trigger deprecation
|
||||||
if (
|
if (
|
||||||
@@ -594,7 +596,8 @@ class SmartyExtend extends \Smarty
|
|||||||
$admin_call === true && (
|
$admin_call === true && (
|
||||||
$set_admin_stylesheet === null ||
|
$set_admin_stylesheet === null ||
|
||||||
$set_admin_javascript === null ||
|
$set_admin_javascript === null ||
|
||||||
$set_page_width === null
|
$set_page_width === null ||
|
||||||
|
$set_user_name === null
|
||||||
)
|
)
|
||||||
) ||
|
) ||
|
||||||
(
|
(
|
||||||
@@ -623,6 +626,7 @@ class SmartyExtend extends \Smarty
|
|||||||
$set_page_width = $set_page_width ?? PAGE_WIDTH;
|
$set_page_width = $set_page_width ?? PAGE_WIDTH;
|
||||||
$set_stylesheet = $set_stylesheet ?? STYLESHEET;
|
$set_stylesheet = $set_stylesheet ?? STYLESHEET;
|
||||||
$set_javascript = $set_javascript ?? JAVASCRIPT;
|
$set_javascript = $set_javascript ?? JAVASCRIPT;
|
||||||
|
$set_user_name = $set_user_name ?? $_SESSION['USER_NAME'] ?? '';
|
||||||
// depreacte call globals cms on null 4mcs
|
// depreacte call globals cms on null 4mcs
|
||||||
if (
|
if (
|
||||||
$cms === null &&
|
$cms === null &&
|
||||||
@@ -731,7 +735,7 @@ class SmartyExtend extends \Smarty
|
|||||||
$this->DATA['JS_FLATPICKR'] = $this->JS_FLATPICKR;
|
$this->DATA['JS_FLATPICKR'] = $this->JS_FLATPICKR;
|
||||||
$this->DATA['JS_FILE_UPLOADER'] = $this->JS_FILE_UPLOADER;
|
$this->DATA['JS_FILE_UPLOADER'] = $this->JS_FILE_UPLOADER;
|
||||||
// user name
|
// user name
|
||||||
$this->DATA['USER_NAME'] = !empty($_SESSION['USER_NAME']) ? $_SESSION['USER_NAME'] : '';
|
$this->DATA['USER_NAME'] = $set_user_name;
|
||||||
// the template part to include into the body
|
// the template part to include into the body
|
||||||
$this->DATA['TEMPLATE_NAME'] = $this->TEMPLATE_NAME;
|
$this->DATA['TEMPLATE_NAME'] = $this->TEMPLATE_NAME;
|
||||||
$this->DATA['CONTENT_INCLUDE'] = $this->CONTENT_INCLUDE;
|
$this->DATA['CONTENT_INCLUDE'] = $this->CONTENT_INCLUDE;
|
||||||
|
|||||||
Reference in New Issue
Block a user