Merge pull request #26961 from nextcloud/techdet/noid/lib-accountmanager-api

ValidatePhoneNumber and PersonalInfo to use public IAccountManager
This commit is contained in:
blizzz 2021-05-12 23:35:28 +02:00 committed by GitHub
commit a923213b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 17 deletions

View File

@ -35,7 +35,6 @@ declare(strict_types=1);
namespace OCA\Settings\Settings\Personal; namespace OCA\Settings\Settings\Personal;
use OC\Accounts\AccountManager;
use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\Accounts\IAccount; use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager; use OCP\Accounts\IAccountManager;
@ -57,7 +56,7 @@ class PersonalInfo implements ISettings {
private $config; private $config;
/** @var IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var AccountManager */ /** @var IAccountManager */
private $accountManager; private $accountManager;
/** @var IGroupManager */ /** @var IGroupManager */
private $groupManager; private $groupManager;
@ -72,7 +71,7 @@ class PersonalInfo implements ISettings {
IConfig $config, IConfig $config,
IUserManager $userManager, IUserManager $userManager,
IGroupManager $groupManager, IGroupManager $groupManager,
AccountManager $accountManager, IAccountManager $accountManager,
IAppManager $appManager, IAppManager $appManager,
IFactory $l10nFactory, IFactory $l10nFactory,
IL10N $l IL10N $l
@ -272,10 +271,10 @@ class PersonalInfo implements ISettings {
$messageParameters = []; $messageParameters = [];
foreach ($needVerifyMessage as $property) { foreach ($needVerifyMessage as $property) {
switch ($account->getProperty($property)->getVerified()) { switch ($account->getProperty($property)->getVerified()) {
case AccountManager::VERIFIED: case IAccountManager::VERIFIED:
$message = $this->l->t('Verifying'); $message = $this->l->t('Verifying');
break; break;
case AccountManager::VERIFICATION_IN_PROGRESS: case IAccountManager::VERIFICATION_IN_PROGRESS:
$message = $this->l->t('Verifying …'); $message = $this->l->t('Verifying …');
break; break;
default: default:

View File

@ -26,7 +26,6 @@ declare(strict_types=1);
namespace OC\Repair\NC21; namespace OC\Repair\NC21;
use OC\Accounts\AccountManager;
use OCP\Accounts\IAccountManager; use OCP\Accounts\IAccountManager;
use OCP\IConfig; use OCP\IConfig;
use OCP\IUser; use OCP\IUser;
@ -40,11 +39,11 @@ class ValidatePhoneNumber implements IRepairStep {
protected $config; protected $config;
/** @var IUserManager */ /** @var IUserManager */
protected $userManager; protected $userManager;
/** @var AccountManager */ /** @var IAccountManager */
private $accountManager; private $accountManager;
public function __construct(IUserManager $userManager, public function __construct(IUserManager $userManager,
AccountManager $accountManager, IAccountManager $accountManager,
IConfig $config) { IConfig $config) {
$this->config = $config; $this->config = $config;
$this->userManager = $userManager; $this->userManager = $userManager;
@ -55,10 +54,6 @@ class ValidatePhoneNumber implements IRepairStep {
return 'Validate the phone number and store it in a known format for search'; return 'Validate the phone number and store it in a known format for search';
} }
private function shouldRun(): bool {
return true;
}
public function run(IOutput $output): void { public function run(IOutput $output): void {
if ($this->config->getSystemValueString('default_phone_region', '') === '') { if ($this->config->getSystemValueString('default_phone_region', '') === '') {
throw new \Exception('Can not validate phone numbers without `default_phone_region` being set in the config file'); throw new \Exception('Can not validate phone numbers without `default_phone_region` being set in the config file');
@ -68,13 +63,16 @@ class ValidatePhoneNumber implements IRepairStep {
$numRemoved = 0; $numRemoved = 0;
$this->userManager->callForSeenUsers(function (IUser $user) use (&$numUpdated, &$numRemoved) { $this->userManager->callForSeenUsers(function (IUser $user) use (&$numUpdated, &$numRemoved) {
$account = $this->accountManager->getUser($user); $account = $this->accountManager->getAccount($user);
$property = $account->getProperty(IAccountManager::PROPERTY_PHONE);
if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== '') { if ($property->getValue() !== '') {
$updated = $this->accountManager->updateUser($user, $account); $this->accountManager->updateAccount($account);
$updatedAccount = $this->accountManager->getAccount($user);
$updatedProperty = $updatedAccount->getProperty(IAccountManager::PROPERTY_PHONE);
if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== $updated[IAccountManager::PROPERTY_PHONE]['value']) { if ($property->getValue() !== $updatedProperty->getValue()) {
if ($updated[IAccountManager::PROPERTY_PHONE]['value'] === '') { if ($updatedProperty->getValue() === '') {
$numRemoved++; $numRemoved++;
} else { } else {
$numUpdated++; $numUpdated++;