summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-03-09 20:32:08 +0100
committerJoas Schilling <coding@schilljs.com>2021-03-10 15:05:48 +0100
commitf62d9b50fda96fe2acd6ebb2eb11e1f6bcf54116 (patch)
tree8c19b3d2cc6ee12ec81b7f163ed9e6d357b8abb5 /apps/provisioning_api
parentf1bb4e56991f2842dafab729258ad2ab7a53e1f1 (diff)
downloadnextcloud-server-f62d9b50fda96fe2acd6ebb2eb11e1f6bcf54116.tar.gz
nextcloud-server-f62d9b50fda96fe2acd6ebb2eb11e1f6bcf54116.zip
Store when a user knows another user based on phone number
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index 11c3a85db9b..9cc8372daa4 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -49,6 +49,8 @@ use libphonenumber\PhoneNumberUtil;
use OC\Accounts\AccountManager;
use OC\Authentication\Token\RemoteWipe;
use OC\HintException;
+use OC\KnownUser\KnownUser;
+use OC\KnownUser\KnownUserMapper;
use OCA\Provisioning_API\FederatedShareProviderFactory;
use OCA\Settings\Mailer\NewUserMailHelper;
use OCP\Accounts\IAccountManager;
@@ -90,6 +92,8 @@ class UsersController extends AUserData {
private $secureRandom;
/** @var RemoteWipe */
private $remoteWipe;
+ /** @var KnownUserMapper */
+ private $knownUserMapper;
/** @var IEventDispatcher */
private $eventDispatcher;
@@ -108,6 +112,7 @@ class UsersController extends AUserData {
FederatedShareProviderFactory $federatedShareProviderFactory,
ISecureRandom $secureRandom,
RemoteWipe $remoteWipe,
+ KnownUserMapper $knownUserMapper,
IEventDispatcher $eventDispatcher) {
parent::__construct($appName,
$request,
@@ -126,6 +131,7 @@ class UsersController extends AUserData {
$this->federatedShareProviderFactory = $federatedShareProviderFactory;
$this->secureRandom = $secureRandom;
$this->remoteWipe = $remoteWipe;
+ $this->knownUserMapper = $knownUserMapper;
$this->eventDispatcher = $eventDispatcher;
}
@@ -265,9 +271,25 @@ 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);
}
return new DataResponse($matches);