summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/KnownUser/KnownUserMapper.php13
-rw-r--r--lib/private/KnownUser/KnownUserService.php62
4 files changed, 77 insertions, 0 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index bfac8495018..fe24e817087 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -1171,6 +1171,7 @@ return array(
'OC\\IntegrityCheck\\Iterator\\ExcludeFoldersByPathFilterIterator' => $baseDir . '/lib/private/IntegrityCheck/Iterator/ExcludeFoldersByPathFilterIterator.php',
'OC\\KnownUser\\KnownUser' => $baseDir . '/lib/private/KnownUser/KnownUser.php',
'OC\\KnownUser\\KnownUserMapper' => $baseDir . '/lib/private/KnownUser/KnownUserMapper.php',
+ 'OC\\KnownUser\\KnownUserService' => $baseDir . '/lib/private/KnownUser/KnownUserService.php',
'OC\\L10N\\Factory' => $baseDir . '/lib/private/L10N/Factory.php',
'OC\\L10N\\L10N' => $baseDir . '/lib/private/L10N/L10N.php',
'OC\\L10N\\L10NString' => $baseDir . '/lib/private/L10N/L10NString.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 349b84fdcf8..1827ac55d42 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -1200,6 +1200,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\IntegrityCheck\\Iterator\\ExcludeFoldersByPathFilterIterator' => __DIR__ . '/../../..' . '/lib/private/IntegrityCheck/Iterator/ExcludeFoldersByPathFilterIterator.php',
'OC\\KnownUser\\KnownUser' => __DIR__ . '/../../..' . '/lib/private/KnownUser/KnownUser.php',
'OC\\KnownUser\\KnownUserMapper' => __DIR__ . '/../../..' . '/lib/private/KnownUser/KnownUserMapper.php',
+ 'OC\\KnownUser\\KnownUserService' => __DIR__ . '/../../..' . '/lib/private/KnownUser/KnownUserService.php',
'OC\\L10N\\Factory' => __DIR__ . '/../../..' . '/lib/private/L10N/Factory.php',
'OC\\L10N\\L10N' => __DIR__ . '/../../..' . '/lib/private/L10N/L10N.php',
'OC\\L10N\\L10NString' => __DIR__ . '/../../..' . '/lib/private/L10N/L10NString.php',
diff --git a/lib/private/KnownUser/KnownUserMapper.php b/lib/private/KnownUser/KnownUserMapper.php
index 86e13a2e2f0..1144e2fd212 100644
--- a/lib/private/KnownUser/KnownUserMapper.php
+++ b/lib/private/KnownUser/KnownUserMapper.php
@@ -62,6 +62,19 @@ class KnownUserMapper extends QBMapper {
return (int) $query->execute();
}
+ /**
+ * @param string $knownTo
+ * @return KnownUser[]
+ */
+ public function getKnownTo(string $knownTo): array {
+ $query = $this->db->getQueryBuilder();
+ $query->select('*')
+ ->from($this->getTableName())
+ ->where($query->expr()->eq('known_to', $query->createNamedParameter($knownTo)));
+
+ return $this->findEntities($query);
+ }
+
public function createKnownUserFromRow(array $row): KnownUser {
return $this->mapRowToEntity([
'id' => $row['s_id'],
diff --git a/lib/private/KnownUser/KnownUserService.php b/lib/private/KnownUser/KnownUserService.php
new file mode 100644
index 00000000000..3a97b967c3a
--- /dev/null
+++ b/lib/private/KnownUser/KnownUserService.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\KnownUser;
+
+class KnownUserService {
+ /** @var KnownUserMapper */
+ protected $mapper;
+ /** @var array */
+ protected $knownUsers = [];
+
+ public function __construct(KnownUserMapper $mapper) {
+ $this->mapper = $mapper;
+ }
+
+ public function deleteKnownTo(string $knownTo): int {
+ return $this->mapper->deleteKnownTo($knownTo);
+ }
+
+ public function deleteKnownUser(string $knownUser): int {
+ return $this->mapper->deleteKnownUser($knownUser);
+ }
+
+ public function storeIsKnownToUser(string $knownTo, string $knownUser): void {
+ $entity = new KnownUser();
+ $entity->setKnownTo($knownTo);
+ $entity->setKnownUser($knownUser);
+ $this->mapper->insert($entity);
+ }
+
+ public function isKnownToUser(string $knownTo, string $user): bool {
+ if (!isset($this->knownUsers[$knownTo])) {
+ $entities = $this->mapper->getKnownTo($knownTo);
+ $this->knownUsers[$knownTo] = [];
+ foreach ($entities as $entity) {
+ $this->knownUsers[$knownTo][$entity->getKnownUser()] = true;
+ }
+ }
+
+ return isset($this->knownUsers[$knownTo][$user]);
+ }
+}