Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValidatePhoneNumber and PersonalInfo to use public IAccountManager #26961

Merged
merged 2 commits into from
May 12, 2021
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
9 changes: 4 additions & 5 deletions apps/settings/lib/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

namespace OCA\Settings\Settings\Personal;

use OC\Accounts\AccountManager;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager;
Expand All @@ -57,7 +56,7 @@ class PersonalInfo implements ISettings {
private $config;
/** @var IUserManager */
private $userManager;
/** @var AccountManager */
/** @var IAccountManager */
private $accountManager;
/** @var IGroupManager */
private $groupManager;
Expand All @@ -72,7 +71,7 @@ public function __construct(
IConfig $config,
IUserManager $userManager,
IGroupManager $groupManager,
AccountManager $accountManager,
IAccountManager $accountManager,
IAppManager $appManager,
IFactory $l10nFactory,
IL10N $l
Expand Down Expand Up @@ -272,10 +271,10 @@ private function getMessageParameters(IAccount $account): array {
$messageParameters = [];
foreach ($needVerifyMessage as $property) {
switch ($account->getProperty($property)->getVerified()) {
case AccountManager::VERIFIED:
case IAccountManager::VERIFIED:
$message = $this->l->t('Verifying');
break;
case AccountManager::VERIFICATION_IN_PROGRESS:
case IAccountManager::VERIFICATION_IN_PROGRESS:
$message = $this->l->t('Verifying …');
break;
default:
Expand Down
22 changes: 10 additions & 12 deletions lib/private/Repair/NC21/ValidatePhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace OC\Repair\NC21;

use OC\Accounts\AccountManager;
use OCP\Accounts\IAccountManager;
use OCP\IConfig;
use OCP\IUser;
Expand All @@ -40,11 +39,11 @@ class ValidatePhoneNumber implements IRepairStep {
protected $config;
/** @var IUserManager */
protected $userManager;
/** @var AccountManager */
/** @var IAccountManager */
private $accountManager;

public function __construct(IUserManager $userManager,
AccountManager $accountManager,
IAccountManager $accountManager,
IConfig $config) {
$this->config = $config;
$this->userManager = $userManager;
Expand All @@ -55,10 +54,6 @@ public function getName(): string {
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 {
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');
Expand All @@ -68,13 +63,16 @@ public function run(IOutput $output): void {
$numRemoved = 0;

$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'] !== '') {
$updated = $this->accountManager->updateUser($user, $account);
if ($property->getValue() !== '') {
$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 ($updated[IAccountManager::PROPERTY_PHONE]['value'] === '') {
if ($property->getValue() !== $updatedProperty->getValue()) {
if ($updatedProperty->getValue() === '') {
$numRemoved++;
} else {
$numUpdated++;
Expand Down