aboutsummaryrefslogtreecommitdiffstats
path: root/core/Db
diff options
context:
space:
mode:
Diffstat (limited to 'core/Db')
-rw-r--r--core/Db/LoginFlowV2.php27
-rw-r--r--core/Db/LoginFlowV2Mapper.php42
-rw-r--r--core/Db/ProfileConfig.php106
-rw-r--r--core/Db/ProfileConfigMapper.php34
4 files changed, 160 insertions, 49 deletions
diff --git a/core/Db/LoginFlowV2.php b/core/Db/LoginFlowV2.php
index c78150bf88b..1671e5990e0 100644
--- a/core/Db/LoginFlowV2.php
+++ b/core/Db/LoginFlowV2.php
@@ -3,30 +3,13 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OC\Core\Db;
use OCP\AppFramework\Db\Entity;
+use OCP\DB\Types;
/**
* @method int getTimestamp()
@@ -73,8 +56,8 @@ class LoginFlowV2 extends Entity {
protected $appPassword;
public function __construct() {
- $this->addType('timestamp', 'int');
- $this->addType('started', 'int');
+ $this->addType('timestamp', Types::INTEGER);
+ $this->addType('started', Types::INTEGER);
$this->addType('pollToken', 'string');
$this->addType('loginToken', 'string');
$this->addType('publicKey', 'string');
diff --git a/core/Db/LoginFlowV2Mapper.php b/core/Db/LoginFlowV2Mapper.php
index 3d072d132ef..32664917cb5 100644
--- a/core/Db/LoginFlowV2Mapper.php
+++ b/core/Db/LoginFlowV2Mapper.php
@@ -3,27 +3,9 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OC\Core\Db;
use OCP\AppFramework\Db\DoesNotExistException;
@@ -31,15 +13,21 @@ use OCP\AppFramework\Db\QBMapper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IDBConnection;
+/**
+ * @template-extends QBMapper<LoginFlowV2>
+ */
class LoginFlowV2Mapper extends QBMapper {
private const lifetime = 1200;
- /** @var ITimeFactory */
- private $timeFactory;
-
- public function __construct(IDBConnection $db, ITimeFactory $timeFactory) {
- parent::__construct($db, 'login_flow_v2', LoginFlowV2::class);
- $this->timeFactory = $timeFactory;
+ public function __construct(
+ IDBConnection $db,
+ private ITimeFactory $timeFactory,
+ ) {
+ parent::__construct(
+ $db,
+ 'login_flow_v2',
+ LoginFlowV2::class,
+ );
}
/**
@@ -83,7 +71,7 @@ class LoginFlowV2Mapper extends QBMapper {
$qb->expr()->lt('timestamp', $qb->createNamedParameter($this->timeFactory->getTime() - self::lifetime))
);
- $qb->execute();
+ $qb->executeStatement();
}
/**
diff --git a/core/Db/ProfileConfig.php b/core/Db/ProfileConfig.php
new file mode 100644
index 00000000000..226a77b7330
--- /dev/null
+++ b/core/Db/ProfileConfig.php
@@ -0,0 +1,106 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OC\Core\Db;
+
+use JsonSerializable;
+use OCP\AppFramework\Db\Entity;
+use OCP\Profile\ParameterDoesNotExistException;
+use function json_decode;
+use function json_encode;
+
+/**
+ * @method string getUserId()
+ * @method void setUserId(string $userId)
+ * @method string getConfig()
+ * @method void setConfig(string $config)
+ */
+class ProfileConfig extends Entity implements JsonSerializable {
+ /** @var string */
+ protected $userId;
+
+ /** @var string */
+ protected $config;
+
+ public function __construct() {
+ $this->addType('userId', 'string');
+ $this->addType('config', 'string');
+ }
+
+ /**
+ * Returns the config in an associative array
+ */
+ public function getConfigArray(): array {
+ return json_decode($this->config, true);
+ }
+
+ /**
+ * Set the config
+ */
+ public function setConfigArray(array $config): void {
+ $this->setConfig(json_encode($config));
+ }
+
+ /**
+ * Returns the visibility map in an associative array
+ */
+ public function getVisibilityMap(): array {
+ $config = $this->getConfigArray();
+ $visibilityMap = [];
+ foreach ($config as $paramId => $paramConfig) {
+ $visibilityMap[$paramId] = $paramConfig['visibility'];
+ }
+
+ return $visibilityMap;
+ }
+
+ /**
+ * Set the visibility map
+ */
+ public function setVisibilityMap(array $visibilityMap): void {
+ $config = $this->getConfigArray();
+ foreach ($visibilityMap as $paramId => $visibility) {
+ $config[$paramId] = array_merge(
+ $config[$paramId] ?: [],
+ ['visibility' => $visibility],
+ );
+ }
+
+ $this->setConfigArray($config);
+ }
+
+ /**
+ * Returns the visibility of the parameter
+ *
+ * @throws ParameterDoesNotExistException
+ */
+ public function getVisibility(string $paramId): string {
+ $visibilityMap = $this->getVisibilityMap();
+ if (isset($visibilityMap[$paramId])) {
+ return $visibilityMap[$paramId];
+ }
+ throw new ParameterDoesNotExistException($paramId);
+ }
+
+ /**
+ * Set the visibility of the parameter
+ */
+ public function setVisibility(string $paramId, string $visibility): void {
+ $visibilityMap = $this->getVisibilityMap();
+ $visibilityMap[$paramId] = $visibility;
+ $this->setVisibilityMap($visibilityMap);
+ }
+
+ public function jsonSerialize(): array {
+ return [
+ 'userId' => $this->userId,
+ 'config' => $this->getConfigArray(),
+ ];
+ }
+}
diff --git a/core/Db/ProfileConfigMapper.php b/core/Db/ProfileConfigMapper.php
new file mode 100644
index 00000000000..26e3d2da19f
--- /dev/null
+++ b/core/Db/ProfileConfigMapper.php
@@ -0,0 +1,34 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OC\Core\Db;
+
+use OCP\AppFramework\Db\QBMapper;
+use OCP\IDBConnection;
+
+/**
+ * @template-extends QBMapper<ProfileConfig>
+ */
+class ProfileConfigMapper extends QBMapper {
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'profile_config', ProfileConfig::class);
+ }
+
+ public function get(string $userId): ProfileConfig {
+ $qb = $this->db->getQueryBuilder();
+ $qb->select('*')
+ ->from($this->getTableName())
+ ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
+ return $this->findEntity($qb);
+ }
+
+ public function getArray(string $userId): array {
+ return $this->get($userId)->getConfigArray();
+ }
+}