Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions apps/twofactor_backupcodes/lib/Provider/BackupCodesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,24 @@
use OC\App\AppManager;
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
use OCA\TwoFactorBackupCodes\Settings\Personal;
use OCP\AppFramework\Services\IInitialState;
use OCP\Authentication\TwoFactorAuth\IDeactivatableByAdmin;
use OCP\Authentication\TwoFactorAuth\IPersonalProviderSettings;
use OCP\Authentication\TwoFactorAuth\IProvidesPersonalSettings;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\IUser;
use OCP\Template\ITemplate;
use OCP\Template\ITemplateManager;

class BackupCodesProvider implements IDeactivatableByAdmin, IProvidesPersonalSettings {

/** @var AppManager */
private $appManager;

/**
* @param string $appName
* @param BackupCodeStorage $storage
* @param IL10N $l10n
* @param AppManager $appManager
*/
public function __construct(
private string $appName,
private BackupCodeStorage $storage,
private IL10N $l10n,
AppManager $appManager,
private IInitialStateService $initialStateService,
private AppManager $appManager,
private IInitialState $initialState,
private ITemplateManager $templateManager,
) {
$this->appManager = $appManager;
}

/**
Expand Down Expand Up @@ -131,11 +120,11 @@ public function isActive(IUser $user): bool {
*/
public function getPersonalSettings(IUser $user): IPersonalProviderSettings {
$state = $this->storage->getBackupCodesState($user);
$this->initialStateService->provideInitialState($this->appName, 'state', $state);
$this->initialState->provideInitialState('state', $state);
return new Personal();
}

public function disableFor(IUser $user) {
public function disableFor(IUser $user): void {
$this->storage->deleteCodes($user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use OC\App\AppManager;
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
use OCP\IInitialStateService;
use OCP\AppFramework\Services\IInitialState;
use OCP\IL10N;
use OCP\IUser;
use OCP\Server;
Expand All @@ -25,7 +25,7 @@ class BackupCodesProviderTest extends TestCase {
private BackupCodeStorage&MockObject $storage;
private IL10N&MockObject $l10n;
private AppManager&MockObject $appManager;
private IInitialStateService&MockObject $initialState;
private IInitialState&MockObject $initialState;

private ITemplateManager $templateManager;
private BackupCodesProvider $provider;
Expand All @@ -37,7 +37,7 @@ protected function setUp(): void {
$this->storage = $this->createMock(BackupCodeStorage::class);
$this->l10n = $this->createMock(IL10N::class);
$this->appManager = $this->createMock(AppManager::class);
$this->initialState = $this->createMock(IInitialStateService::class);
$this->initialState = $this->createMock(IInitialState::class);
$this->templateManager = Server::get(ITemplateManager::class);

$this->provider = new BackupCodesProvider(
Expand Down
13 changes: 5 additions & 8 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2424,14 +2424,6 @@
<code><![CDATA[getName]]></code>
</DeprecatedMethod>
</file>
<file src="apps/twofactor_backupcodes/lib/Provider/BackupCodesProvider.php">
<DeprecatedInterface>
<code><![CDATA[private]]></code>
</DeprecatedInterface>
<DeprecatedMethod>
<code><![CDATA[provideInitialState]]></code>
</DeprecatedMethod>
</file>
<file src="apps/user_ldap/ajax/clearMappings.php">
<DeprecatedMethod>
<code><![CDATA[\OC_JSON::callCheck()]]></code>
Expand Down Expand Up @@ -4013,6 +4005,11 @@
<code><![CDATA[isAdmin]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/private/InitialStateService.php">
<UndefinedInterfaceMethod>
<code><![CDATA[query]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/private/Installer.php">
<InvalidArgument>
<code><![CDATA[false]]></code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OC\ServerContainer;
use OC\Settings\AuthorizedGroupMapper;
use OCA\WorkflowEngine\Manager;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\IOutput;
use OCP\AppFramework\IAppContainer;
use OCP\AppFramework\QueryException;
Expand Down Expand Up @@ -200,7 +201,7 @@ public function __construct(string $appName, array $urlParams = [], ?ServerConta
$server->getUserSession()->isLoggedIn(),
$c->get(IGroupManager::class),
$c->get(ISubAdmin::class),
$server->getAppManager(),
$c->get(IAppManager::class),
$server->getL10N('lib'),
$c->get(AuthorizedGroupMapper::class),
$c->get(IUserSession::class),
Expand Down
22 changes: 8 additions & 14 deletions lib/private/InitialStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,23 @@
use OCP\AppFramework\QueryException;
use OCP\AppFramework\Services\InitialStateProvider;
use OCP\IInitialStateService;
use OCP\IServerContainer;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

class InitialStateService implements IInitialStateService {
/** @var LoggerInterface */
private $logger;

/** @var string[][] */
private $states = [];
private array $states = [];

/** @var Closure[][] */
private $lazyStates = [];
private array $lazyStates = [];

/** @var Coordinator */
private $bootstrapCoordinator;

/** @var IServerContainer */
private $container;

public function __construct(LoggerInterface $logger, Coordinator $bootstrapCoordinator, IServerContainer $container) {
$this->logger = $logger;
$this->bootstrapCoordinator = $bootstrapCoordinator;
$this->container = $container;
public function __construct(
private LoggerInterface $logger,
private Coordinator $bootstrapCoordinator,
private ContainerInterface $container,
) {
}

public function provideInitialState(string $appName, string $key, $data): void {
Expand Down
38 changes: 12 additions & 26 deletions lib/private/UserStatus/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,21 @@
*/
namespace OC\UserStatus;

use OCP\IServerContainer;
use OCP\UserStatus\IManager;
use OCP\UserStatus\IProvider;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

class Manager implements IManager {
/** @var IServerContainer */
private $container;

/** @var LoggerInterface */
private $logger;

/** @var class-string */
private $providerClass;

/** @var IProvider */
private $provider;

/**
* Manager constructor.
*
* @param IServerContainer $container
* @param LoggerInterface $logger
*/
public function __construct(IServerContainer $container,
LoggerInterface $logger) {
$this->container = $container;
$this->logger = $logger;
/** @var ?class-string */
private ?string $providerClass = null;
private ?IProvider $provider = null;

public function __construct(
private ContainerInterface $container,
private LoggerInterface $logger,
) {
}

/**
Expand Down Expand Up @@ -89,7 +75,7 @@ private function setupProvider(): void {

public function setUserStatus(string $userId, string $messageId, string $status, bool $createBackup = false, ?string $customMessage = null): void {
$this->setupProvider();
if (!$this->provider || !($this->provider instanceof ISettableProvider)) {
if (!$this->provider instanceof ISettableProvider) {
return;
}

Expand All @@ -98,15 +84,15 @@ public function setUserStatus(string $userId, string $messageId, string $status,

public function revertUserStatus(string $userId, string $messageId, string $status): void {
$this->setupProvider();
if (!$this->provider || !($this->provider instanceof ISettableProvider)) {
if (!$this->provider instanceof ISettableProvider) {
return;
}
$this->provider->revertUserStatus($userId, $messageId, $status);
}

public function revertMultipleUserStatus(array $userIds, string $messageId, string $status): void {
$this->setupProvider();
if (!$this->provider || !($this->provider instanceof ISettableProvider)) {
if (!$this->provider instanceof ISettableProvider) {
return;
}
$this->provider->revertMultipleUserStatus($userIds, $messageId, $status);
Expand Down
8 changes: 4 additions & 4 deletions lib/public/IInitialStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

/**
* @since 16.0.0
* @deprecated 21 Use OCP\AppFramework\Services\IInitialState or OCP\AppFramework\Services\InitialStateProvider
* @deprecated 21 Use {@see \OCP\AppFramework\Services\IInitialState} or {@see \OCP\AppFramework\Services\InitialStateProvider}
* @see \OCP\AppFramework\Services\IInitialState
*/
interface IInitialStateService {
/**
* Allows an app to provide its initial state to the template system.
* Use this if you know your initial state sill be used for example if
* Use this if you know your initial state still be used for example if
* you are in the render function of you controller.
*
* @since 16.0.0
Expand All @@ -26,7 +26,7 @@ interface IInitialStateService {
* @param string $key
* @param bool|int|float|string|array|\JsonSerializable $data
*
* @deprecated 21 Use OCP\AppFramework\Services\IInitialState or OCP\AppFramework\Services\InitialStateProvider
* @deprecated 21 Use {@see \OCP\AppFramework\Services\IInitialState} or {@see \OCP\AppFramework\Services\InitialStateProvider}
* @see \OCP\AppFramework\Services\IInitialState::provideInitialState()
*/
public function provideInitialState(string $appName, string $key, $data): void;
Expand All @@ -44,7 +44,7 @@ public function provideInitialState(string $appName, string $key, $data): void;
* @param string $key
* @param Closure $closure returns a primitive or an object that implements JsonSerializable
*
* @deprecated 21 Use OCP\AppFramework\Services\IInitialState or OCP\AppFramework\Services\InitialStateProvider
* @deprecated 21 Use {@see \OCP\AppFramework\Services\IInitialState} or {@see \OCP\AppFramework\Services\InitialStateProvider}
* @see \OCP\AppFramework\Services\IInitialState::provideLazyInitialState()
*/
public function provideLazyInitialState(string $appName, string $key, Closure $closure): void;
Expand Down
Loading