Merge pull request #25892 from nextcloud/techdept/initialstate/part1
Move some settings over to the IInitialState
This commit is contained in:
commit
ce430c3613
|
@ -27,8 +27,8 @@ namespace OCA\Accessibility\Settings;
|
|||
|
||||
use OCA\Accessibility\AccessibilityProvider;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\IConfig;
|
||||
use OCP\IInitialStateService;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUserSession;
|
||||
|
@ -55,26 +55,16 @@ class Personal implements ISettings {
|
|||
/** @var AccessibilityProvider */
|
||||
private $accessibilityProvider;
|
||||
|
||||
/** @var IInitialStateService */
|
||||
/** @var IInitialState */
|
||||
private $initialStateService;
|
||||
|
||||
/**
|
||||
* Settings constructor.
|
||||
*
|
||||
* @param string $appName
|
||||
* @param IConfig $config
|
||||
* @param IUserSession $userSession
|
||||
* @param IL10N $l
|
||||
* @param IURLGenerator $urlGenerator
|
||||
* @param AccessibilityProvider $accessibilityProvider
|
||||
*/
|
||||
public function __construct(string $appName,
|
||||
IConfig $config,
|
||||
IUserSession $userSession,
|
||||
IL10N $l,
|
||||
IURLGenerator $urlGenerator,
|
||||
AccessibilityProvider $accessibilityProvider,
|
||||
IInitialStateService $initialStateService) {
|
||||
IInitialState $initialStateService) {
|
||||
$this->appName = $appName;
|
||||
$this->config = $config;
|
||||
$this->userSession = $userSession;
|
||||
|
@ -88,7 +78,7 @@ class Personal implements ISettings {
|
|||
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered
|
||||
* @since 9.1
|
||||
*/
|
||||
public function getForm() {
|
||||
public function getForm(): TemplateResponse {
|
||||
Util::addScript('accessibility', 'accessibility');
|
||||
Util::addStyle('accessibility', 'style');
|
||||
|
||||
|
@ -104,8 +94,8 @@ class Personal implements ISettings {
|
|||
'font' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false)
|
||||
];
|
||||
|
||||
$this->initialStateService->provideInitialState($this->appName, 'available-config', $availableConfig);
|
||||
$this->initialStateService->provideInitialState($this->appName, 'user-config', $userConfig);
|
||||
$this->initialStateService->provideInitialState('available-config', $availableConfig);
|
||||
$this->initialStateService->provideInitialState('user-config', $userConfig);
|
||||
|
||||
return new TemplateResponse($this->appName, 'settings-personal');
|
||||
}
|
||||
|
@ -114,7 +104,7 @@ class Personal implements ISettings {
|
|||
* @return string the section ID, e.g. 'sharing'
|
||||
* @since 9.1
|
||||
*/
|
||||
public function getSection() {
|
||||
public function getSection(): string {
|
||||
return $this->appName;
|
||||
}
|
||||
|
||||
|
@ -126,7 +116,7 @@ class Personal implements ISettings {
|
|||
* E.g.: 70
|
||||
* @since 9.1
|
||||
*/
|
||||
public function getPriority() {
|
||||
public function getPriority(): int {
|
||||
return 40;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,20 +29,20 @@ namespace OCA\Files_Sharing\Settings;
|
|||
|
||||
use OCA\Files_Sharing\AppInfo\Application;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\IConfig;
|
||||
use OCP\IInitialStateService;
|
||||
use OCP\Settings\ISettings;
|
||||
|
||||
class Personal implements ISettings {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var IInitialStateService */
|
||||
/** @var IInitialState */
|
||||
private $initialState;
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
public function __construct(IConfig $config, IInitialStateService $initialState, string $userId) {
|
||||
public function __construct(IConfig $config, IInitialState $initialState, string $userId) {
|
||||
$this->config = $config;
|
||||
$this->initialState = $initialState;
|
||||
$this->userId = $userId;
|
||||
|
@ -52,8 +52,8 @@ class Personal implements ISettings {
|
|||
$defaultAcceptSystemConfig = $this->config->getSystemValueBool('sharing.enable_share_accept', false) ? 'no' : 'yes';
|
||||
$acceptDefault = $this->config->getUserValue($this->userId, Application::APP_ID, 'default_accept', $defaultAcceptSystemConfig) === 'yes';
|
||||
$enforceAccept = $this->config->getSystemValueBool('sharing.force_share_accept', false);
|
||||
$this->initialState->provideInitialState(Application::APP_ID, 'accept_default', $acceptDefault);
|
||||
$this->initialState->provideInitialState(Application::APP_ID, 'enforce_accept', $enforceAccept);
|
||||
$this->initialState->provideInitialState('accept_default', $acceptDefault);
|
||||
$this->initialState->provideInitialState('enforce_accept', $enforceAccept);
|
||||
return new TemplateResponse('files_sharing', 'Settings/personal');
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace OCA\Settings\Settings\Admin;
|
|||
|
||||
use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\Encryption\IManager;
|
||||
use OCP\IInitialStateService;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Settings\ISettings;
|
||||
|
||||
|
@ -45,13 +45,13 @@ class Security implements ISettings {
|
|||
/** @var MandatoryTwoFactor */
|
||||
private $mandatoryTwoFactor;
|
||||
|
||||
/** @var IInitialStateService */
|
||||
/** @var IInitialState */
|
||||
private $initialState;
|
||||
|
||||
public function __construct(IManager $manager,
|
||||
IUserManager $userManager,
|
||||
MandatoryTwoFactor $mandatoryTwoFactor,
|
||||
IInitialStateService $initialState) {
|
||||
IInitialState $initialState) {
|
||||
$this->manager = $manager;
|
||||
$this->userManager = $userManager;
|
||||
$this->mandatoryTwoFactor = $mandatoryTwoFactor;
|
||||
|
@ -61,7 +61,7 @@ class Security implements ISettings {
|
|||
/**
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function getForm() {
|
||||
public function getForm(): TemplateResponse {
|
||||
$encryptionModules = $this->manager->getEncryptionModules();
|
||||
$defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId();
|
||||
$encryptionModuleList = [];
|
||||
|
@ -74,7 +74,6 @@ class Security implements ISettings {
|
|||
}
|
||||
|
||||
$this->initialState->provideInitialState(
|
||||
'settings',
|
||||
'mandatory2FAState',
|
||||
$this->mandatoryTwoFactor->getState()
|
||||
);
|
||||
|
@ -94,7 +93,7 @@ class Security implements ISettings {
|
|||
/**
|
||||
* @return string the section ID, e.g. 'sharing'
|
||||
*/
|
||||
public function getSection() {
|
||||
public function getSection(): string {
|
||||
return 'security';
|
||||
}
|
||||
|
||||
|
@ -105,7 +104,7 @@ class Security implements ISettings {
|
|||
*
|
||||
* E.g.: 70
|
||||
*/
|
||||
public function getPriority() {
|
||||
public function getPriority(): int {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
|
|||
use OC\Encryption\Manager;
|
||||
use OCA\Settings\Settings\Admin\Security;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IInitialStateService;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\IUserManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
@ -46,7 +46,7 @@ class SecurityTest extends TestCase {
|
|||
private $userManager;
|
||||
/** @var MandatoryTwoFactor|MockObject */
|
||||
private $mandatoryTwoFactor;
|
||||
/** @var IInitialStateService|MockObject */
|
||||
/** @var IInitialState|MockObject */
|
||||
private $initialState;
|
||||
|
||||
protected function setUp(): void {
|
||||
|
@ -54,7 +54,7 @@ class SecurityTest extends TestCase {
|
|||
$this->manager = $this->getMockBuilder(Manager::class)->disableOriginalConstructor()->getMock();
|
||||
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
|
||||
$this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
|
||||
$this->initialState = $this->createMock(IInitialStateService::class);
|
||||
$this->initialState = $this->createMock(IInitialState::class);
|
||||
|
||||
$this->admin = new Security(
|
||||
$this->manager,
|
||||
|
|
|
@ -28,9 +28,9 @@ namespace OCA\WorkflowEngine\Settings;
|
|||
use OCA\WorkflowEngine\AppInfo\Application;
|
||||
use OCA\WorkflowEngine\Manager;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IConfig;
|
||||
use OCP\IInitialStateService;
|
||||
use OCP\IL10N;
|
||||
use OCP\Settings\ISettings;
|
||||
use OCP\WorkflowEngine\Events\LoadSettingsScriptsEvent;
|
||||
|
@ -54,7 +54,7 @@ abstract class ASettings implements ISettings {
|
|||
/** @var Manager */
|
||||
protected $manager;
|
||||
|
||||
/** @var IInitialStateService */
|
||||
/** @var IInitialState */
|
||||
private $initialStateService;
|
||||
|
||||
/** @var IConfig */
|
||||
|
@ -65,7 +65,7 @@ abstract class ASettings implements ISettings {
|
|||
IL10N $l,
|
||||
IEventDispatcher $eventDispatcher,
|
||||
Manager $manager,
|
||||
IInitialStateService $initialStateService,
|
||||
IInitialState $initialStateService,
|
||||
IConfig $config
|
||||
) {
|
||||
$this->appName = $appName;
|
||||
|
@ -81,7 +81,7 @@ abstract class ASettings implements ISettings {
|
|||
/**
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function getForm() {
|
||||
public function getForm(): TemplateResponse {
|
||||
// @deprecated in 20.0.0: retire this one in favor of the typed event
|
||||
$this->eventDispatcher->dispatch(
|
||||
'OCP\WorkflowEngine::loadAdditionalSettingScripts',
|
||||
|
@ -91,33 +91,28 @@ abstract class ASettings implements ISettings {
|
|||
|
||||
$entities = $this->manager->getEntitiesList();
|
||||
$this->initialStateService->provideInitialState(
|
||||
Application::APP_ID,
|
||||
'entities',
|
||||
$this->entitiesToArray($entities)
|
||||
);
|
||||
|
||||
$operators = $this->manager->getOperatorList();
|
||||
$this->initialStateService->provideInitialState(
|
||||
Application::APP_ID,
|
||||
'operators',
|
||||
$this->operatorsToArray($operators)
|
||||
);
|
||||
|
||||
$checks = $this->manager->getCheckList();
|
||||
$this->initialStateService->provideInitialState(
|
||||
Application::APP_ID,
|
||||
'checks',
|
||||
$this->checksToArray($checks)
|
||||
);
|
||||
|
||||
$this->initialStateService->provideInitialState(
|
||||
Application::APP_ID,
|
||||
'scope',
|
||||
$this->getScope()
|
||||
);
|
||||
|
||||
$this->initialStateService->provideInitialState(
|
||||
Application::APP_ID,
|
||||
'appstoreenabled',
|
||||
$this->config->getSystemValueBool('appstoreenabled', true)
|
||||
);
|
||||
|
@ -128,7 +123,7 @@ abstract class ASettings implements ISettings {
|
|||
/**
|
||||
* @return string the section ID, e.g. 'sharing'
|
||||
*/
|
||||
public function getSection() {
|
||||
public function getSection(): ?string {
|
||||
return 'workflow';
|
||||
}
|
||||
|
||||
|
@ -139,7 +134,7 @@ abstract class ASettings implements ISettings {
|
|||
*
|
||||
* E.g.: 70
|
||||
*/
|
||||
public function getPriority() {
|
||||
public function getPriority(): int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class Personal extends ASettings {
|
|||
return IManager::SCOPE_USER;
|
||||
}
|
||||
|
||||
public function getSection() {
|
||||
public function getSection(): ?string {
|
||||
return $this->manager->isUserScopeEnabled() ? 'workflow' : null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue