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

update single display-name #1394

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
76 changes: 39 additions & 37 deletions lib/Command/CirclesMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);


/**
* Circles - Bring cloud-users closer together.
*
Expand All @@ -28,12 +27,13 @@
*
*/


namespace OCA\Circles\Command;

use Exception;
use OC\Core\Command\Base;
use OCA\Circles\Db\CoreRequestBuilder;
use OCA\Circles\Exceptions\MaintenanceException;
use OCA\Circles\Service\FederatedUserService;
use OCA\Circles\Service\MaintenanceService;
use OCA\Circles\Service\OutputService;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -48,50 +48,32 @@
* @package OCA\Circles\Command
*/
class CirclesMaintenance extends Base {
/** @var CoreRequestBuilder */
private $coreRequestBuilder;

/** @var MaintenanceService */
private $maintenanceService;

/** @var OutputService */
private $outputService;

/**
* CirclesMaintenance constructor.
*
* @param CoreRequestBuilder $coreRequestBuilder
* @param MaintenanceService $maintenanceService
* @param OutputService $outputService
*/
public function __construct(
CoreRequestBuilder $coreRequestBuilder,
MaintenanceService $maintenanceService,
OutputService $outputService
private FederatedUserService $federatedUserService,
private CoreRequestBuilder $coreRequestBuilder,
private MaintenanceService $maintenanceService,
private OutputService $outputService
) {
parent::__construct();

$this->coreRequestBuilder = $coreRequestBuilder;
$this->maintenanceService = $maintenanceService;
$this->outputService = $outputService;
}


protected function configure() {
parent::configure();
$this->setName('circles:maintenance')
->setDescription('Clean stuff, keeps the app running')
->addOption('level', '', InputOption::VALUE_REQUIRED, 'level of maintenance', '3')
->addOption(
'reset', '', InputOption::VALUE_NONE, 'reset Circles; remove all data related to the App'
)
->addOption(
'clean-shares', '', InputOption::VALUE_NONE, 'remove Circles\' shares'
)
->addOption(
'uninstall', '', InputOption::VALUE_NONE,
'Uninstall the apps and everything related to the app from the database'
)
->setDescription('Clean stuff, keeps the app running')
->addOption('refresh-display-name', '', InputOption::VALUE_REQUIRED, 'refresh single user display name', '')
->addOption('level', '', InputOption::VALUE_REQUIRED, 'level of maintenance', '3')
->addOption(
'reset', '', InputOption::VALUE_NONE, 'reset Circles; remove all data related to the App'
)
->addOption(
'clean-shares', '', InputOption::VALUE_NONE, 'remove Circles\' shares'
)
->addOption(
'uninstall', '', InputOption::VALUE_NONE,
'Uninstall the apps and everything related to the app from the database'
)
->addOption('force-refresh', '', InputOption::VALUE_NONE, 'enforce some refresh');
}

Expand All @@ -103,6 +85,10 @@ protected function configure() {
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
if (($refreshDisplayName = $input->getOption('refresh-display-name')) !== '') {
return $this->refreshSingleDisplayName($refreshDisplayName, $output);
}

$reset = $input->getOption('reset');
$uninstall = $input->getOption('uninstall');
$level = (int)$input->getOption('level');
Expand Down Expand Up @@ -168,4 +154,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return 0;
}

/**
* @param string $userId
* @param OutputInterface $output
* @return int
* @throws Exception
*/
public function refreshSingleDisplayName(string $userId, OutputInterface $output): int {
$federatedUser = $this->federatedUserService->getLocalFederatedUser($userId);
$displayName = $this->maintenanceService->updateDisplayName($federatedUser);
if ($displayName !== '') {
$output->writeln('Display name of ' . $federatedUser->getSingleId() . ' updated to ' . $displayName);
}

return 0;
}
}
32 changes: 27 additions & 5 deletions lib/Service/MaintenanceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
namespace OCA\Circles\Service;

use Exception;
use OC\User\NoUserException;
use OCA\Circles\Db\CircleRequest;
use OCA\Circles\Db\MemberRequest;
use OCA\Circles\Db\ShareWrapperRequest;
use OCA\Circles\Exceptions\InitiatorNotFoundException;
use OCA\Circles\Exceptions\MaintenanceException;
use OCA\Circles\Exceptions\RequestBuilderException;
use OCA\Circles\IFederatedUser;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\Probes\CircleProbe;
use OCA\Circles\Model\ShareWrapper;
Expand Down Expand Up @@ -420,14 +423,33 @@ private function refreshDisplayName(bool $forceRefresh = false): void {
continue; // ignore update done in the last 8 days.
}

if ($owner->getUserType() === Member::TYPE_USER) {
$user = $this->userManager->get($owner->getUserId());
$this->memberRequest->updateDisplayName($owner->getSingleId(), $user->getDisplayName());
$this->circleRequest->updateDisplayName($owner->getSingleId(), $user->getDisplayName());
}
$this->updateDisplayName($owner);
}
}

/**
* @param IFederatedUser $federatedUser
* @return string
* @throws NoUserException
*/
public function updateDisplayName(IFederatedUser $federatedUser): string {
if ($federatedUser->getUserType() !== Member::TYPE_USER) {
return '';
}

$user = $this->userManager->get($federatedUser->getUserId());
if ($user === null) {
throw new NoUserException();
}

$displayName = $user->getDisplayName();
if ($displayName !== '') {
$this->memberRequest->updateDisplayName($federatedUser->getSingleId(), $displayName);
$this->circleRequest->updateDisplayName($federatedUser->getSingleId(), $displayName);
}

return $displayName;
}

/**
* @throws RequestBuilderException
Expand Down
Loading