2014-10-26 15:47:56 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2015-12-16 17:57:44 +03:00
|
|
|
* ownCloud - Richdocuments App
|
2014-10-26 15:47:56 +03:00
|
|
|
*
|
|
|
|
* @author Victor Dubiniuk
|
|
|
|
* @copyright 2014 Victor Dubiniuk victor.dubiniuk@gmail.com
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
*/
|
|
|
|
|
2015-12-16 17:57:44 +03:00
|
|
|
namespace OCA\Richdocuments\Controller;
|
2014-10-26 15:47:56 +03:00
|
|
|
|
2016-12-07 09:13:21 +01:00
|
|
|
use OCA\Richdocuments\WOPI\DiscoveryManager;
|
2014-10-26 15:47:56 +03:00
|
|
|
use \OCP\AppFramework\Controller;
|
2016-12-06 21:09:40 +01:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2016-12-07 09:13:21 +01:00
|
|
|
use OCP\Files\IAppData;
|
2014-10-26 15:47:56 +03:00
|
|
|
use \OCP\IRequest;
|
|
|
|
use \OCP\IL10N;
|
2015-12-16 17:57:44 +03:00
|
|
|
use OCA\Richdocuments\AppConfig;
|
2014-10-26 15:47:56 +03:00
|
|
|
|
|
|
|
class SettingsController extends Controller{
|
2016-12-06 21:09:40 +01:00
|
|
|
/** @var IL10N */
|
2014-10-26 15:47:56 +03:00
|
|
|
private $l10n;
|
2016-12-06 21:09:40 +01:00
|
|
|
/** @var AppConfig */
|
2015-09-18 22:10:27 +03:00
|
|
|
private $appConfig;
|
2016-12-07 09:13:21 +01:00
|
|
|
/** @var DiscoveryManager */
|
|
|
|
private $discoveryManager;
|
2016-03-05 17:40:47 -04:00
|
|
|
|
2016-12-06 21:09:40 +01:00
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
|
|
|
* @param IL10N $l10n
|
|
|
|
* @param AppConfig $appConfig
|
2016-12-07 09:13:21 +01:00
|
|
|
* @param DiscoveryManager $discoveryManager
|
2016-12-06 21:09:40 +01:00
|
|
|
*/
|
|
|
|
public function __construct($appName,
|
|
|
|
IRequest $request,
|
|
|
|
IL10N $l10n,
|
|
|
|
AppConfig $appConfig,
|
2016-12-07 09:13:21 +01:00
|
|
|
DiscoveryManager $discoveryManager) {
|
2014-10-26 15:47:56 +03:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->l10n = $l10n;
|
2015-09-18 22:10:27 +03:00
|
|
|
$this->appConfig = $appConfig;
|
2016-12-07 09:13:21 +01:00
|
|
|
$this->discoveryManager = $discoveryManager;
|
2014-10-28 18:50:58 +03:00
|
|
|
}
|
2016-03-05 17:40:47 -04:00
|
|
|
|
2017-05-19 23:45:19 +05:30
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
|
|
|
public function getSettings() {
|
|
|
|
return new JSONResponse([
|
|
|
|
'wopi_url' => $this->appConfig->getAppValue('wopi_url'),
|
2017-09-07 17:18:29 -06:00
|
|
|
'wopi_internal_url' => $this->appConfig->getAppValue('wopi_internal_url'),
|
2017-06-14 14:11:09 +02:00
|
|
|
'edit_groups' => $this->appConfig->getAppValue('edit_groups'),
|
|
|
|
'doc_format' => $this->appConfig->getAppValue('doc_format'),
|
2017-05-19 23:45:19 +05:30
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-12-06 21:09:40 +01:00
|
|
|
/**
|
|
|
|
* @param string $wopi_url
|
2017-09-07 17:18:29 -06:00
|
|
|
* @param string $wopi_internal_url
|
2017-06-14 14:11:09 +02:00
|
|
|
* @param string $edit_groups
|
2016-12-06 21:09:40 +01:00
|
|
|
* @param string $doc_format
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
|
|
|
public function setSettings($wopi_url,
|
2017-09-07 17:18:29 -06:00
|
|
|
$wopi_internal_url,
|
|
|
|
$edit_groups,
|
|
|
|
$doc_format) {
|
2016-11-01 16:32:04 +01:00
|
|
|
$message = $this->l10n->t('Saved');
|
|
|
|
|
2016-12-06 21:09:40 +01:00
|
|
|
if ($wopi_url !== null){
|
2016-03-05 17:40:47 -04:00
|
|
|
$this->appConfig->setAppValue('wopi_url', $wopi_url);
|
2016-11-01 16:32:04 +01:00
|
|
|
|
|
|
|
$colon = strpos($wopi_url, ':', 0);
|
2016-12-07 09:13:21 +01:00
|
|
|
if ($this->request->getServerProtocol() !== substr($wopi_url, 0, $colon)){
|
2016-11-01 16:32:04 +01:00
|
|
|
$message = $this->l10n->t('Saved with error: Collabora Online should use the same protocol as the server installation.');
|
|
|
|
}
|
2016-03-05 17:40:47 -04:00
|
|
|
}
|
2017-09-07 17:18:29 -06:00
|
|
|
|
|
|
|
if ($wopi_internal_url !== null){
|
|
|
|
$this->appConfig->setAppValue('wopi_internal_url', $wopi_internal_url);
|
|
|
|
}
|
2016-03-05 17:40:47 -04:00
|
|
|
|
2017-06-14 14:11:09 +02:00
|
|
|
if ($edit_groups !== null){
|
|
|
|
$this->appConfig->setAppValue('edit_groups', $edit_groups);
|
|
|
|
}
|
|
|
|
|
2016-12-06 21:09:40 +01:00
|
|
|
if ($doc_format !== null) {
|
2016-10-13 12:28:54 +05:30
|
|
|
$this->appConfig->setAppValue('doc_format', $doc_format);
|
|
|
|
}
|
|
|
|
|
2016-12-07 09:13:21 +01:00
|
|
|
$this->discoveryManager->refretch();
|
2016-03-17 10:00:46 -04:00
|
|
|
|
2016-12-07 09:13:21 +01:00
|
|
|
$response = [
|
2014-10-26 15:47:56 +03:00
|
|
|
'status' => 'success',
|
2016-11-01 16:32:04 +01:00
|
|
|
'data' => array('message' => (string) $message)
|
2016-12-07 09:13:21 +01:00
|
|
|
];
|
2016-03-05 17:40:47 -04:00
|
|
|
|
2016-12-06 21:09:40 +01:00
|
|
|
return new JSONResponse($response);
|
2014-10-26 15:47:56 +03:00
|
|
|
}
|
|
|
|
}
|