@@ -34,121 +34,121 @@ |
||
34 | 34 | |
35 | 35 | class ConfigController extends OCSController { |
36 | 36 | |
37 | - /** @var string */ |
|
38 | - protected $appName; |
|
39 | - |
|
40 | - /** @var string */ |
|
41 | - protected $userId; |
|
42 | - |
|
43 | - /** @var string */ |
|
44 | - protected $serverRoot; |
|
45 | - |
|
46 | - /** @var IConfig */ |
|
47 | - private $config; |
|
48 | - |
|
49 | - /** @var IUserSession */ |
|
50 | - private $userSession; |
|
51 | - |
|
52 | - /** @var AccessibilityProvider */ |
|
53 | - private $accessibilityProvider; |
|
54 | - |
|
55 | - /** |
|
56 | - * Config constructor. |
|
57 | - * |
|
58 | - * @param string $appName |
|
59 | - * @param IRequest $request |
|
60 | - * @param IConfig $config |
|
61 | - * @param IUserSession $userSession |
|
62 | - * @param AccessibilityProvider $accessibilityProvider |
|
63 | - */ |
|
64 | - public function __construct(string $appName, |
|
65 | - IRequest $request, |
|
66 | - IConfig $config, |
|
67 | - IUserSession $userSession, |
|
68 | - AccessibilityProvider $accessibilityProvider) { |
|
69 | - parent::__construct($appName, $request); |
|
70 | - $this->appName = $appName; |
|
71 | - $this->config = $config; |
|
72 | - $this->userSession = $userSession; |
|
73 | - $this->accessibilityProvider = $accessibilityProvider; |
|
74 | - $this->userId = $userSession->getUser()->getUID(); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * @NoAdminRequired |
|
79 | - * |
|
80 | - * Get user accessibility config |
|
81 | - * |
|
82 | - * @param string $key theme or font |
|
83 | - * @return DataResponse |
|
84 | - */ |
|
85 | - public function getConfig(): DataResponse { |
|
86 | - return new DataResponse([ |
|
87 | - 'highcontrast' => $this->config->getUserValue($this->userId, $this->appName, 'highcontrast', false), |
|
88 | - 'theme' => $this->config->getUserValue($this->userId, $this->appName, 'theme', false), |
|
89 | - 'font' => $this->config->getUserValue($this->userId, $this->appName, 'font', false) |
|
90 | - ]); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @NoAdminRequired |
|
95 | - * |
|
96 | - * Set theme or font config |
|
97 | - * |
|
98 | - * @param string $key theme or font |
|
99 | - * @return DataResponse |
|
100 | - * @throws Exception |
|
101 | - */ |
|
102 | - public function setConfig(string $key, $value): DataResponse { |
|
103 | - if ($key === 'theme' || $key === 'font' || $key === 'highcontrast') { |
|
104 | - |
|
105 | - if ($value === false || $value === '') { |
|
106 | - throw new OCSBadRequestException('Invalid value: ' . $value); |
|
107 | - } |
|
108 | - |
|
109 | - $themes = $this->accessibilityProvider->getThemes(); |
|
110 | - $highcontrast = array($this->accessibilityProvider->getHighContrast()); |
|
111 | - $fonts = $this->accessibilityProvider->getFonts(); |
|
112 | - |
|
113 | - $availableOptions = array_map(function($option) { |
|
114 | - return $option['id']; |
|
115 | - }, array_merge($themes, $highcontrast, $fonts)); |
|
116 | - |
|
117 | - if (in_array($value, $availableOptions)) { |
|
118 | - $this->config->setUserValue($this->userId, $this->appName, $key, $value); |
|
119 | - return new DataResponse(); |
|
120 | - } |
|
121 | - |
|
122 | - throw new OCSBadRequestException('Invalid value: ' . $value); |
|
123 | - } |
|
124 | - |
|
125 | - throw new OCSBadRequestException('Invalid key: ' . $key); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @NoAdminRequired |
|
130 | - * |
|
131 | - * Unset theme or font config |
|
132 | - * |
|
133 | - * @param string $key theme or font |
|
134 | - * @return DataResponse |
|
135 | - * @throws Exception |
|
136 | - */ |
|
137 | - public function deleteConfig(string $key): DataResponse { |
|
138 | - if ($key === 'theme' || $key === 'font' || $key === 'highcontrast') { |
|
139 | - |
|
140 | - $this->config->deleteUserValue($this->userId, $this->appName, $key); |
|
141 | - $userValues = $this->config->getUserKeys($this->userId, $this->appName); |
|
142 | - |
|
143 | - // remove hash if no settings selected |
|
144 | - if (count($userValues) === 1 && $userValues[0] === 'icons-css') { |
|
145 | - $this->config->deleteUserValue($this->userId, $this->appName, 'icons-css'); |
|
146 | - } |
|
147 | - |
|
148 | - return new DataResponse(); |
|
149 | - } |
|
150 | - |
|
151 | - throw new OCSBadRequestException('Invalid key: ' . $key); |
|
152 | - } |
|
37 | + /** @var string */ |
|
38 | + protected $appName; |
|
39 | + |
|
40 | + /** @var string */ |
|
41 | + protected $userId; |
|
42 | + |
|
43 | + /** @var string */ |
|
44 | + protected $serverRoot; |
|
45 | + |
|
46 | + /** @var IConfig */ |
|
47 | + private $config; |
|
48 | + |
|
49 | + /** @var IUserSession */ |
|
50 | + private $userSession; |
|
51 | + |
|
52 | + /** @var AccessibilityProvider */ |
|
53 | + private $accessibilityProvider; |
|
54 | + |
|
55 | + /** |
|
56 | + * Config constructor. |
|
57 | + * |
|
58 | + * @param string $appName |
|
59 | + * @param IRequest $request |
|
60 | + * @param IConfig $config |
|
61 | + * @param IUserSession $userSession |
|
62 | + * @param AccessibilityProvider $accessibilityProvider |
|
63 | + */ |
|
64 | + public function __construct(string $appName, |
|
65 | + IRequest $request, |
|
66 | + IConfig $config, |
|
67 | + IUserSession $userSession, |
|
68 | + AccessibilityProvider $accessibilityProvider) { |
|
69 | + parent::__construct($appName, $request); |
|
70 | + $this->appName = $appName; |
|
71 | + $this->config = $config; |
|
72 | + $this->userSession = $userSession; |
|
73 | + $this->accessibilityProvider = $accessibilityProvider; |
|
74 | + $this->userId = $userSession->getUser()->getUID(); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * @NoAdminRequired |
|
79 | + * |
|
80 | + * Get user accessibility config |
|
81 | + * |
|
82 | + * @param string $key theme or font |
|
83 | + * @return DataResponse |
|
84 | + */ |
|
85 | + public function getConfig(): DataResponse { |
|
86 | + return new DataResponse([ |
|
87 | + 'highcontrast' => $this->config->getUserValue($this->userId, $this->appName, 'highcontrast', false), |
|
88 | + 'theme' => $this->config->getUserValue($this->userId, $this->appName, 'theme', false), |
|
89 | + 'font' => $this->config->getUserValue($this->userId, $this->appName, 'font', false) |
|
90 | + ]); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @NoAdminRequired |
|
95 | + * |
|
96 | + * Set theme or font config |
|
97 | + * |
|
98 | + * @param string $key theme or font |
|
99 | + * @return DataResponse |
|
100 | + * @throws Exception |
|
101 | + */ |
|
102 | + public function setConfig(string $key, $value): DataResponse { |
|
103 | + if ($key === 'theme' || $key === 'font' || $key === 'highcontrast') { |
|
104 | + |
|
105 | + if ($value === false || $value === '') { |
|
106 | + throw new OCSBadRequestException('Invalid value: ' . $value); |
|
107 | + } |
|
108 | + |
|
109 | + $themes = $this->accessibilityProvider->getThemes(); |
|
110 | + $highcontrast = array($this->accessibilityProvider->getHighContrast()); |
|
111 | + $fonts = $this->accessibilityProvider->getFonts(); |
|
112 | + |
|
113 | + $availableOptions = array_map(function($option) { |
|
114 | + return $option['id']; |
|
115 | + }, array_merge($themes, $highcontrast, $fonts)); |
|
116 | + |
|
117 | + if (in_array($value, $availableOptions)) { |
|
118 | + $this->config->setUserValue($this->userId, $this->appName, $key, $value); |
|
119 | + return new DataResponse(); |
|
120 | + } |
|
121 | + |
|
122 | + throw new OCSBadRequestException('Invalid value: ' . $value); |
|
123 | + } |
|
124 | + |
|
125 | + throw new OCSBadRequestException('Invalid key: ' . $key); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @NoAdminRequired |
|
130 | + * |
|
131 | + * Unset theme or font config |
|
132 | + * |
|
133 | + * @param string $key theme or font |
|
134 | + * @return DataResponse |
|
135 | + * @throws Exception |
|
136 | + */ |
|
137 | + public function deleteConfig(string $key): DataResponse { |
|
138 | + if ($key === 'theme' || $key === 'font' || $key === 'highcontrast') { |
|
139 | + |
|
140 | + $this->config->deleteUserValue($this->userId, $this->appName, $key); |
|
141 | + $userValues = $this->config->getUserKeys($this->userId, $this->appName); |
|
142 | + |
|
143 | + // remove hash if no settings selected |
|
144 | + if (count($userValues) === 1 && $userValues[0] === 'icons-css') { |
|
145 | + $this->config->deleteUserValue($this->userId, $this->appName, 'icons-css'); |
|
146 | + } |
|
147 | + |
|
148 | + return new DataResponse(); |
|
149 | + } |
|
150 | + |
|
151 | + throw new OCSBadRequestException('Invalid key: ' . $key); |
|
152 | + } |
|
153 | 153 | |
154 | 154 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare (strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | /** |
4 | 4 | * @copyright Copyright (c) 2018 John Molakvoæ (skjnldsv) <[email protected]> |
5 | 5 | * @copyright Copyright (c) 2019 Janis Köhr <[email protected]> |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $this->config = $config; |
72 | 72 | $this->userSession = $userSession; |
73 | 73 | $this->accessibilityProvider = $accessibilityProvider; |
74 | - $this->userId = $userSession->getUser()->getUID(); |
|
74 | + $this->userId = $userSession->getUser()->getUID(); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | if ($key === 'theme' || $key === 'font' || $key === 'highcontrast') { |
104 | 104 | |
105 | 105 | if ($value === false || $value === '') { |
106 | - throw new OCSBadRequestException('Invalid value: ' . $value); |
|
106 | + throw new OCSBadRequestException('Invalid value: '.$value); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | $themes = $this->accessibilityProvider->getThemes(); |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | return new DataResponse(); |
120 | 120 | } |
121 | 121 | |
122 | - throw new OCSBadRequestException('Invalid value: ' . $value); |
|
122 | + throw new OCSBadRequestException('Invalid value: '.$value); |
|
123 | 123 | } |
124 | 124 | |
125 | - throw new OCSBadRequestException('Invalid key: ' . $key); |
|
125 | + throw new OCSBadRequestException('Invalid key: '.$key); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | return new DataResponse(); |
149 | 149 | } |
150 | 150 | |
151 | - throw new OCSBadRequestException('Invalid key: ' . $key); |
|
151 | + throw new OCSBadRequestException('Invalid key: '.$key); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | } |
@@ -36,96 +36,96 @@ |
||
36 | 36 | |
37 | 37 | class Personal implements ISettings { |
38 | 38 | |
39 | - /** @var string */ |
|
40 | - protected $appName; |
|
41 | - |
|
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
44 | - |
|
45 | - /** @var IUserSession */ |
|
46 | - private $userSession; |
|
47 | - |
|
48 | - /** @var IL10N */ |
|
49 | - private $l; |
|
50 | - |
|
51 | - /** @var IURLGenerator */ |
|
52 | - private $urlGenerator; |
|
53 | - |
|
54 | - /** @var AccessibilityProvider */ |
|
55 | - private $accessibilityProvider; |
|
56 | - |
|
57 | - /** @var IInitialStateService */ |
|
58 | - private $initialStateService; |
|
59 | - |
|
60 | - /** |
|
61 | - * Settings constructor. |
|
62 | - * |
|
63 | - * @param string $appName |
|
64 | - * @param IConfig $config |
|
65 | - * @param IUserSession $userSession |
|
66 | - * @param IL10N $l |
|
67 | - * @param IURLGenerator $urlGenerator |
|
68 | - * @param AccessibilityProvider $accessibilityProvider |
|
69 | - */ |
|
70 | - public function __construct(string $appName, |
|
71 | - IConfig $config, |
|
72 | - IUserSession $userSession, |
|
73 | - IL10N $l, |
|
74 | - IURLGenerator $urlGenerator, |
|
75 | - AccessibilityProvider $accessibilityProvider, |
|
76 | - IInitialStateService $initialStateService) { |
|
77 | - $this->appName = $appName; |
|
78 | - $this->config = $config; |
|
79 | - $this->userSession = $userSession; |
|
80 | - $this->l = $l; |
|
81 | - $this->urlGenerator = $urlGenerator; |
|
82 | - $this->accessibilityProvider = $accessibilityProvider; |
|
83 | - $this->initialStateService = $initialStateService; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
88 | - * @since 9.1 |
|
89 | - */ |
|
90 | - public function getForm() { |
|
91 | - Util::addScript('accessibility', 'accessibility'); |
|
92 | - Util::addStyle('accessibility', 'style'); |
|
93 | - |
|
94 | - $availableConfig = [ |
|
95 | - 'themes' => $this->accessibilityProvider->getThemes(), |
|
96 | - 'fonts' => $this->accessibilityProvider->getFonts(), |
|
97 | - 'highcontrast' => $this->accessibilityProvider->getHighContrast() |
|
98 | - ]; |
|
99 | - |
|
100 | - $userConfig = [ |
|
101 | - 'highcontrast' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'highcontrast', false), |
|
102 | - 'theme' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false), |
|
103 | - 'font' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false) |
|
104 | - ]; |
|
105 | - |
|
106 | - $this->initialStateService->provideInitialState($this->appName, 'available-config', $availableConfig); |
|
107 | - $this->initialStateService->provideInitialState($this->appName, 'user-config', $userConfig); |
|
108 | - |
|
109 | - return new TemplateResponse($this->appName, 'settings-personal'); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @return string the section ID, e.g. 'sharing' |
|
114 | - * @since 9.1 |
|
115 | - */ |
|
116 | - public function getSection() { |
|
117 | - return $this->appName; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return int whether the form should be rather on the top or bottom of |
|
122 | - * the admin section. The forms are arranged in ascending order of the |
|
123 | - * priority values. It is required to return a value between 0 and 100. |
|
124 | - * |
|
125 | - * E.g.: 70 |
|
126 | - * @since 9.1 |
|
127 | - */ |
|
128 | - public function getPriority() { |
|
129 | - return 40; |
|
130 | - } |
|
39 | + /** @var string */ |
|
40 | + protected $appName; |
|
41 | + |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | + |
|
45 | + /** @var IUserSession */ |
|
46 | + private $userSession; |
|
47 | + |
|
48 | + /** @var IL10N */ |
|
49 | + private $l; |
|
50 | + |
|
51 | + /** @var IURLGenerator */ |
|
52 | + private $urlGenerator; |
|
53 | + |
|
54 | + /** @var AccessibilityProvider */ |
|
55 | + private $accessibilityProvider; |
|
56 | + |
|
57 | + /** @var IInitialStateService */ |
|
58 | + private $initialStateService; |
|
59 | + |
|
60 | + /** |
|
61 | + * Settings constructor. |
|
62 | + * |
|
63 | + * @param string $appName |
|
64 | + * @param IConfig $config |
|
65 | + * @param IUserSession $userSession |
|
66 | + * @param IL10N $l |
|
67 | + * @param IURLGenerator $urlGenerator |
|
68 | + * @param AccessibilityProvider $accessibilityProvider |
|
69 | + */ |
|
70 | + public function __construct(string $appName, |
|
71 | + IConfig $config, |
|
72 | + IUserSession $userSession, |
|
73 | + IL10N $l, |
|
74 | + IURLGenerator $urlGenerator, |
|
75 | + AccessibilityProvider $accessibilityProvider, |
|
76 | + IInitialStateService $initialStateService) { |
|
77 | + $this->appName = $appName; |
|
78 | + $this->config = $config; |
|
79 | + $this->userSession = $userSession; |
|
80 | + $this->l = $l; |
|
81 | + $this->urlGenerator = $urlGenerator; |
|
82 | + $this->accessibilityProvider = $accessibilityProvider; |
|
83 | + $this->initialStateService = $initialStateService; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
88 | + * @since 9.1 |
|
89 | + */ |
|
90 | + public function getForm() { |
|
91 | + Util::addScript('accessibility', 'accessibility'); |
|
92 | + Util::addStyle('accessibility', 'style'); |
|
93 | + |
|
94 | + $availableConfig = [ |
|
95 | + 'themes' => $this->accessibilityProvider->getThemes(), |
|
96 | + 'fonts' => $this->accessibilityProvider->getFonts(), |
|
97 | + 'highcontrast' => $this->accessibilityProvider->getHighContrast() |
|
98 | + ]; |
|
99 | + |
|
100 | + $userConfig = [ |
|
101 | + 'highcontrast' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'highcontrast', false), |
|
102 | + 'theme' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false), |
|
103 | + 'font' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false) |
|
104 | + ]; |
|
105 | + |
|
106 | + $this->initialStateService->provideInitialState($this->appName, 'available-config', $availableConfig); |
|
107 | + $this->initialStateService->provideInitialState($this->appName, 'user-config', $userConfig); |
|
108 | + |
|
109 | + return new TemplateResponse($this->appName, 'settings-personal'); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @return string the section ID, e.g. 'sharing' |
|
114 | + * @since 9.1 |
|
115 | + */ |
|
116 | + public function getSection() { |
|
117 | + return $this->appName; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return int whether the form should be rather on the top or bottom of |
|
122 | + * the admin section. The forms are arranged in ascending order of the |
|
123 | + * priority values. It is required to return a value between 0 and 100. |
|
124 | + * |
|
125 | + * E.g.: 70 |
|
126 | + * @since 9.1 |
|
127 | + */ |
|
128 | + public function getPriority() { |
|
129 | + return 40; |
|
130 | + } |
|
131 | 131 | } |
@@ -22,25 +22,25 @@ |
||
22 | 22 | */ |
23 | 23 | |
24 | 24 | return [ |
25 | - 'routes' => [ |
|
26 | - ['name' => 'accessibility#getCss', 'url' => '/css/user-{md5}', 'verb' => 'GET'], |
|
27 | - ['name' => 'accessibility#getJavascript', 'url' => '/js/accessibility', 'verb' => 'GET'], |
|
25 | + 'routes' => [ |
|
26 | + ['name' => 'accessibility#getCss', 'url' => '/css/user-{md5}', 'verb' => 'GET'], |
|
27 | + ['name' => 'accessibility#getJavascript', 'url' => '/js/accessibility', 'verb' => 'GET'], |
|
28 | 28 | ], |
29 | 29 | 'ocs' => [ |
30 | - [ |
|
31 | - 'name' => 'Config#getConfig', |
|
32 | - 'url' => '/api/v1/config', |
|
33 | - 'verb' => 'GET', |
|
30 | + [ |
|
31 | + 'name' => 'Config#getConfig', |
|
32 | + 'url' => '/api/v1/config', |
|
33 | + 'verb' => 'GET', |
|
34 | + ], |
|
35 | + [ |
|
36 | + 'name' => 'Config#setConfig', |
|
37 | + 'url' => '/api/v1/config/{key}', |
|
38 | + 'verb' => 'PUT', |
|
39 | + ], |
|
40 | + [ |
|
41 | + 'name' => 'Config#deleteConfig', |
|
42 | + 'url' => '/api/v1/config/{key}', |
|
43 | + 'verb' => 'DELETE', |
|
34 | 44 | ], |
35 | - [ |
|
36 | - 'name' => 'Config#setConfig', |
|
37 | - 'url' => '/api/v1/config/{key}', |
|
38 | - 'verb' => 'PUT', |
|
39 | - ], |
|
40 | - [ |
|
41 | - 'name' => 'Config#deleteConfig', |
|
42 | - 'url' => '/api/v1/config/{key}', |
|
43 | - 'verb' => 'DELETE', |
|
44 | - ], |
|
45 | 45 | ] |
46 | 46 | ]; |