@@ -40,323 +40,323 @@ |
||
| 40 | 40 | |
| 41 | 41 | class Manager implements IManager { |
| 42 | 42 | |
| 43 | - /** @var ILogger */ |
|
| 44 | - private $log; |
|
| 45 | - |
|
| 46 | - /** @var IL10N */ |
|
| 47 | - private $l; |
|
| 48 | - |
|
| 49 | - /** @var IURLGenerator */ |
|
| 50 | - private $url; |
|
| 51 | - |
|
| 52 | - /** @var IServerContainer */ |
|
| 53 | - private $container; |
|
| 54 | - |
|
| 55 | - public function __construct( |
|
| 56 | - ILogger $log, |
|
| 57 | - IL10N $l10n, |
|
| 58 | - IURLGenerator $url, |
|
| 59 | - IServerContainer $container |
|
| 60 | - ) { |
|
| 61 | - $this->log = $log; |
|
| 62 | - $this->l = $l10n; |
|
| 63 | - $this->url = $url; |
|
| 64 | - $this->container = $container; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** @var array */ |
|
| 68 | - protected $sectionClasses = []; |
|
| 69 | - |
|
| 70 | - /** @var array */ |
|
| 71 | - protected $sections = []; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param string $type 'admin' or 'personal' |
|
| 75 | - * @param string $section Class must implement OCP\Settings\ISection |
|
| 76 | - * |
|
| 77 | - * @return void |
|
| 78 | - */ |
|
| 79 | - public function registerSection(string $type, string $section) { |
|
| 80 | - if (!isset($this->sectionClasses[$type])) { |
|
| 81 | - $this->sectionClasses[$type] = []; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $this->sectionClasses[$type][] = $section; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param string $type 'admin' or 'personal' |
|
| 89 | - * |
|
| 90 | - * @return ISection[] |
|
| 91 | - */ |
|
| 92 | - protected function getSections(string $type): array { |
|
| 93 | - if (!isset($this->sections[$type])) { |
|
| 94 | - $this->sections[$type] = []; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (!isset($this->sectionClasses[$type])) { |
|
| 98 | - return $this->sections[$type]; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - foreach ($this->sectionClasses[$type] as $index => $class) { |
|
| 102 | - try { |
|
| 103 | - /** @var ISection $section */ |
|
| 104 | - $section = \OC::$server->query($class); |
|
| 105 | - } catch (QueryException $e) { |
|
| 106 | - $this->log->logException($e, ['level' => ILogger::INFO]); |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if (!$section instanceof ISection) { |
|
| 111 | - $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]); |
|
| 112 | - continue; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $sectionID = $section->getID(); |
|
| 116 | - |
|
| 117 | - if (isset($this->sections[$type][$sectionID])) { |
|
| 118 | - $this->log->logException(new \InvalidArgumentException('Section with the same ID already registered'), ['level' => ILogger::INFO]); |
|
| 119 | - continue; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $this->sections[$type][$sectionID] = $section; |
|
| 123 | - |
|
| 124 | - unset($this->sectionClasses[$type][$index]); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return $this->sections[$type]; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** @var array */ |
|
| 131 | - protected $settingClasses = []; |
|
| 132 | - |
|
| 133 | - /** @var array */ |
|
| 134 | - protected $settings = []; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param string $type 'admin' or 'personal' |
|
| 138 | - * @param string $setting Class must implement OCP\Settings\ISetting |
|
| 139 | - * |
|
| 140 | - * @return void |
|
| 141 | - */ |
|
| 142 | - public function registerSetting(string $type, string $setting) { |
|
| 143 | - $this->settingClasses[$setting] = $type; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param string $type 'admin' or 'personal' |
|
| 148 | - * @param string $section |
|
| 149 | - * |
|
| 150 | - * @return ISettings[] |
|
| 151 | - */ |
|
| 152 | - protected function getSettings(string $type, string $section): array { |
|
| 153 | - if (!isset($this->settings[$type])) { |
|
| 154 | - $this->settings[$type] = []; |
|
| 155 | - } |
|
| 156 | - if (!isset($this->settings[$type][$section])) { |
|
| 157 | - $this->settings[$type][$section] = []; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - foreach ($this->settingClasses as $class => $settingsType) { |
|
| 161 | - try { |
|
| 162 | - /** @var ISettings $setting */ |
|
| 163 | - $setting = \OC::$server->query($class); |
|
| 164 | - } catch (QueryException $e) { |
|
| 165 | - $this->log->logException($e, ['level' => ILogger::INFO]); |
|
| 166 | - continue; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - if (!$setting instanceof ISettings) { |
|
| 170 | - $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')'), ['level' => ILogger::INFO]); |
|
| 171 | - continue; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - if ($setting->getSection() === null) { |
|
| 175 | - continue; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - if (!isset($this->settings[$settingsType][$setting->getSection()])) { |
|
| 179 | - $this->settings[$settingsType][$setting->getSection()] = []; |
|
| 180 | - } |
|
| 181 | - $this->settings[$settingsType][$setting->getSection()][] = $setting; |
|
| 182 | - |
|
| 183 | - unset($this->settingClasses[$class]); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - return $this->settings[$type][$section]; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @inheritdoc |
|
| 191 | - */ |
|
| 192 | - public function getAdminSections(): array { |
|
| 193 | - // built-in sections |
|
| 194 | - $sections = [ |
|
| 195 | - 0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
| 196 | - 1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 197 | - 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
| 198 | - 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 199 | - 50 => [new Section('groupware', $this->l->t('Groupware'), 0, $this->url->imagePath('core', 'places/contacts.svg'))], |
|
| 200 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 201 | - ]; |
|
| 202 | - |
|
| 203 | - $appSections = $this->getSections('admin'); |
|
| 204 | - |
|
| 205 | - foreach ($appSections as $section) { |
|
| 206 | - /** @var ISection $section */ |
|
| 207 | - if (!isset($sections[$section->getPriority()])) { |
|
| 208 | - $sections[$section->getPriority()] = []; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - $sections[$section->getPriority()][] = $section; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - ksort($sections); |
|
| 215 | - |
|
| 216 | - return $sections; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param string $section |
|
| 221 | - * |
|
| 222 | - * @return ISection[] |
|
| 223 | - */ |
|
| 224 | - private function getBuiltInAdminSettings($section): array { |
|
| 225 | - $forms = []; |
|
| 226 | - |
|
| 227 | - if ($section === 'overview') { |
|
| 228 | - /** @var ISettings $form */ |
|
| 229 | - $form = $this->container->query(Admin\Overview::class); |
|
| 230 | - $forms[$form->getPriority()] = [$form]; |
|
| 231 | - } |
|
| 232 | - if ($section === 'server') { |
|
| 233 | - /** @var ISettings $form */ |
|
| 234 | - $form = $this->container->query(Admin\Server::class); |
|
| 235 | - $forms[$form->getPriority()] = [$form]; |
|
| 236 | - $form = $this->container->query(Admin\Mail::class); |
|
| 237 | - $forms[$form->getPriority()] = [$form]; |
|
| 238 | - } |
|
| 239 | - if ($section === 'security') { |
|
| 240 | - /** @var ISettings $form */ |
|
| 241 | - $form = $this->container->query(Admin\Security::class); |
|
| 242 | - $forms[$form->getPriority()] = [$form]; |
|
| 243 | - } |
|
| 244 | - if ($section === 'sharing') { |
|
| 245 | - /** @var ISettings $form */ |
|
| 246 | - $form = $this->container->query(Admin\Sharing::class); |
|
| 247 | - $forms[$form->getPriority()] = [$form]; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return $forms; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * @param string $section |
|
| 255 | - * |
|
| 256 | - * @return ISection[] |
|
| 257 | - */ |
|
| 258 | - private function getBuiltInPersonalSettings($section): array { |
|
| 259 | - $forms = []; |
|
| 260 | - |
|
| 261 | - if ($section === 'personal-info') { |
|
| 262 | - /** @var ISettings $form */ |
|
| 263 | - $form = $this->container->query(Personal\PersonalInfo::class); |
|
| 264 | - $forms[$form->getPriority()] = [$form]; |
|
| 265 | - $form = new Personal\ServerDevNotice(); |
|
| 266 | - $forms[$form->getPriority()] = [$form]; |
|
| 267 | - } |
|
| 268 | - if ($section === 'security') { |
|
| 269 | - /** @var ISettings $form */ |
|
| 270 | - $form = $this->container->query(Personal\Security::class); |
|
| 271 | - $forms[$form->getPriority()] = [$form]; |
|
| 272 | - } |
|
| 273 | - if ($section === 'additional') { |
|
| 274 | - /** @var ISettings $form */ |
|
| 275 | - $form = $this->container->query(Personal\Additional::class); |
|
| 276 | - $forms[$form->getPriority()] = [$form]; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return $forms; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @inheritdoc |
|
| 284 | - */ |
|
| 285 | - public function getAdminSettings($section): array { |
|
| 286 | - $settings = $this->getBuiltInAdminSettings($section); |
|
| 287 | - $appSettings = $this->getSettings('admin', $section); |
|
| 288 | - |
|
| 289 | - foreach ($appSettings as $setting) { |
|
| 290 | - if (!isset($settings[$setting->getPriority()])) { |
|
| 291 | - $settings[$setting->getPriority()] = []; |
|
| 292 | - } |
|
| 293 | - $settings[$setting->getPriority()][] = $setting; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - ksort($settings); |
|
| 297 | - return $settings; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @inheritdoc |
|
| 302 | - */ |
|
| 303 | - public function getPersonalSections(): array { |
|
| 304 | - $sections = [ |
|
| 305 | - 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
| 306 | - 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
| 307 | - 15 => [new Section('sync-clients', $this->l->t('Mobile & desktop'), 0, $this->url->imagePath('core', 'clients/phone.svg'))], |
|
| 308 | - ]; |
|
| 309 | - |
|
| 310 | - $legacyForms = \OC_App::getForms('personal'); |
|
| 311 | - if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
| 312 | - $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $appSections = $this->getSections('personal'); |
|
| 316 | - |
|
| 317 | - foreach ($appSections as $section) { |
|
| 318 | - /** @var ISection $section */ |
|
| 319 | - if (!isset($sections[$section->getPriority()])) { |
|
| 320 | - $sections[$section->getPriority()] = []; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - $sections[$section->getPriority()][] = $section; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - ksort($sections); |
|
| 327 | - |
|
| 328 | - return $sections; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * @param string[] $forms |
|
| 333 | - * |
|
| 334 | - * @return bool |
|
| 335 | - */ |
|
| 336 | - private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
|
| 337 | - foreach ($forms as $form) { |
|
| 338 | - if (trim($form) !== '') { |
|
| 339 | - return true; |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - return false; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * @inheritdoc |
|
| 347 | - */ |
|
| 348 | - public function getPersonalSettings($section): array { |
|
| 349 | - $settings = $this->getBuiltInPersonalSettings($section); |
|
| 350 | - $appSettings = $this->getSettings('personal', $section); |
|
| 351 | - |
|
| 352 | - foreach ($appSettings as $setting) { |
|
| 353 | - if (!isset($settings[$setting->getPriority()])) { |
|
| 354 | - $settings[$setting->getPriority()] = []; |
|
| 355 | - } |
|
| 356 | - $settings[$setting->getPriority()][] = $setting; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - ksort($settings); |
|
| 360 | - return $settings; |
|
| 361 | - } |
|
| 43 | + /** @var ILogger */ |
|
| 44 | + private $log; |
|
| 45 | + |
|
| 46 | + /** @var IL10N */ |
|
| 47 | + private $l; |
|
| 48 | + |
|
| 49 | + /** @var IURLGenerator */ |
|
| 50 | + private $url; |
|
| 51 | + |
|
| 52 | + /** @var IServerContainer */ |
|
| 53 | + private $container; |
|
| 54 | + |
|
| 55 | + public function __construct( |
|
| 56 | + ILogger $log, |
|
| 57 | + IL10N $l10n, |
|
| 58 | + IURLGenerator $url, |
|
| 59 | + IServerContainer $container |
|
| 60 | + ) { |
|
| 61 | + $this->log = $log; |
|
| 62 | + $this->l = $l10n; |
|
| 63 | + $this->url = $url; |
|
| 64 | + $this->container = $container; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** @var array */ |
|
| 68 | + protected $sectionClasses = []; |
|
| 69 | + |
|
| 70 | + /** @var array */ |
|
| 71 | + protected $sections = []; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param string $type 'admin' or 'personal' |
|
| 75 | + * @param string $section Class must implement OCP\Settings\ISection |
|
| 76 | + * |
|
| 77 | + * @return void |
|
| 78 | + */ |
|
| 79 | + public function registerSection(string $type, string $section) { |
|
| 80 | + if (!isset($this->sectionClasses[$type])) { |
|
| 81 | + $this->sectionClasses[$type] = []; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $this->sectionClasses[$type][] = $section; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param string $type 'admin' or 'personal' |
|
| 89 | + * |
|
| 90 | + * @return ISection[] |
|
| 91 | + */ |
|
| 92 | + protected function getSections(string $type): array { |
|
| 93 | + if (!isset($this->sections[$type])) { |
|
| 94 | + $this->sections[$type] = []; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (!isset($this->sectionClasses[$type])) { |
|
| 98 | + return $this->sections[$type]; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + foreach ($this->sectionClasses[$type] as $index => $class) { |
|
| 102 | + try { |
|
| 103 | + /** @var ISection $section */ |
|
| 104 | + $section = \OC::$server->query($class); |
|
| 105 | + } catch (QueryException $e) { |
|
| 106 | + $this->log->logException($e, ['level' => ILogger::INFO]); |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if (!$section instanceof ISection) { |
|
| 111 | + $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]); |
|
| 112 | + continue; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $sectionID = $section->getID(); |
|
| 116 | + |
|
| 117 | + if (isset($this->sections[$type][$sectionID])) { |
|
| 118 | + $this->log->logException(new \InvalidArgumentException('Section with the same ID already registered'), ['level' => ILogger::INFO]); |
|
| 119 | + continue; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $this->sections[$type][$sectionID] = $section; |
|
| 123 | + |
|
| 124 | + unset($this->sectionClasses[$type][$index]); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return $this->sections[$type]; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** @var array */ |
|
| 131 | + protected $settingClasses = []; |
|
| 132 | + |
|
| 133 | + /** @var array */ |
|
| 134 | + protected $settings = []; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param string $type 'admin' or 'personal' |
|
| 138 | + * @param string $setting Class must implement OCP\Settings\ISetting |
|
| 139 | + * |
|
| 140 | + * @return void |
|
| 141 | + */ |
|
| 142 | + public function registerSetting(string $type, string $setting) { |
|
| 143 | + $this->settingClasses[$setting] = $type; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param string $type 'admin' or 'personal' |
|
| 148 | + * @param string $section |
|
| 149 | + * |
|
| 150 | + * @return ISettings[] |
|
| 151 | + */ |
|
| 152 | + protected function getSettings(string $type, string $section): array { |
|
| 153 | + if (!isset($this->settings[$type])) { |
|
| 154 | + $this->settings[$type] = []; |
|
| 155 | + } |
|
| 156 | + if (!isset($this->settings[$type][$section])) { |
|
| 157 | + $this->settings[$type][$section] = []; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + foreach ($this->settingClasses as $class => $settingsType) { |
|
| 161 | + try { |
|
| 162 | + /** @var ISettings $setting */ |
|
| 163 | + $setting = \OC::$server->query($class); |
|
| 164 | + } catch (QueryException $e) { |
|
| 165 | + $this->log->logException($e, ['level' => ILogger::INFO]); |
|
| 166 | + continue; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + if (!$setting instanceof ISettings) { |
|
| 170 | + $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')'), ['level' => ILogger::INFO]); |
|
| 171 | + continue; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + if ($setting->getSection() === null) { |
|
| 175 | + continue; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + if (!isset($this->settings[$settingsType][$setting->getSection()])) { |
|
| 179 | + $this->settings[$settingsType][$setting->getSection()] = []; |
|
| 180 | + } |
|
| 181 | + $this->settings[$settingsType][$setting->getSection()][] = $setting; |
|
| 182 | + |
|
| 183 | + unset($this->settingClasses[$class]); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + return $this->settings[$type][$section]; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @inheritdoc |
|
| 191 | + */ |
|
| 192 | + public function getAdminSections(): array { |
|
| 193 | + // built-in sections |
|
| 194 | + $sections = [ |
|
| 195 | + 0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
| 196 | + 1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 197 | + 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
| 198 | + 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 199 | + 50 => [new Section('groupware', $this->l->t('Groupware'), 0, $this->url->imagePath('core', 'places/contacts.svg'))], |
|
| 200 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 201 | + ]; |
|
| 202 | + |
|
| 203 | + $appSections = $this->getSections('admin'); |
|
| 204 | + |
|
| 205 | + foreach ($appSections as $section) { |
|
| 206 | + /** @var ISection $section */ |
|
| 207 | + if (!isset($sections[$section->getPriority()])) { |
|
| 208 | + $sections[$section->getPriority()] = []; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + $sections[$section->getPriority()][] = $section; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + ksort($sections); |
|
| 215 | + |
|
| 216 | + return $sections; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param string $section |
|
| 221 | + * |
|
| 222 | + * @return ISection[] |
|
| 223 | + */ |
|
| 224 | + private function getBuiltInAdminSettings($section): array { |
|
| 225 | + $forms = []; |
|
| 226 | + |
|
| 227 | + if ($section === 'overview') { |
|
| 228 | + /** @var ISettings $form */ |
|
| 229 | + $form = $this->container->query(Admin\Overview::class); |
|
| 230 | + $forms[$form->getPriority()] = [$form]; |
|
| 231 | + } |
|
| 232 | + if ($section === 'server') { |
|
| 233 | + /** @var ISettings $form */ |
|
| 234 | + $form = $this->container->query(Admin\Server::class); |
|
| 235 | + $forms[$form->getPriority()] = [$form]; |
|
| 236 | + $form = $this->container->query(Admin\Mail::class); |
|
| 237 | + $forms[$form->getPriority()] = [$form]; |
|
| 238 | + } |
|
| 239 | + if ($section === 'security') { |
|
| 240 | + /** @var ISettings $form */ |
|
| 241 | + $form = $this->container->query(Admin\Security::class); |
|
| 242 | + $forms[$form->getPriority()] = [$form]; |
|
| 243 | + } |
|
| 244 | + if ($section === 'sharing') { |
|
| 245 | + /** @var ISettings $form */ |
|
| 246 | + $form = $this->container->query(Admin\Sharing::class); |
|
| 247 | + $forms[$form->getPriority()] = [$form]; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $forms; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * @param string $section |
|
| 255 | + * |
|
| 256 | + * @return ISection[] |
|
| 257 | + */ |
|
| 258 | + private function getBuiltInPersonalSettings($section): array { |
|
| 259 | + $forms = []; |
|
| 260 | + |
|
| 261 | + if ($section === 'personal-info') { |
|
| 262 | + /** @var ISettings $form */ |
|
| 263 | + $form = $this->container->query(Personal\PersonalInfo::class); |
|
| 264 | + $forms[$form->getPriority()] = [$form]; |
|
| 265 | + $form = new Personal\ServerDevNotice(); |
|
| 266 | + $forms[$form->getPriority()] = [$form]; |
|
| 267 | + } |
|
| 268 | + if ($section === 'security') { |
|
| 269 | + /** @var ISettings $form */ |
|
| 270 | + $form = $this->container->query(Personal\Security::class); |
|
| 271 | + $forms[$form->getPriority()] = [$form]; |
|
| 272 | + } |
|
| 273 | + if ($section === 'additional') { |
|
| 274 | + /** @var ISettings $form */ |
|
| 275 | + $form = $this->container->query(Personal\Additional::class); |
|
| 276 | + $forms[$form->getPriority()] = [$form]; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return $forms; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * @inheritdoc |
|
| 284 | + */ |
|
| 285 | + public function getAdminSettings($section): array { |
|
| 286 | + $settings = $this->getBuiltInAdminSettings($section); |
|
| 287 | + $appSettings = $this->getSettings('admin', $section); |
|
| 288 | + |
|
| 289 | + foreach ($appSettings as $setting) { |
|
| 290 | + if (!isset($settings[$setting->getPriority()])) { |
|
| 291 | + $settings[$setting->getPriority()] = []; |
|
| 292 | + } |
|
| 293 | + $settings[$setting->getPriority()][] = $setting; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + ksort($settings); |
|
| 297 | + return $settings; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @inheritdoc |
|
| 302 | + */ |
|
| 303 | + public function getPersonalSections(): array { |
|
| 304 | + $sections = [ |
|
| 305 | + 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
| 306 | + 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
| 307 | + 15 => [new Section('sync-clients', $this->l->t('Mobile & desktop'), 0, $this->url->imagePath('core', 'clients/phone.svg'))], |
|
| 308 | + ]; |
|
| 309 | + |
|
| 310 | + $legacyForms = \OC_App::getForms('personal'); |
|
| 311 | + if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
| 312 | + $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $appSections = $this->getSections('personal'); |
|
| 316 | + |
|
| 317 | + foreach ($appSections as $section) { |
|
| 318 | + /** @var ISection $section */ |
|
| 319 | + if (!isset($sections[$section->getPriority()])) { |
|
| 320 | + $sections[$section->getPriority()] = []; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + $sections[$section->getPriority()][] = $section; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + ksort($sections); |
|
| 327 | + |
|
| 328 | + return $sections; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * @param string[] $forms |
|
| 333 | + * |
|
| 334 | + * @return bool |
|
| 335 | + */ |
|
| 336 | + private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
|
| 337 | + foreach ($forms as $form) { |
|
| 338 | + if (trim($form) !== '') { |
|
| 339 | + return true; |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * @inheritdoc |
|
| 347 | + */ |
|
| 348 | + public function getPersonalSettings($section): array { |
|
| 349 | + $settings = $this->getBuiltInPersonalSettings($section); |
|
| 350 | + $appSettings = $this->getSettings('personal', $section); |
|
| 351 | + |
|
| 352 | + foreach ($appSettings as $setting) { |
|
| 353 | + if (!isset($settings[$setting->getPriority()])) { |
|
| 354 | + $settings[$setting->getPriority()] = []; |
|
| 355 | + } |
|
| 356 | + $settings[$setting->getPriority()][] = $setting; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + ksort($settings); |
|
| 360 | + return $settings; |
|
| 361 | + } |
|
| 362 | 362 | } |
@@ -33,68 +33,68 @@ |
||
| 33 | 33 | |
| 34 | 34 | class Personal implements ISettings { |
| 35 | 35 | |
| 36 | - /** @var FederatedShareProvider */ |
|
| 37 | - private $federatedShareProvider; |
|
| 38 | - /** @var IUserSession */ |
|
| 39 | - private $userSession; |
|
| 40 | - /** @var IL10N */ |
|
| 41 | - private $l; |
|
| 42 | - /** @var \OC_Defaults */ |
|
| 43 | - private $defaults; |
|
| 36 | + /** @var FederatedShareProvider */ |
|
| 37 | + private $federatedShareProvider; |
|
| 38 | + /** @var IUserSession */ |
|
| 39 | + private $userSession; |
|
| 40 | + /** @var IL10N */ |
|
| 41 | + private $l; |
|
| 42 | + /** @var \OC_Defaults */ |
|
| 43 | + private $defaults; |
|
| 44 | 44 | |
| 45 | - public function __construct( |
|
| 46 | - FederatedShareProvider $federatedShareProvider, # |
|
| 47 | - IUserSession $userSession, |
|
| 48 | - IL10N $l, |
|
| 49 | - \OC_Defaults $defaults |
|
| 50 | - ) { |
|
| 51 | - $this->federatedShareProvider = $federatedShareProvider; |
|
| 52 | - $this->userSession = $userSession; |
|
| 53 | - $this->l = $l; |
|
| 54 | - $this->defaults = $defaults; |
|
| 55 | - } |
|
| 45 | + public function __construct( |
|
| 46 | + FederatedShareProvider $federatedShareProvider, # |
|
| 47 | + IUserSession $userSession, |
|
| 48 | + IL10N $l, |
|
| 49 | + \OC_Defaults $defaults |
|
| 50 | + ) { |
|
| 51 | + $this->federatedShareProvider = $federatedShareProvider; |
|
| 52 | + $this->userSession = $userSession; |
|
| 53 | + $this->l = $l; |
|
| 54 | + $this->defaults = $defaults; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 59 | - * @since 9.1 |
|
| 60 | - */ |
|
| 61 | - public function getForm() { |
|
| 62 | - $cloudID = $this->userSession->getUser()->getCloudId(); |
|
| 63 | - $url = 'https://nextcloud.com/sharing#' . $cloudID; |
|
| 57 | + /** |
|
| 58 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 59 | + * @since 9.1 |
|
| 60 | + */ |
|
| 61 | + public function getForm() { |
|
| 62 | + $cloudID = $this->userSession->getUser()->getCloudId(); |
|
| 63 | + $url = 'https://nextcloud.com/sharing#' . $cloudID; |
|
| 64 | 64 | |
| 65 | - $parameters = [ |
|
| 66 | - 'outgoingServer2serverShareEnabled' => $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(), |
|
| 67 | - 'message_with_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID, see %s', [$url]), |
|
| 68 | - 'message_without_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID', [$cloudID]), |
|
| 69 | - 'logoPath' => $this->defaults->getLogo(), |
|
| 70 | - 'reference' => $url, |
|
| 71 | - 'cloudId' => $cloudID, |
|
| 72 | - 'color' => $this->defaults->getColorPrimary(), |
|
| 73 | - 'textColor' => "#ffffff", |
|
| 74 | - ]; |
|
| 75 | - return new TemplateResponse('federatedfilesharing', 'settings-personal', $parameters, ''); |
|
| 76 | - } |
|
| 65 | + $parameters = [ |
|
| 66 | + 'outgoingServer2serverShareEnabled' => $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(), |
|
| 67 | + 'message_with_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID, see %s', [$url]), |
|
| 68 | + 'message_without_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID', [$cloudID]), |
|
| 69 | + 'logoPath' => $this->defaults->getLogo(), |
|
| 70 | + 'reference' => $url, |
|
| 71 | + 'cloudId' => $cloudID, |
|
| 72 | + 'color' => $this->defaults->getColorPrimary(), |
|
| 73 | + 'textColor' => "#ffffff", |
|
| 74 | + ]; |
|
| 75 | + return new TemplateResponse('federatedfilesharing', 'settings-personal', $parameters, ''); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @return string the section ID, e.g. 'sharing' |
|
| 80 | - * @since 9.1 |
|
| 81 | - */ |
|
| 82 | - public function getSection() { |
|
| 83 | - if (!$this->federatedShareProvider->isOutgoingServer2serverShareEnabled()) { |
|
| 84 | - return null; |
|
| 85 | - } |
|
| 86 | - return 'sharing'; |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * @return string the section ID, e.g. 'sharing' |
|
| 80 | + * @since 9.1 |
|
| 81 | + */ |
|
| 82 | + public function getSection() { |
|
| 83 | + if (!$this->federatedShareProvider->isOutgoingServer2serverShareEnabled()) { |
|
| 84 | + return null; |
|
| 85 | + } |
|
| 86 | + return 'sharing'; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @return int whether the form should be rather on the top or bottom of |
|
| 91 | - * the admin section. The forms are arranged in ascending order of the |
|
| 92 | - * priority values. It is required to return a value between 0 and 100. |
|
| 93 | - * |
|
| 94 | - * E.g.: 70 |
|
| 95 | - * @since 9.1 |
|
| 96 | - */ |
|
| 97 | - public function getPriority() { |
|
| 98 | - return 40; |
|
| 99 | - } |
|
| 89 | + /** |
|
| 90 | + * @return int whether the form should be rather on the top or bottom of |
|
| 91 | + * the admin section. The forms are arranged in ascending order of the |
|
| 92 | + * priority values. It is required to return a value between 0 and 100. |
|
| 93 | + * |
|
| 94 | + * E.g.: 70 |
|
| 95 | + * @since 9.1 |
|
| 96 | + */ |
|
| 97 | + public function getPriority() { |
|
| 98 | + return 40; |
|
| 99 | + } |
|
| 100 | 100 | } |