Provide config though initial state service

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2020-04-03 22:42:45 +02:00
parent 24e58947d6
commit cbd20867b5
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
2 changed files with 37 additions and 24 deletions

View File

@ -37,6 +37,7 @@ use OCP\App\IAppManager;
use OCP\Defaults; use OCP\Defaults;
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IInitialStateService;
use OCP\IL10N; use OCP\IL10N;
use OCP\ISession; use OCP\ISession;
use OCP\IURLGenerator; use OCP\IURLGenerator;
@ -75,6 +76,9 @@ class JSConfigHelper {
/** @var CapabilitiesManager */ /** @var CapabilitiesManager */
private $capabilitiesManager; private $capabilitiesManager;
/** @var IInitialStateService */
private $initialStateService;
/** @var array user back-ends excluded from password verification */ /** @var array user back-ends excluded from password verification */
private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true];
@ -99,7 +103,8 @@ class JSConfigHelper {
IGroupManager $groupManager, IGroupManager $groupManager,
IniGetWrapper $iniWrapper, IniGetWrapper $iniWrapper,
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
CapabilitiesManager $capabilitiesManager) { CapabilitiesManager $capabilitiesManager,
IInitialStateService $initialStateService) {
$this->l = $l; $this->l = $l;
$this->defaults = $defaults; $this->defaults = $defaults;
$this->appManager = $appManager; $this->appManager = $appManager;
@ -110,6 +115,7 @@ class JSConfigHelper {
$this->iniWrapper = $iniWrapper; $this->iniWrapper = $iniWrapper;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
$this->capabilitiesManager = $capabilitiesManager; $this->capabilitiesManager = $capabilitiesManager;
$this->initialStateService = $initialStateService;
} }
public function getConfig() { public function getConfig() {
@ -146,7 +152,7 @@ class JSConfigHelper {
$defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
$defaultExpireDate = $enforceDefaultExpireDate = null; $defaultExpireDate = $enforceDefaultExpireDate = null;
if ($defaultExpireDateEnabled) { if ($defaultExpireDateEnabled) {
$defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); $defaultExpireDate = (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
$enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
} }
$outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
@ -154,12 +160,12 @@ class JSConfigHelper {
$defaultInternalExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes'; $defaultInternalExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes';
$defaultInternalExpireDate = $defaultInternalExpireDateEnforced = null; $defaultInternalExpireDate = $defaultInternalExpireDateEnforced = null;
if ($defaultInternalExpireDateEnabled) { if ($defaultInternalExpireDateEnabled) {
$defaultInternalExpireDate = (int) $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); $defaultInternalExpireDate = (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7');
$defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_internal_enforce_expire_date', 'no') === 'yes'; $defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_internal_enforce_expire_date', 'no') === 'yes';
} }
$countOfDataLocation = 0; $countOfDataLocation = 0;
$dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); $dataLocation = str_replace(\OC::$SERVERROOT . '/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation);
if ($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { if ($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) {
$dataLocation = false; $dataLocation = false;
} }
@ -175,17 +181,31 @@ class JSConfigHelper {
$capabilities = $this->capabilitiesManager->getCapabilities(); $capabilities = $this->capabilitiesManager->getCapabilities();
$config = [
'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')),
'session_keepalive' => $this->config->getSystemValue('session_keepalive', true),
'auto_logout' => $this->config->getSystemValue('auto_logout', false),
'version' => implode('.', \OCP\Util::getVersion()),
'versionstring' => \OC_Util::getVersionString(),
'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value
'lost_password_link' => $this->config->getSystemValue('lost_password_link', null),
'modRewriteWorking' => $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true',
'sharing.maxAutocompleteResults' => (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0),
'sharing.minSearchStringLength' => (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0),
'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX,
];
$array = [ $array = [
"_oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', "_oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
"_oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', "_oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false',
"backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false', "backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false',
"oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', "oc_dataURL" => is_string($dataLocation) ? "\"" . $dataLocation . "\"" : 'false',
"_oc_webroot" => "\"".\OC::$WEBROOT."\"", "_oc_webroot" => "\"" . \OC::$WEBROOT . "\"",
"_oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution "_oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution
"datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)),
'nc_lastLogin' => $lastConfirmTimestamp, 'nc_lastLogin' => $lastConfirmTimestamp,
'nc_pageLoad' => time(), 'nc_pageLoad' => time(),
"dayNames" => json_encode([ "dayNames" => json_encode([
(string)$this->l->t('Sunday'), (string)$this->l->t('Sunday'),
(string)$this->l->t('Monday'), (string)$this->l->t('Monday'),
(string)$this->l->t('Tuesday'), (string)$this->l->t('Tuesday'),
@ -194,7 +214,7 @@ class JSConfigHelper {
(string)$this->l->t('Friday'), (string)$this->l->t('Friday'),
(string)$this->l->t('Saturday') (string)$this->l->t('Saturday')
]), ]),
"dayNamesShort" => json_encode([ "dayNamesShort" => json_encode([
(string)$this->l->t('Sun.'), (string)$this->l->t('Sun.'),
(string)$this->l->t('Mon.'), (string)$this->l->t('Mon.'),
(string)$this->l->t('Tue.'), (string)$this->l->t('Tue.'),
@ -203,7 +223,7 @@ class JSConfigHelper {
(string)$this->l->t('Fri.'), (string)$this->l->t('Fri.'),
(string)$this->l->t('Sat.') (string)$this->l->t('Sat.')
]), ]),
"dayNamesMin" => json_encode([ "dayNamesMin" => json_encode([
(string)$this->l->t('Su'), (string)$this->l->t('Su'),
(string)$this->l->t('Mo'), (string)$this->l->t('Mo'),
(string)$this->l->t('Tu'), (string)$this->l->t('Tu'),
@ -240,19 +260,8 @@ class JSConfigHelper {
(string)$this->l->t('Nov.'), (string)$this->l->t('Nov.'),
(string)$this->l->t('Dec.') (string)$this->l->t('Dec.')
]), ]),
"firstDay" => json_encode($this->l->l('firstday', null)) , "firstDay" => json_encode($this->l->l('firstday', null)),
"_oc_config" => json_encode([ "_oc_config" => json_encode($config),
'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')),
'session_keepalive' => $this->config->getSystemValue('session_keepalive', true),
'version' => implode('.', \OCP\Util::getVersion()),
'versionstring' => \OC_Util::getVersionString(),
'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value
'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null),
'modRewriteWorking' => $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true',
'sharing.maxAutocompleteResults' => (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0),
'sharing.minSearchStringLength' => (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0),
'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX,
]),
"oc_appconfig" => json_encode([ "oc_appconfig" => json_encode([
'core' => [ 'core' => [
'defaultExpireDateEnabled' => $defaultExpireDateEnabled, 'defaultExpireDateEnabled' => $defaultExpireDateEnabled,
@ -296,6 +305,8 @@ class JSConfigHelper {
]); ]);
} }
$this->initialStateService->provideInitialState('core', 'config', $config);
// Allow hooks to modify the output values // Allow hooks to modify the output values
\OC_Hook::emit('\OCP\Config', 'js', ['array' => &$array]); \OC_Hook::emit('\OCP\Config', 'js', ['array' => &$array]);

View File

@ -49,6 +49,7 @@ use OC\Template\JSCombiner;
use OC\Template\JSConfigHelper; use OC\Template\JSConfigHelper;
use OC\Template\SCSSCacher; use OC\Template\SCSSCacher;
use OCP\Defaults; use OCP\Defaults;
use OCP\IInitialStateService;
use OCP\Support\Subscription\IRegistry; use OCP\Support\Subscription\IRegistry;
class TemplateLayout extends \OC_Template { class TemplateLayout extends \OC_Template {
@ -183,7 +184,8 @@ class TemplateLayout extends \OC_Template {
\OC::$server->getGroupManager(), \OC::$server->getGroupManager(),
\OC::$server->getIniWrapper(), \OC::$server->getIniWrapper(),
\OC::$server->getURLGenerator(), \OC::$server->getURLGenerator(),
\OC::$server->getCapabilitiesManager() \OC::$server->getCapabilitiesManager(),
\OC::$server->query(IInitialStateService::class)
); );
$this->assign('inline_ocjs', $jsConfigHelper->getConfig()); $this->assign('inline_ocjs', $jsConfigHelper->getConfig());
} else { } else {