aboutsummaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/lib/Controller/UsersController.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-03-09 21:22:59 +0100
committerJoas Schilling <coding@schilljs.com>2021-03-10 17:19:55 +0100
commitc7be18c0d6cf6a5af2251abdfa18cdccd11da33b (patch)
tree13dcd637d5cc1437ec3febf8ba5f809ce11f7c63 /apps/provisioning_api/lib/Controller/UsersController.php
parent7baefcfc74d12da8a3850b6747da7c055c56e522 (diff)
downloadnextcloud-server-c7be18c0d6cf6a5af2251abdfa18cdccd11da33b.tar.gz
nextcloud-server-c7be18c0d6cf6a5af2251abdfa18cdccd11da33b.zip
Add a service to find out if a user knows another user
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/provisioning_api/lib/Controller/UsersController.php')
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php37
1 files changed, 14 insertions, 23 deletions
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index 648faf8ad20..d1dba3ea6ee 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -49,8 +49,7 @@ use libphonenumber\PhoneNumberUtil;
use OC\Accounts\AccountManager;
use OC\Authentication\Token\RemoteWipe;
use OC\HintException;
-use OC\KnownUser\KnownUser;
-use OC\KnownUser\KnownUserMapper;
+use OC\KnownUser\KnownUserService;
use OCA\Provisioning_API\FederatedShareProviderFactory;
use OCA\Settings\Mailer\NewUserMailHelper;
use OCP\Accounts\IAccountManager;
@@ -92,8 +91,8 @@ class UsersController extends AUserData {
private $secureRandom;
/** @var RemoteWipe */
private $remoteWipe;
- /** @var KnownUserMapper */
- private $knownUserMapper;
+ /** @var KnownUserService */
+ private $knownUserService;
/** @var IEventDispatcher */
private $eventDispatcher;
@@ -112,7 +111,7 @@ class UsersController extends AUserData {
FederatedShareProviderFactory $federatedShareProviderFactory,
ISecureRandom $secureRandom,
RemoteWipe $remoteWipe,
- KnownUserMapper $knownUserMapper,
+ KnownUserService $knownUserService,
IEventDispatcher $eventDispatcher) {
parent::__construct($appName,
$request,
@@ -131,7 +130,7 @@ class UsersController extends AUserData {
$this->federatedShareProviderFactory = $federatedShareProviderFactory;
$this->secureRandom = $secureRandom;
$this->remoteWipe = $remoteWipe;
- $this->knownUserMapper = $knownUserMapper;
+ $this->knownUserService = $knownUserService;
$this->eventDispatcher = $eventDispatcher;
}
@@ -237,6 +236,13 @@ class UsersController extends AUserData {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
+ /** @var IUser $user */
+ $user = $this->userSession->getUser();
+ $knownTo = $user->getUID();
+
+ // Cleanup all previous entries and only allow new matches
+ $this->knownUserService->deleteKnownTo($knownTo);
+
$normalizedNumberToKey = [];
foreach ($search as $key => $phoneNumbers) {
foreach ($phoneNumbers as $phone) {
@@ -271,25 +277,10 @@ class UsersController extends AUserData {
}
$matches = [];
- $knownUsers = [];
foreach ($userMatches as $phone => $userId) {
// Not using the ICloudIdManager as that would run a search for each contact to find the display name in the address book
$matches[$normalizedNumberToKey[$phone]] = $userId . '@' . $cloudUrl;
- $knownUsers[] = $userId;
- }
-
- /** @var IUser $user */
- $user = $this->userSession->getUser();
- $knownTo = $user->getUID();
-
- // Cleanup all previous entries and only allow new matches
- $this->knownUserMapper->deleteKnownTo($knownTo);
-
- foreach ($knownUsers as $knownUser) {
- $entity = new KnownUser();
- $entity->setKnownTo($knownTo);
- $entity->setKnownUser($knownUser);
- $this->knownUserMapper->insert($entity);
+ $this->knownUserService->storeIsKnownToUser($knownTo, $userId);
}
return new DataResponse($matches);
@@ -701,7 +692,7 @@ class UsersController extends AUserData {
$this->accountManager->updateUser($targetUser, $userAccount, true);
if ($key === IAccountManager::PROPERTY_PHONE) {
- $this->knownUserMapper->deleteKnownUser($targetUser->getUID());
+ $this->knownUserService->deleteKnownUser($targetUser->getUID());
}
} catch (\InvalidArgumentException $e) {
throw new OCSException('Invalid ' . $e->getMessage(), 102);