@@ -34,132 +34,132 @@ |
||
34 | 34 | |
35 | 35 | class AppConfigController extends OCSController { |
36 | 36 | |
37 | - /** @var IConfig */ |
|
38 | - protected $config; |
|
39 | - |
|
40 | - /** @var IAppConfig */ |
|
41 | - protected $appConfig; |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $appName |
|
45 | - * @param IRequest $request |
|
46 | - * @param IConfig $config |
|
47 | - * @param IAppConfig $appConfig |
|
48 | - */ |
|
49 | - public function __construct(string $appName, |
|
50 | - IRequest $request, |
|
51 | - IConfig $config, |
|
52 | - IAppConfig $appConfig) { |
|
53 | - parent::__construct($appName, $request); |
|
54 | - $this->config = $config; |
|
55 | - $this->appConfig = $appConfig; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @return DataResponse |
|
60 | - */ |
|
61 | - public function getApps(): DataResponse { |
|
62 | - return new DataResponse([ |
|
63 | - 'data' => $this->appConfig->getApps(), |
|
64 | - ]); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @param string $app |
|
69 | - * @return DataResponse |
|
70 | - */ |
|
71 | - public function getKeys(string $app): DataResponse { |
|
72 | - try { |
|
73 | - $this->verifyAppId($app); |
|
74 | - } catch (\InvalidArgumentException $e) { |
|
75 | - return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); |
|
76 | - } |
|
77 | - return new DataResponse([ |
|
78 | - 'data' => $this->config->getAppKeys($app), |
|
79 | - ]); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $app |
|
84 | - * @param string $key |
|
85 | - * @param string $defaultValue |
|
86 | - * @return DataResponse |
|
87 | - */ |
|
88 | - public function getValue(string $app, string $key, string $defaultValue = ''): DataResponse { |
|
89 | - try { |
|
90 | - $this->verifyAppId($app); |
|
91 | - } catch (\InvalidArgumentException $e) { |
|
92 | - return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); |
|
93 | - } |
|
94 | - return new DataResponse([ |
|
95 | - 'data' => $this->config->getAppValue($app, $key, $defaultValue), |
|
96 | - ]); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @PasswordConfirmationRequired |
|
101 | - * @param string $app |
|
102 | - * @param string $key |
|
103 | - * @param string $value |
|
104 | - * @return DataResponse |
|
105 | - */ |
|
106 | - public function setValue(string $app, string $key, string $value): DataResponse { |
|
107 | - try { |
|
108 | - $this->verifyAppId($app); |
|
109 | - $this->verifyConfigKey($app, $key, $value); |
|
110 | - } catch (\InvalidArgumentException $e) { |
|
111 | - return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); |
|
112 | - } |
|
113 | - |
|
114 | - $this->config->setAppValue($app, $key, $value); |
|
115 | - return new DataResponse(); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @PasswordConfirmationRequired |
|
120 | - * @param string $app |
|
121 | - * @param string $key |
|
122 | - * @return DataResponse |
|
123 | - */ |
|
124 | - public function deleteKey(string $app, string $key): DataResponse { |
|
125 | - try { |
|
126 | - $this->verifyAppId($app); |
|
127 | - $this->verifyConfigKey($app, $key, ''); |
|
128 | - } catch (\InvalidArgumentException $e) { |
|
129 | - return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); |
|
130 | - } |
|
131 | - |
|
132 | - $this->config->deleteAppValue($app, $key); |
|
133 | - return new DataResponse(); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $app |
|
138 | - * @throws \InvalidArgumentException |
|
139 | - */ |
|
140 | - protected function verifyAppId(string $app) { |
|
141 | - if (\OC_App::cleanAppId($app) !== $app) { |
|
142 | - throw new \InvalidArgumentException('Invalid app id given'); |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @param string $app |
|
148 | - * @param string $key |
|
149 | - * @param string $value |
|
150 | - * @throws \InvalidArgumentException |
|
151 | - */ |
|
152 | - protected function verifyConfigKey(string $app, string $key, string $value) { |
|
153 | - if (in_array($key, ['installed_version', 'enabled', 'types'])) { |
|
154 | - throw new \InvalidArgumentException('The given key can not be set'); |
|
155 | - } |
|
156 | - |
|
157 | - if ($app === 'core' && $key === 'encryption_enabled' && $value !== 'yes') { |
|
158 | - throw new \InvalidArgumentException('The given key can not be set'); |
|
159 | - } |
|
160 | - |
|
161 | - if ($app === 'core' && (strpos($key, 'public_') === 0 || strpos($key, 'remote_') === 0)) { |
|
162 | - throw new \InvalidArgumentException('The given key can not be set'); |
|
163 | - } |
|
164 | - } |
|
37 | + /** @var IConfig */ |
|
38 | + protected $config; |
|
39 | + |
|
40 | + /** @var IAppConfig */ |
|
41 | + protected $appConfig; |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $appName |
|
45 | + * @param IRequest $request |
|
46 | + * @param IConfig $config |
|
47 | + * @param IAppConfig $appConfig |
|
48 | + */ |
|
49 | + public function __construct(string $appName, |
|
50 | + IRequest $request, |
|
51 | + IConfig $config, |
|
52 | + IAppConfig $appConfig) { |
|
53 | + parent::__construct($appName, $request); |
|
54 | + $this->config = $config; |
|
55 | + $this->appConfig = $appConfig; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @return DataResponse |
|
60 | + */ |
|
61 | + public function getApps(): DataResponse { |
|
62 | + return new DataResponse([ |
|
63 | + 'data' => $this->appConfig->getApps(), |
|
64 | + ]); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @param string $app |
|
69 | + * @return DataResponse |
|
70 | + */ |
|
71 | + public function getKeys(string $app): DataResponse { |
|
72 | + try { |
|
73 | + $this->verifyAppId($app); |
|
74 | + } catch (\InvalidArgumentException $e) { |
|
75 | + return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); |
|
76 | + } |
|
77 | + return new DataResponse([ |
|
78 | + 'data' => $this->config->getAppKeys($app), |
|
79 | + ]); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $app |
|
84 | + * @param string $key |
|
85 | + * @param string $defaultValue |
|
86 | + * @return DataResponse |
|
87 | + */ |
|
88 | + public function getValue(string $app, string $key, string $defaultValue = ''): DataResponse { |
|
89 | + try { |
|
90 | + $this->verifyAppId($app); |
|
91 | + } catch (\InvalidArgumentException $e) { |
|
92 | + return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); |
|
93 | + } |
|
94 | + return new DataResponse([ |
|
95 | + 'data' => $this->config->getAppValue($app, $key, $defaultValue), |
|
96 | + ]); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @PasswordConfirmationRequired |
|
101 | + * @param string $app |
|
102 | + * @param string $key |
|
103 | + * @param string $value |
|
104 | + * @return DataResponse |
|
105 | + */ |
|
106 | + public function setValue(string $app, string $key, string $value): DataResponse { |
|
107 | + try { |
|
108 | + $this->verifyAppId($app); |
|
109 | + $this->verifyConfigKey($app, $key, $value); |
|
110 | + } catch (\InvalidArgumentException $e) { |
|
111 | + return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); |
|
112 | + } |
|
113 | + |
|
114 | + $this->config->setAppValue($app, $key, $value); |
|
115 | + return new DataResponse(); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @PasswordConfirmationRequired |
|
120 | + * @param string $app |
|
121 | + * @param string $key |
|
122 | + * @return DataResponse |
|
123 | + */ |
|
124 | + public function deleteKey(string $app, string $key): DataResponse { |
|
125 | + try { |
|
126 | + $this->verifyAppId($app); |
|
127 | + $this->verifyConfigKey($app, $key, ''); |
|
128 | + } catch (\InvalidArgumentException $e) { |
|
129 | + return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); |
|
130 | + } |
|
131 | + |
|
132 | + $this->config->deleteAppValue($app, $key); |
|
133 | + return new DataResponse(); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $app |
|
138 | + * @throws \InvalidArgumentException |
|
139 | + */ |
|
140 | + protected function verifyAppId(string $app) { |
|
141 | + if (\OC_App::cleanAppId($app) !== $app) { |
|
142 | + throw new \InvalidArgumentException('Invalid app id given'); |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @param string $app |
|
148 | + * @param string $key |
|
149 | + * @param string $value |
|
150 | + * @throws \InvalidArgumentException |
|
151 | + */ |
|
152 | + protected function verifyConfigKey(string $app, string $key, string $value) { |
|
153 | + if (in_array($key, ['installed_version', 'enabled', 'types'])) { |
|
154 | + throw new \InvalidArgumentException('The given key can not be set'); |
|
155 | + } |
|
156 | + |
|
157 | + if ($app === 'core' && $key === 'encryption_enabled' && $value !== 'yes') { |
|
158 | + throw new \InvalidArgumentException('The given key can not be set'); |
|
159 | + } |
|
160 | + |
|
161 | + if ($app === 'core' && (strpos($key, 'public_') === 0 || strpos($key, 'remote_') === 0)) { |
|
162 | + throw new \InvalidArgumentException('The given key can not be set'); |
|
163 | + } |
|
164 | + } |
|
165 | 165 | } |