summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-11-19 21:54:26 +0100
committerJulius Härtl <jus@bitgrid.net>2018-11-19 21:54:26 +0100
commitab1c26f69c9bc8c65ac2cc4590956fb732cb2b8b (patch)
treef271cf5b70d9bd8f243b9f95dc717efa1e0c82f3 /lib
parent86e90ffef8f7ae85e3115c9a0fba887b636b8138 (diff)
Implement social app setup
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ConfigController.php61
-rw-r--r--lib/Controller/NavigationController.php18
-rw-r--r--lib/Service/ConfigService.php10
3 files changed, 86 insertions, 3 deletions
diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php
new file mode 100644
index 00000000..dc2ee989
--- /dev/null
+++ b/lib/Controller/ConfigController.php
@@ -0,0 +1,61 @@
+<?php
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @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 OCA\Social\Controller;
+
+use OCA\Activity\Data;
+use OCA\Social\Exceptions\SocialAppConfigException;
+use OCA\Social\Service\ConfigService;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\IRequest;
+
+
+class ConfigController extends Controller {
+
+ private $configService;
+
+ public function __construct(string $appName, IRequest $request, ConfigService $configService) {
+ parent::__construct($appName, $request);
+
+ $this->configService = $configService;
+ }
+
+ /**
+ * @param string $cloudAddress
+ * @return DataResponse
+ */
+ public function setCloudAddress(string $cloudAddress): DataResponse {
+ try {
+ $this->configService->setCloudAddress($cloudAddress);
+ return new DataResponse([]);
+ } catch (SocialAppConfigException $e) {
+ return new DataResponse([
+ 'message' => $e->getMessage()
+ ], Http::STATUS_BAD_REQUEST);
+ }
+ }
+} \ No newline at end of file
diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php
index e19e9ff2..c0de31ec 100644
--- a/lib/Controller/NavigationController.php
+++ b/lib/Controller/NavigationController.php
@@ -122,14 +122,24 @@ class NavigationController extends Controller {
'serverData' => [
'public' => false,
'firstrun' => false,
- 'setup' => false
+ 'setup' => false,
]
];
try {
- $this->configService->getCloudAddress();
- $data['serverData']['setup'] = true;
+ $data['serverData']['cloudAddress'] = $this->configService->getCloudAddress();
} catch (SocialAppConfigException $e) {
+ $data['serverData']['setup'] = true;
+ $data['serverData']['isAdmin'] = \OC::$server->getGroupManager()->isAdmin($this->userId);
+ if ($data['serverData']['isAdmin']) {
+ $cloudAddress = $this->request->getParam('cloudAddress');
+ if ($cloudAddress !== null) {
+ $this->configService->setCloudAddress($cloudAddress);
+ } else {
+ $data['serverData']['cliUrl'] = $this->config->getSystemValue('overwrite.cli.url', \OC::$server->getURLGenerator()->getBaseUrl());
+ return new TemplateResponse(Application::APP_NAME, 'setup', $data);
+ }
+ }
}
try {
@@ -143,6 +153,8 @@ class NavigationController extends Controller {
}
+
+
/**
* Display the navigation page of the Social app.
*
diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php
index 66e88c68..4ecaa335 100644
--- a/lib/Service/ConfigService.php
+++ b/lib/Service/ConfigService.php
@@ -210,6 +210,16 @@ class ConfigService {
return $this->config->getSystemValue($key, '');
}
+ /**
+ * @param bool $host
+ *
+ * @return string
+ * @throws SocialAppConfigException
+ */
+ public function setCloudAddress(string $cloudAddress) {
+ // TODO: Validate
+ $this->setAppValue(self::SOCIAL_ADDRESS, $cloudAddress);
+ }
/**
* @param bool $host