Completed
Push — master ( 04edcb...d3404c )
by
unknown
07:52
created

SettingsController::setSettings()   B

Complexity

Conditions 8
Paths 96

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
cc 8
c 0
b 0
f 0
nc 96
nop 6
dl 0
loc 46
ccs 0
cts 36
cp 0
crap 72
rs 7.9337
1
<?php
2
/**
3
 * ownCloud - Richdocuments App
4
 *
5
 * @author Victor Dubiniuk
6
 * @copyright 2014 Victor Dubiniuk [email protected]
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later.
10
 */
11
12
namespace OCA\Richdocuments\Controller;
13
14
use OCA\Richdocuments\WOPI\DiscoveryManager;
15
use \OCP\AppFramework\Controller;
16
use OCP\AppFramework\Http\JSONResponse;
17
use OCP\Files\IAppData;
18
use \OCP\IRequest;
19
use \OCP\IL10N;
20
use OCA\Richdocuments\AppConfig;
21
22
class SettingsController extends Controller{
23
	/** @var IL10N */
24
	private $l10n;
25
	/** @var AppConfig */
26
	private $appConfig;
27
	/** @var DiscoveryManager  */
28
	private $discoveryManager;
29
30
	/**
31
	 * @param string $appName
32
	 * @param IRequest $request
33
	 * @param IL10N $l10n
34
	 * @param AppConfig $appConfig
35
	 * @param DiscoveryManager $discoveryManager
36
	 */
37
	public function __construct($appName,
38
								IRequest $request,
39
								IL10N $l10n,
40
								AppConfig $appConfig,
41
								DiscoveryManager $discoveryManager) {
42
		parent::__construct($appName, $request);
43
		$this->l10n = $l10n;
44
		$this->appConfig = $appConfig;
45
		$this->discoveryManager = $discoveryManager;
46
	}
47
48
	/**
49
	 * @NoAdminRequired
50
	 *
51
	 * @return JSONResponse
52
	 */
53
	public function getSettings() {
54
		return new JSONResponse([
55
			'wopi_url' => $this->appConfig->getAppValue('wopi_url'),
56
			'edit_groups' => $this->appConfig->getAppValue('edit_groups'),
57
			'use_groups' => $this->appConfig->getAppValue('use_groups'),
58
			'doc_format' => $this->appConfig->getAppValue('doc_format'),
59
		]);
60
	}
61
62
	/**
63
	 * @param string $wopi_url
64
	 * @param string $edit_groups
65
	 * @param string $use_groups
66
	 * @param string $doc_format
67
	 * @param string $external_apps
68
	 * @param string $canonical_webroot
69
	 * @return JSONResponse
70
	 */
71
	public function setSettings($wopi_url,
72
	                            $edit_groups,
73
	                            $use_groups,
74
	                            $doc_format,
75
	                            $external_apps,
76
	                            $canonical_webroot) {
77
		$message = $this->l10n->t('Saved');
78
79
		if ($wopi_url !== null){
80
			$this->appConfig->setAppValue('wopi_url', $wopi_url);
81
82
			$colon = strpos($wopi_url, ':', 0);
83
			if ($this->request->getServerProtocol() !== substr($wopi_url, 0, $colon)){
84
				$message = $this->l10n->t('Saved with error: Collabora Online should use the same protocol as the server installation.');
85
			}
86
		}
87
88
		if ($edit_groups !== null){
89
			$this->appConfig->setAppValue('edit_groups', $edit_groups);
90
		}
91
92
		if ($use_groups !== null){
93
			$this->appConfig->setAppValue('use_groups', $use_groups);
94
		}
95
96
		if ($doc_format !== null) {
97
			$this->appConfig->setAppValue('doc_format', $doc_format);
98
		}
99
100
		if ($external_apps !== null) {
101
			$this->appConfig->setAppValue('external_apps', $external_apps);
102
		}
103
104
		if ($canonical_webroot !== null) {
105
			$this->appConfig->setAppValue('canonical_webroot', $canonical_webroot);
106
		}
107
108
		$this->discoveryManager->refretch();
109
110
		$response = [
111
			'status' => 'success',
112
			'data' => array('message' => (string) $message)
113
		];
114
115
		return new JSONResponse($response);
116
	}
117
}
118