Completed
Pull Request — master (#4890)
by Blizzz
22:36
created
settings/Controller/CommonSettingsTrait.php 1 patch
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -29,95 +29,95 @@
 block discarded – undo
29 29
 use OCP\Settings\ISettings;
30 30
 
31 31
 trait CommonSettingsTrait  {
32
-	/** @var ISettingsManager */
33
-	private $settingsManager;
34
-
35
-	/**
36
-	 * @param string $currentSection
37
-	 * @return array
38
-	 */
39
-	private function getNavigationParameters($currentSection) {
40
-		$templateParameters = [
41
-			'personal' => $this->formatPersonalSections($currentSection),
42
-			'admin' => []
43
-		];
44
-
45
-		if(\OC_User::isAdminUser(\OC_User::getUser())) {
46
-			$templateParameters['admin'] = $this->formatAdminSections($currentSection);
47
-		}
48
-
49
-		return [
50
-			'forms' => $templateParameters
51
-		];
52
-	}
53
-
54
-	protected function formatSections($sections, $currentSection, $type) {
55
-		$templateParameters = [];
56
-		/** @var \OCP\Settings\ISection[] $prioritizedSections */
57
-		foreach($sections as $prioritizedSections) {
58
-			foreach ($prioritizedSections as $section) {
59
-				if($type === 'admin') {
60
-					$settings = $this->settingsManager->getAdminSettings($section->getID());
61
-				} else if($type === 'personal') {
62
-					$settings = $this->settingsManager->getPersonalSettings($section->getID());
63
-				}
64
-				if (empty($settings)) {
65
-					continue;
66
-				}
67
-
68
-				$icon = '';
69
-				if ($section instanceof IIconSection) {
70
-					$icon = $section->getIcon();
71
-				}
72
-
73
-				$templateParameters[] = [
74
-					'anchor'       => $section->getID(),
75
-					'section-name' => $section->getName(),
76
-					'active'       => $section->getID() === $currentSection,
77
-					'icon'         => $icon,
78
-				];
79
-			}
80
-		}
81
-		return $templateParameters;
82
-	}
83
-
84
-	protected function formatPersonalSections($currentSections) {
85
-		$sections = $this->settingsManager->getPersonalSections();
86
-		$templateParameters = $this->formatSections($sections, $currentSections, 'personal');
87
-
88
-		return $templateParameters;
89
-	}
90
-
91
-	protected function formatAdminSections($currentSections) {
92
-		$sections = $this->settingsManager->getAdminSections();
93
-		$templateParameters = $this->formatSections($sections, $currentSections, 'admin');
94
-
95
-		return $templateParameters;
96
-	}
97
-
98
-	/**
99
-	 * @param ISettings[] $settings
100
-	 * @return array
101
-	 */
102
-	private function formatSettings($settings) {
103
-		$html = '';
104
-		foreach ($settings as $prioritizedSettings) {
105
-			foreach ($prioritizedSettings as $setting) {
106
-				/** @var \OCP\Settings\ISettings $setting */
107
-				$form = $setting->getForm();
108
-				$html .= $form->renderAs('')->render();
109
-			}
110
-		}
111
-		return ['content' => $html];
112
-	}
113
-
114
-	private function getIndexResponse($section) {
115
-		$templateParams = [];
116
-		$templateParams = array_merge($templateParams, $this->getNavigationParameters($section));
117
-		$templateParams = array_merge($templateParams, $this->getSettings($section));
118
-
119
-		return new TemplateResponse('settings', 'settings/frame', $templateParams);
120
-	}
121
-
122
-	abstract protected function getSettings($section);
32
+    /** @var ISettingsManager */
33
+    private $settingsManager;
34
+
35
+    /**
36
+     * @param string $currentSection
37
+     * @return array
38
+     */
39
+    private function getNavigationParameters($currentSection) {
40
+        $templateParameters = [
41
+            'personal' => $this->formatPersonalSections($currentSection),
42
+            'admin' => []
43
+        ];
44
+
45
+        if(\OC_User::isAdminUser(\OC_User::getUser())) {
46
+            $templateParameters['admin'] = $this->formatAdminSections($currentSection);
47
+        }
48
+
49
+        return [
50
+            'forms' => $templateParameters
51
+        ];
52
+    }
53
+
54
+    protected function formatSections($sections, $currentSection, $type) {
55
+        $templateParameters = [];
56
+        /** @var \OCP\Settings\ISection[] $prioritizedSections */
57
+        foreach($sections as $prioritizedSections) {
58
+            foreach ($prioritizedSections as $section) {
59
+                if($type === 'admin') {
60
+                    $settings = $this->settingsManager->getAdminSettings($section->getID());
61
+                } else if($type === 'personal') {
62
+                    $settings = $this->settingsManager->getPersonalSettings($section->getID());
63
+                }
64
+                if (empty($settings)) {
65
+                    continue;
66
+                }
67
+
68
+                $icon = '';
69
+                if ($section instanceof IIconSection) {
70
+                    $icon = $section->getIcon();
71
+                }
72
+
73
+                $templateParameters[] = [
74
+                    'anchor'       => $section->getID(),
75
+                    'section-name' => $section->getName(),
76
+                    'active'       => $section->getID() === $currentSection,
77
+                    'icon'         => $icon,
78
+                ];
79
+            }
80
+        }
81
+        return $templateParameters;
82
+    }
83
+
84
+    protected function formatPersonalSections($currentSections) {
85
+        $sections = $this->settingsManager->getPersonalSections();
86
+        $templateParameters = $this->formatSections($sections, $currentSections, 'personal');
87
+
88
+        return $templateParameters;
89
+    }
90
+
91
+    protected function formatAdminSections($currentSections) {
92
+        $sections = $this->settingsManager->getAdminSections();
93
+        $templateParameters = $this->formatSections($sections, $currentSections, 'admin');
94
+
95
+        return $templateParameters;
96
+    }
97
+
98
+    /**
99
+     * @param ISettings[] $settings
100
+     * @return array
101
+     */
102
+    private function formatSettings($settings) {
103
+        $html = '';
104
+        foreach ($settings as $prioritizedSettings) {
105
+            foreach ($prioritizedSettings as $setting) {
106
+                /** @var \OCP\Settings\ISettings $setting */
107
+                $form = $setting->getForm();
108
+                $html .= $form->renderAs('')->render();
109
+            }
110
+        }
111
+        return ['content' => $html];
112
+    }
113
+
114
+    private function getIndexResponse($section) {
115
+        $templateParams = [];
116
+        $templateParams = array_merge($templateParams, $this->getNavigationParameters($section));
117
+        $templateParams = array_merge($templateParams, $this->getSettings($section));
118
+
119
+        return new TemplateResponse('settings', 'settings/frame', $templateParams);
120
+    }
121
+
122
+    abstract protected function getSettings($section);
123 123
 }
Please login to merge, or discard this patch.
apps/files_external/lib/AppInfo/Application.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -41,89 +41,89 @@
 block discarded – undo
41 41
  */
42 42
 class Application extends App implements IBackendProvider, IAuthMechanismProvider {
43 43
 
44
-	public function __construct(array $urlParams = array()) {
45
-		parent::__construct('files_external', $urlParams);
46
-
47
-		$container = $this->getContainer();
48
-
49
-		$container->registerService('OCP\Files\Config\IUserMountCache', function (IAppContainer $c) {
50
-			return $c->getServer()->query('UserMountCache');
51
-		});
52
-
53
-		$backendService = $container->query('OCA\\Files_External\\Service\\BackendService');
54
-		$backendService->registerBackendProvider($this);
55
-		$backendService->registerAuthMechanismProvider($this);
56
-
57
-		// force-load auth mechanisms since some will register hooks
58
-		// TODO: obsolete these and use the TokenProvider to get the user's password from the session
59
-		$this->getAuthMechanisms();
60
-
61
-		// app developers: do NOT depend on this! it will disappear with oC 9.0!
62
-		\OC::$server->getEventDispatcher()->dispatch(
63
-			'OCA\\Files_External::loadAdditionalBackends'
64
-		);
65
-	}
66
-
67
-	/**
68
-	 * @{inheritdoc}
69
-	 */
70
-	public function getBackends() {
71
-		$container = $this->getContainer();
72
-
73
-		$backends = [
74
-			$container->query('OCA\Files_External\Lib\Backend\Local'),
75
-			$container->query('OCA\Files_External\Lib\Backend\FTP'),
76
-			$container->query('OCA\Files_External\Lib\Backend\DAV'),
77
-			$container->query('OCA\Files_External\Lib\Backend\OwnCloud'),
78
-			$container->query('OCA\Files_External\Lib\Backend\SFTP'),
79
-			$container->query('OCA\Files_External\Lib\Backend\AmazonS3'),
80
-			$container->query('OCA\Files_External\Lib\Backend\Dropbox'),
81
-			$container->query('OCA\Files_External\Lib\Backend\Google'),
82
-			$container->query('OCA\Files_External\Lib\Backend\Swift'),
83
-			$container->query('OCA\Files_External\Lib\Backend\SFTP_Key'),
84
-			$container->query('OCA\Files_External\Lib\Backend\SMB'),
85
-			$container->query('OCA\Files_External\Lib\Backend\SMB_OC'),
86
-		];
87
-
88
-		return $backends;
89
-	}
90
-
91
-	/**
92
-	 * @{inheritdoc}
93
-	 */
94
-	public function getAuthMechanisms() {
95
-		$container = $this->getContainer();
96
-
97
-		return [
98
-			// AuthMechanism::SCHEME_NULL mechanism
99
-			$container->query('OCA\Files_External\Lib\Auth\NullMechanism'),
100
-
101
-			// AuthMechanism::SCHEME_BUILTIN mechanism
102
-			$container->query('OCA\Files_External\Lib\Auth\Builtin'),
103
-
104
-			// AuthMechanism::SCHEME_PASSWORD mechanisms
105
-			$container->query('OCA\Files_External\Lib\Auth\Password\Password'),
106
-			$container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'),
107
-			$container->query('OCA\Files_External\Lib\Auth\Password\LoginCredentials'),
108
-			$container->query('OCA\Files_External\Lib\Auth\Password\UserProvided'),
109
-			$container->query('OCA\Files_External\Lib\Auth\Password\GlobalAuth'),
110
-
111
-			// AuthMechanism::SCHEME_OAUTH1 mechanisms
112
-			$container->query('OCA\Files_External\Lib\Auth\OAuth1\OAuth1'),
113
-
114
-			// AuthMechanism::SCHEME_OAUTH2 mechanisms
115
-			$container->query('OCA\Files_External\Lib\Auth\OAuth2\OAuth2'),
116
-
117
-			// AuthMechanism::SCHEME_PUBLICKEY mechanisms
118
-			$container->query('OCA\Files_External\Lib\Auth\PublicKey\RSA'),
119
-
120
-			// AuthMechanism::SCHEME_OPENSTACK mechanisms
121
-			$container->query('OCA\Files_External\Lib\Auth\OpenStack\OpenStack'),
122
-			$container->query('OCA\Files_External\Lib\Auth\OpenStack\Rackspace'),
123
-
124
-			// Specialized mechanisms
125
-			$container->query('OCA\Files_External\Lib\Auth\AmazonS3\AccessKey'),
126
-		];
127
-	}
44
+    public function __construct(array $urlParams = array()) {
45
+        parent::__construct('files_external', $urlParams);
46
+
47
+        $container = $this->getContainer();
48
+
49
+        $container->registerService('OCP\Files\Config\IUserMountCache', function (IAppContainer $c) {
50
+            return $c->getServer()->query('UserMountCache');
51
+        });
52
+
53
+        $backendService = $container->query('OCA\\Files_External\\Service\\BackendService');
54
+        $backendService->registerBackendProvider($this);
55
+        $backendService->registerAuthMechanismProvider($this);
56
+
57
+        // force-load auth mechanisms since some will register hooks
58
+        // TODO: obsolete these and use the TokenProvider to get the user's password from the session
59
+        $this->getAuthMechanisms();
60
+
61
+        // app developers: do NOT depend on this! it will disappear with oC 9.0!
62
+        \OC::$server->getEventDispatcher()->dispatch(
63
+            'OCA\\Files_External::loadAdditionalBackends'
64
+        );
65
+    }
66
+
67
+    /**
68
+     * @{inheritdoc}
69
+     */
70
+    public function getBackends() {
71
+        $container = $this->getContainer();
72
+
73
+        $backends = [
74
+            $container->query('OCA\Files_External\Lib\Backend\Local'),
75
+            $container->query('OCA\Files_External\Lib\Backend\FTP'),
76
+            $container->query('OCA\Files_External\Lib\Backend\DAV'),
77
+            $container->query('OCA\Files_External\Lib\Backend\OwnCloud'),
78
+            $container->query('OCA\Files_External\Lib\Backend\SFTP'),
79
+            $container->query('OCA\Files_External\Lib\Backend\AmazonS3'),
80
+            $container->query('OCA\Files_External\Lib\Backend\Dropbox'),
81
+            $container->query('OCA\Files_External\Lib\Backend\Google'),
82
+            $container->query('OCA\Files_External\Lib\Backend\Swift'),
83
+            $container->query('OCA\Files_External\Lib\Backend\SFTP_Key'),
84
+            $container->query('OCA\Files_External\Lib\Backend\SMB'),
85
+            $container->query('OCA\Files_External\Lib\Backend\SMB_OC'),
86
+        ];
87
+
88
+        return $backends;
89
+    }
90
+
91
+    /**
92
+     * @{inheritdoc}
93
+     */
94
+    public function getAuthMechanisms() {
95
+        $container = $this->getContainer();
96
+
97
+        return [
98
+            // AuthMechanism::SCHEME_NULL mechanism
99
+            $container->query('OCA\Files_External\Lib\Auth\NullMechanism'),
100
+
101
+            // AuthMechanism::SCHEME_BUILTIN mechanism
102
+            $container->query('OCA\Files_External\Lib\Auth\Builtin'),
103
+
104
+            // AuthMechanism::SCHEME_PASSWORD mechanisms
105
+            $container->query('OCA\Files_External\Lib\Auth\Password\Password'),
106
+            $container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'),
107
+            $container->query('OCA\Files_External\Lib\Auth\Password\LoginCredentials'),
108
+            $container->query('OCA\Files_External\Lib\Auth\Password\UserProvided'),
109
+            $container->query('OCA\Files_External\Lib\Auth\Password\GlobalAuth'),
110
+
111
+            // AuthMechanism::SCHEME_OAUTH1 mechanisms
112
+            $container->query('OCA\Files_External\Lib\Auth\OAuth1\OAuth1'),
113
+
114
+            // AuthMechanism::SCHEME_OAUTH2 mechanisms
115
+            $container->query('OCA\Files_External\Lib\Auth\OAuth2\OAuth2'),
116
+
117
+            // AuthMechanism::SCHEME_PUBLICKEY mechanisms
118
+            $container->query('OCA\Files_External\Lib\Auth\PublicKey\RSA'),
119
+
120
+            // AuthMechanism::SCHEME_OPENSTACK mechanisms
121
+            $container->query('OCA\Files_External\Lib\Auth\OpenStack\OpenStack'),
122
+            $container->query('OCA\Files_External\Lib\Auth\OpenStack\Rackspace'),
123
+
124
+            // Specialized mechanisms
125
+            $container->query('OCA\Files_External\Lib\Auth\AmazonS3\AccessKey'),
126
+        ];
127
+    }
128 128
 
129 129
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Settings/Personal.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -32,72 +32,72 @@
 block discarded – undo
32 32
 
33 33
 class Personal implements ISettings {
34 34
 
35
-	/** @var IManager */
36
-	private $encryptionManager;
35
+    /** @var IManager */
36
+    private $encryptionManager;
37 37
 
38
-	/** @var UserGlobalStoragesService */
39
-	private $userGlobalStoragesService;
38
+    /** @var UserGlobalStoragesService */
39
+    private $userGlobalStoragesService;
40 40
 
41
-	/** @var BackendService */
42
-	private $backendService;
41
+    /** @var BackendService */
42
+    private $backendService;
43 43
 
44
-	/** @var GlobalAuth	 */
45
-	private $globalAuth;
44
+    /** @var GlobalAuth	 */
45
+    private $globalAuth;
46 46
 
47
-	/** @var IUserSession */
48
-	private $userSession;
47
+    /** @var IUserSession */
48
+    private $userSession;
49 49
 
50
-	public function __construct(
51
-		IManager $encryptionManager,
52
-		UserGlobalStoragesService $userGlobalStoragesService,
53
-		BackendService $backendService,
54
-		GlobalAuth $globalAuth,
55
-		IUserSession $userSession
56
-	) {
57
-		$this->encryptionManager = $encryptionManager;
58
-		$this->userGlobalStoragesService = $userGlobalStoragesService;
59
-		$this->backendService = $backendService;
60
-		$this->globalAuth = $globalAuth;
61
-		$this->userSession = $userSession;
62
-	}
50
+    public function __construct(
51
+        IManager $encryptionManager,
52
+        UserGlobalStoragesService $userGlobalStoragesService,
53
+        BackendService $backendService,
54
+        GlobalAuth $globalAuth,
55
+        IUserSession $userSession
56
+    ) {
57
+        $this->encryptionManager = $encryptionManager;
58
+        $this->userGlobalStoragesService = $userGlobalStoragesService;
59
+        $this->backendService = $backendService;
60
+        $this->globalAuth = $globalAuth;
61
+        $this->userSession = $userSession;
62
+    }
63 63
 
64
-	/**
65
-	 * @return TemplateResponse
66
-	 */
67
-	public function getForm() {
68
-		$uid = $this->userSession->getUser()->getUID();
64
+    /**
65
+     * @return TemplateResponse
66
+     */
67
+    public function getForm() {
68
+        $uid = $this->userSession->getUser()->getUID();
69 69
 
70
-		$parameters = [
71
-			'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
72
-			'visibilityType'       => BackendService::VISIBILITY_PERSONAL,
73
-			'storages'             => $this->userGlobalStoragesService->getStorages(),
74
-			'backends'             => $this->backendService->getAvailableBackends(),
75
-			'authMechanisms'       => $this->backendService->getAuthMechanisms(),
76
-			'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
77
-			'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
78
-			'globalCredentials'    => $this->globalAuth->getAuth($uid),
79
-			'globalCredentialsUid' => $uid,
80
-		];
70
+        $parameters = [
71
+            'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
72
+            'visibilityType'       => BackendService::VISIBILITY_PERSONAL,
73
+            'storages'             => $this->userGlobalStoragesService->getStorages(),
74
+            'backends'             => $this->backendService->getAvailableBackends(),
75
+            'authMechanisms'       => $this->backendService->getAuthMechanisms(),
76
+            'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
77
+            'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
78
+            'globalCredentials'    => $this->globalAuth->getAuth($uid),
79
+            'globalCredentialsUid' => $uid,
80
+        ];
81 81
 
82
-		return new TemplateResponse('files_external', 'settings', $parameters, '');
83
-	}
82
+        return new TemplateResponse('files_external', 'settings', $parameters, '');
83
+    }
84 84
 
85
-	/**
86
-	 * @return string the section ID, e.g. 'sharing'
87
-	 */
88
-	public function getSection() {
89
-		return 'externalstorages';
90
-	}
85
+    /**
86
+     * @return string the section ID, e.g. 'sharing'
87
+     */
88
+    public function getSection() {
89
+        return 'externalstorages';
90
+    }
91 91
 
92
-	/**
93
-	 * @return int whether the form should be rather on the top or bottom of
94
-	 * the admin section. The forms are arranged in ascending order of the
95
-	 * priority values. It is required to return a value between 0 and 100.
96
-	 *
97
-	 * E.g.: 70
98
-	 */
99
-	public function getPriority() {
100
-		return 40;
101
-	}
92
+    /**
93
+     * @return int whether the form should be rather on the top or bottom of
94
+     * the admin section. The forms are arranged in ascending order of the
95
+     * priority values. It is required to return a value between 0 and 100.
96
+     *
97
+     * E.g.: 70
98
+     */
99
+    public function getPriority() {
100
+        return 40;
101
+    }
102 102
 
103 103
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Settings/PersonalSection.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -29,39 +29,39 @@
 block discarded – undo
29 29
 use OCP\IUserSession;
30 30
 
31 31
 class PersonalSection extends Section {
32
-	/** @var IUserSession */
33
-	private $userSession;
32
+    /** @var IUserSession */
33
+    private $userSession;
34 34
 
35
-	/** @var UserGlobalStoragesService */
36
-	private $userGlobalStoragesService;
35
+    /** @var UserGlobalStoragesService */
36
+    private $userGlobalStoragesService;
37 37
 
38
-	/** @var BackendService */
39
-	private $backendService;
38
+    /** @var BackendService */
39
+    private $backendService;
40 40
 
41
-	public function __construct(
42
-		IURLGenerator $url,
43
-		IL10N $l,
44
-		IUserSession $userSession,
45
-		UserGlobalStoragesService $userGlobalStoragesService,
46
-		BackendService $backendService
47
-	) {
48
-		parent::__construct($url, $l);
49
-		$this->userSession = $userSession;
50
-		$this->userGlobalStoragesService = $userGlobalStoragesService;
51
-		$this->backendService = $backendService;
52
-	}
41
+    public function __construct(
42
+        IURLGenerator $url,
43
+        IL10N $l,
44
+        IUserSession $userSession,
45
+        UserGlobalStoragesService $userGlobalStoragesService,
46
+        BackendService $backendService
47
+    ) {
48
+        parent::__construct($url, $l);
49
+        $this->userSession = $userSession;
50
+        $this->userGlobalStoragesService = $userGlobalStoragesService;
51
+        $this->backendService = $backendService;
52
+    }
53 53
 
54
-	public function getID() {
55
-		if (!$this->userSession->isLoggedIn()) {
56
-			// we need to return the proper id while installing/upgrading the app
57
-			return parent::getID();
58
-		}
54
+    public function getID() {
55
+        if (!$this->userSession->isLoggedIn()) {
56
+            // we need to return the proper id while installing/upgrading the app
57
+            return parent::getID();
58
+        }
59 59
 
60
-		if (count($this->userGlobalStoragesService->getStorages()) > 0 || $this->backendService->isUserMountingAllowed()) {
61
-			return parent::getID();
62
-		} else {
63
-			// by returning a different id, no matching settings will be found and the item will be hidden
64
-			return null;
65
-		}
66
-	}
60
+        if (count($this->userGlobalStoragesService->getStorages()) > 0 || $this->backendService->isUserMountingAllowed()) {
61
+            return parent::getID();
62
+        } else {
63
+            // by returning a different id, no matching settings will be found and the item will be hidden
64
+            return null;
65
+        }
66
+    }
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.
apps/files_external/appinfo/app.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -36,14 +36,14 @@
 block discarded – undo
36 36
 $appContainer = \OC_Mount_Config::$app->getContainer();
37 37
 
38 38
 \OCA\Files\App::getNavigationManager()->add(function () {
39
-	$l = \OC::$server->getL10N('files_external');
40
-	return [
41
-		'id' => 'extstoragemounts',
42
-		'appname' => 'files_external',
43
-		'script' => 'list.php',
44
-		'order' => 30,
45
-		'name' => $l->t('External storages'),
46
-	];
39
+    $l = \OC::$server->getL10N('files_external');
40
+    return [
41
+        'id' => 'extstoragemounts',
42
+        'appname' => 'files_external',
43
+        'script' => 'list.php',
44
+        'order' => 30,
45
+        'name' => $l->t('External storages'),
46
+    ];
47 47
 });
48 48
 
49 49
 $mountProvider = $appContainer->query('OCA\Files_External\Config\ConfigAdapter');
Please login to merge, or discard this patch.
settings/templates/settings/personal/security.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@
 block discarded – undo
22 22
  */
23 23
 
24 24
 script('settings', [
25
-	'authtoken',
26
-	'authtoken_collection',
27
-	'authtoken_view',
28
-	'settings/authtoken-init'
25
+    'authtoken',
26
+    'authtoken_collection',
27
+    'authtoken_view',
28
+    'settings/authtoken-init'
29 29
 ]);
30 30
 
31 31
 ?>
Please login to merge, or discard this patch.
lib/private/Settings/Manager.php 1 patch
Indentation   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -42,473 +42,473 @@
 block discarded – undo
42 42
 use OCP\Settings\ISection;
43 43
 
44 44
 class Manager implements IManager {
45
-	/** @var ILogger */
46
-	private $log;
47
-	/** @var IDBConnection */
48
-	private $dbc;
49
-	/** @var Mapper */
50
-	private $mapper;
51
-	/** @var IL10N */
52
-	private $l;
53
-	/** @var IConfig */
54
-	private $config;
55
-	/** @var EncryptionManager */
56
-	private $encryptionManager;
57
-	/** @var IUserManager */
58
-	private $userManager;
59
-	/** @var ILockingProvider */
60
-	private $lockingProvider;
61
-	/** @var IRequest */
62
-	private $request;
63
-	/** @var IURLGenerator */
64
-	private $url;
65
-	/** @var AccountManager */
66
-	private $accountManager;
67
-	/** @var IGroupManager */
68
-	private $groupManager;
69
-	/** @var IFactory */
70
-	private $l10nFactory;
71
-	/** @var \OC_Defaults */
72
-	private $defaults;
73
-	/** @var IAppManager */
74
-	private $appManager;
75
-
76
-	/**
77
-	 * @param ILogger $log
78
-	 * @param IDBConnection $dbc
79
-	 * @param IL10N $l
80
-	 * @param IConfig $config
81
-	 * @param EncryptionManager $encryptionManager
82
-	 * @param IUserManager $userManager
83
-	 * @param ILockingProvider $lockingProvider
84
-	 * @param IRequest $request
85
-	 * @param Mapper $mapper
86
-	 * @param IURLGenerator $url
87
-	 * @param AccountManager $accountManager
88
-	 * @param IGroupManager $groupManager
89
-	 * @param IFactory $l10nFactory
90
-	 * @param \OC_Defaults $defaults
91
-	 */
92
-	public function __construct(
93
-		ILogger $log,
94
-		IDBConnection $dbc,
95
-		IL10N $l,
96
-		IConfig $config,
97
-		EncryptionManager $encryptionManager,
98
-		IUserManager $userManager,
99
-		ILockingProvider $lockingProvider,
100
-		IRequest $request,
101
-		Mapper $mapper,
102
-		IURLGenerator $url,
103
-		AccountManager $accountManager,
104
-		IGroupManager $groupManager,
105
-		IFactory $l10nFactory,
106
-		\OC_Defaults $defaults,
107
-		IAppManager $appManager
108
-	) {
109
-		$this->log = $log;
110
-		$this->dbc = $dbc;
111
-		$this->mapper = $mapper;
112
-		$this->l = $l;
113
-		$this->config = $config;
114
-		$this->encryptionManager = $encryptionManager;
115
-		$this->userManager = $userManager;
116
-		$this->lockingProvider = $lockingProvider;
117
-		$this->request = $request;
118
-		$this->url = $url;
119
-		$this->accountManager = $accountManager;
120
-		$this->groupManager = $groupManager;
121
-		$this->l10nFactory = $l10nFactory;
122
-		$this->defaults = $defaults;
123
-		$this->appManager = $appManager;
124
-	}
125
-
126
-	/**
127
-	 * @inheritdoc
128
-	 */
129
-	public function setupSettings(array $settings) {
130
-		if (isset($settings[IManager::KEY_ADMIN_SECTION])) {
131
-			$this->setupSectionEntry($settings[IManager::KEY_ADMIN_SECTION], 'admin');
132
-		}
133
-		if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) {
134
-			$this->setupSettingsEntry($settings[IManager::KEY_ADMIN_SETTINGS], 'admin');
135
-		}
136
-
137
-		if (isset($settings[IManager::KEY_PERSONAL_SECTION])) {
138
-			$this->setupSectionEntry($settings[IManager::KEY_PERSONAL_SECTION], 'personal');
139
-		}
140
-		if (isset($settings[IManager::KEY_PERSONAL_SETTINGS])) {
141
-			$this->setupSettingsEntry($settings[IManager::KEY_PERSONAL_SETTINGS], 'personal');
142
-		}
143
-	}
144
-
145
-	/**
146
-	 * attempts to remove an apps section and/or settings entry. A listener is
147
-	 * added centrally making sure that this method is called ones an app was
148
-	 * disabled.
149
-	 *
150
-	 * @param string $appId
151
-	 * @since 9.1.0
152
-	 */
153
-	public function onAppDisabled($appId) {
154
-		$appInfo = \OC_App::getAppInfo($appId); // hello static legacy
155
-
156
-		if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
157
-			$this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
158
-		}
159
-		if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
160
-			$this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
161
-		}
162
-
163
-		if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) {
164
-			$this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\'));
165
-		}
166
-		if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) {
167
-			$this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\'));
168
-		}
169
-	}
170
-
171
-	public function checkForOrphanedClassNames() {
172
-		$tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS];
173
-		foreach ($tables as $table) {
174
-			$classes = $this->mapper->getClasses($table);
175
-			foreach ($classes as $className) {
176
-				try {
177
-					\OC::$server->query($className);
178
-				} catch (QueryException $e) {
179
-					$this->mapper->remove($table, $className);
180
-				}
181
-			}
182
-		}
183
-	}
184
-
185
-	/**
186
-	 * @param string $sectionClassName
187
-	 * @param string $type either 'admin' or 'personal'
188
-	 */
189
-	private function setupSectionEntry($sectionClassName, $type) {
190
-		if (!class_exists($sectionClassName)) {
191
-			$this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName);
192
-			return;
193
-		}
194
-		try {
195
-			$section = $this->query($sectionClassName);
196
-		} catch (QueryException $e) {
197
-			// cancel
198
-			return;
199
-		}
200
-
201
-		if (!$section instanceof ISection) {
202
-			$this->log->error(
203
-				ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}',
204
-				['class' => $sectionClassName]
205
-			);
206
-			return;
207
-		}
208
-		$table = $this->getSectionTableForType($type);
209
-		if(!$this->hasSection(get_class($section), $table)) {
210
-			$this->addSection($section, $table);
211
-		} else {
212
-			$this->updateSection($section, $table);
213
-		}
214
-	}
215
-
216
-	private function addSection(ISection $section, $table) {
217
-		$this->mapper->add($table, [
218
-			'id' => $section->getID(),
219
-			'class' => get_class($section),
220
-			'priority' => $section->getPriority(),
221
-		]);
222
-	}
223
-
224
-	private function addSettings(ISettings $settings, $table) {
225
-		$this->mapper->add($table, [
226
-			'class' => get_class($settings),
227
-			'section' => $settings->getSection(),
228
-			'priority' => $settings->getPriority(),
229
-		]);
230
-	}
231
-
232
-	private function updateSettings(ISettings $settings, $table) {
233
-		$this->mapper->update(
234
-			$table,
235
-			'class',
236
-			get_class($settings),
237
-			[
238
-				'section' => $settings->getSection(),
239
-				'priority' => $settings->getPriority(),
240
-			]
241
-		);
242
-	}
243
-
244
-	private function updateSection(ISection $section, $table) {
245
-		$this->mapper->update(
246
-			$table,
247
-			'class',
248
-			get_class($section),
249
-			[
250
-				'id' => $section->getID(),
251
-				'priority' => $section->getPriority(),
252
-			]
253
-		);
254
-	}
255
-
256
-	/**
257
-	 * @param string $className
258
-	 * @param string $table
259
-	 * @return bool
260
-	 */
261
-	private function hasSection($className, $table) {
262
-		return $this->mapper->has($table, $className);
263
-	}
264
-
265
-	/**
266
-	 * @param string $className
267
-	 * @return bool
268
-	 */
269
-	private function hasSettings($className, $table) {
270
-		return $this->mapper->has($table, $className);
271
-	}
272
-
273
-	private function setupSettingsEntry($settingsClassName, $type) {
274
-		if (!class_exists($settingsClassName)) {
275
-			$this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName);
276
-			return;
277
-		}
278
-
279
-		try {
280
-			/** @var ISettings $settings */
281
-			$settings = $this->query($settingsClassName);
282
-		} catch (QueryException $e) {
283
-			// cancel
284
-			return;
285
-		}
286
-
287
-		if (!$settings instanceof ISettings) {
288
-			$this->log->error(
289
-				ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}',
290
-				['class' => $settingsClassName]
291
-			);
292
-			return;
293
-		}
294
-		$table = $this->getSettingsTableForType($type);
295
-		if (!$this->hasSettings(get_class($settings), $table)) {
296
-			$this->addSettings($settings, $table);
297
-		} else {
298
-			$this->updateSettings($settings, $table);
299
-		}
300
-	}
301
-
302
-	private function getSectionTableForType($type) {
303
-		if($type === 'admin') {
304
-			return Mapper::TABLE_ADMIN_SECTIONS;
305
-		} else if($type === 'personal') {
306
-			return Mapper::TABLE_PERSONAL_SECTIONS;
307
-		}
308
-		throw new \InvalidArgumentException('"admin" or "personal" expected');
309
-	}
310
-
311
-	private function getSettingsTableForType($type) {
312
-		if($type === 'admin') {
313
-			return Mapper::TABLE_ADMIN_SETTINGS;
314
-		} else if($type === 'personal') {
315
-			return Mapper::TABLE_PERSONAL_SETTINGS;
316
-		}
317
-		throw new \InvalidArgumentException('"admin" or "personal" expected');
318
-	}
319
-
320
-	private function query($className) {
321
-		try {
322
-			return \OC::$server->query($className);
323
-		} catch (QueryException $e) {
324
-			$this->log->logException($e);
325
-			throw $e;
326
-		}
327
-	}
328
-
329
-	/**
330
-	 * @inheritdoc
331
-	 */
332
-	public function getAdminSections() {
333
-		// built-in sections
334
-		$sections = [
335
-			0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))],
336
-			5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
337
-			10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
338
-			45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
339
-			98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
340
-			99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
341
-		];
342
-
343
-		$rows = $this->mapper->getAdminSectionsFromDB();
344
-
345
-		foreach ($rows as $row) {
346
-			if (!isset($sections[$row['priority']])) {
347
-				$sections[$row['priority']] = [];
348
-			}
349
-			try {
350
-				$sections[$row['priority']][] = $this->query($row['class']);
351
-			} catch (QueryException $e) {
352
-				// skip
353
-			}
354
-		}
355
-
356
-		ksort($sections);
357
-
358
-		return $sections;
359
-	}
360
-
361
-	/**
362
-	 * @param string $section
363
-	 * @return ISection[]
364
-	 */
365
-	private function getBuiltInAdminSettings($section) {
366
-		$forms = [];
367
-		try {
368
-			if ($section === 'server') {
369
-				/** @var ISettings $form */
370
-				$form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
371
-				$forms[$form->getPriority()] = [$form];
372
-				$form = new Admin\ServerDevNotice();
373
-				$forms[$form->getPriority()] = [$form];
374
-			}
375
-			if ($section === 'encryption') {
376
-				/** @var ISettings $form */
377
-				$form = new Admin\Encryption($this->encryptionManager, $this->userManager);
378
-				$forms[$form->getPriority()] = [$form];
379
-			}
380
-			if ($section === 'sharing') {
381
-				/** @var ISettings $form */
382
-				$form = new Admin\Sharing($this->config);
383
-				$forms[$form->getPriority()] = [$form];
384
-			}
385
-			if ($section === 'additional') {
386
-				/** @var ISettings $form */
387
-				$form = new Admin\Additional($this->config);
388
-				$forms[$form->getPriority()] = [$form];
389
-			}
390
-			if ($section === 'tips-tricks') {
391
-				/** @var ISettings $form */
392
-				$form = new Admin\TipsTricks($this->config);
393
-				$forms[$form->getPriority()] = [$form];
394
-			}
395
-		} catch (QueryException $e) {
396
-			// skip
397
-		}
398
-		return $forms;
399
-	}
400
-
401
-	/**
402
-	 * @param string $section
403
-	 * @return ISection[]
404
-	 */
405
-	private function getBuiltInPersonalSettings($section) {
406
-		$forms = [];
407
-		try {
408
-			if ($section === 'personal-info') {
409
-				/** @var ISettings $form */
410
-				$form = new Personal\PersonalInfo(
411
-					$this->config,
412
-					$this->userManager,
413
-					$this->groupManager,
414
-					$this->accountManager,
415
-					$this->appManager,
416
-					$this->l10nFactory,
417
-					$this->l
418
-				);
419
-				$forms[$form->getPriority()] = [$form];
420
-			}
421
-			if($section === 'security') {
422
-				/** @var ISettings $form */
423
-				$form = new Personal\Security();
424
-				$forms[$form->getPriority()] = [$form];
425
-			}
426
-			if($section === 'sync-clients') {
427
-				/** @var ISettings $form */
428
-				$form = new Personal\SyncClients($this->config, $this->defaults);
429
-				$forms[$form->getPriority()] = [$form];
430
-			}
431
-			if ($section === 'additional') {
432
-				/** @var ISettings $form */
433
-				$form = new Personal\Additional($this->config);
434
-				$forms[$form->getPriority()] = [$form];
435
-			}
436
-		} catch (QueryException $e) {
437
-			// skip
438
-		}
439
-		return $forms;
440
-	}
441
-
442
-	/**
443
-	 * @inheritdoc
444
-	 */
445
-	public function getAdminSettings($section) {
446
-		$settings = $this->getBuiltInAdminSettings($section);
447
-		$dbRows = $this->mapper->getAdminSettingsFromDB($section);
448
-
449
-		foreach ($dbRows as $row) {
450
-			if (!isset($settings[$row['priority']])) {
451
-				$settings[$row['priority']] = [];
452
-			}
453
-			try {
454
-				$settings[$row['priority']][] = $this->query($row['class']);
455
-			} catch (QueryException $e) {
456
-				// skip
457
-			}
458
-		}
459
-
460
-		ksort($settings);
461
-		return $settings;
462
-	}
463
-
464
-	/**
465
-	 * @inheritdoc
466
-	 */
467
-	public function getPersonalSections() {
468
-		$sections = [
469
-			0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
470
-			5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],
471
-			15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))],
472
-			98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
473
-		];
474
-
475
-		$rows = $this->mapper->getPersonalSectionsFromDB();
476
-
477
-		foreach ($rows as $row) {
478
-			if (!isset($sections[$row['priority']])) {
479
-				$sections[$row['priority']] = [];
480
-			}
481
-			try {
482
-				$sections[$row['priority']][] = $this->query($row['class']);
483
-			} catch (QueryException $e) {
484
-				// skip
485
-			}
486
-		}
487
-
488
-		ksort($sections);
489
-
490
-		return $sections;
491
-	}
492
-
493
-	/**
494
-	 * @inheritdoc
495
-	 */
496
-	public function getPersonalSettings($section) {
497
-		$settings = $this->getBuiltInPersonalSettings($section);
498
-		$dbRows = $this->mapper->getPersonalSettingsFromDB($section);
499
-
500
-		foreach ($dbRows as $row) {
501
-			if (!isset($settings[$row['priority']])) {
502
-				$settings[$row['priority']] = [];
503
-			}
504
-			try {
505
-				$settings[$row['priority']][] = $this->query($row['class']);
506
-			} catch (QueryException $e) {
507
-				// skip
508
-			}
509
-		}
510
-
511
-		ksort($settings);
512
-		return $settings;
513
-	}
45
+    /** @var ILogger */
46
+    private $log;
47
+    /** @var IDBConnection */
48
+    private $dbc;
49
+    /** @var Mapper */
50
+    private $mapper;
51
+    /** @var IL10N */
52
+    private $l;
53
+    /** @var IConfig */
54
+    private $config;
55
+    /** @var EncryptionManager */
56
+    private $encryptionManager;
57
+    /** @var IUserManager */
58
+    private $userManager;
59
+    /** @var ILockingProvider */
60
+    private $lockingProvider;
61
+    /** @var IRequest */
62
+    private $request;
63
+    /** @var IURLGenerator */
64
+    private $url;
65
+    /** @var AccountManager */
66
+    private $accountManager;
67
+    /** @var IGroupManager */
68
+    private $groupManager;
69
+    /** @var IFactory */
70
+    private $l10nFactory;
71
+    /** @var \OC_Defaults */
72
+    private $defaults;
73
+    /** @var IAppManager */
74
+    private $appManager;
75
+
76
+    /**
77
+     * @param ILogger $log
78
+     * @param IDBConnection $dbc
79
+     * @param IL10N $l
80
+     * @param IConfig $config
81
+     * @param EncryptionManager $encryptionManager
82
+     * @param IUserManager $userManager
83
+     * @param ILockingProvider $lockingProvider
84
+     * @param IRequest $request
85
+     * @param Mapper $mapper
86
+     * @param IURLGenerator $url
87
+     * @param AccountManager $accountManager
88
+     * @param IGroupManager $groupManager
89
+     * @param IFactory $l10nFactory
90
+     * @param \OC_Defaults $defaults
91
+     */
92
+    public function __construct(
93
+        ILogger $log,
94
+        IDBConnection $dbc,
95
+        IL10N $l,
96
+        IConfig $config,
97
+        EncryptionManager $encryptionManager,
98
+        IUserManager $userManager,
99
+        ILockingProvider $lockingProvider,
100
+        IRequest $request,
101
+        Mapper $mapper,
102
+        IURLGenerator $url,
103
+        AccountManager $accountManager,
104
+        IGroupManager $groupManager,
105
+        IFactory $l10nFactory,
106
+        \OC_Defaults $defaults,
107
+        IAppManager $appManager
108
+    ) {
109
+        $this->log = $log;
110
+        $this->dbc = $dbc;
111
+        $this->mapper = $mapper;
112
+        $this->l = $l;
113
+        $this->config = $config;
114
+        $this->encryptionManager = $encryptionManager;
115
+        $this->userManager = $userManager;
116
+        $this->lockingProvider = $lockingProvider;
117
+        $this->request = $request;
118
+        $this->url = $url;
119
+        $this->accountManager = $accountManager;
120
+        $this->groupManager = $groupManager;
121
+        $this->l10nFactory = $l10nFactory;
122
+        $this->defaults = $defaults;
123
+        $this->appManager = $appManager;
124
+    }
125
+
126
+    /**
127
+     * @inheritdoc
128
+     */
129
+    public function setupSettings(array $settings) {
130
+        if (isset($settings[IManager::KEY_ADMIN_SECTION])) {
131
+            $this->setupSectionEntry($settings[IManager::KEY_ADMIN_SECTION], 'admin');
132
+        }
133
+        if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) {
134
+            $this->setupSettingsEntry($settings[IManager::KEY_ADMIN_SETTINGS], 'admin');
135
+        }
136
+
137
+        if (isset($settings[IManager::KEY_PERSONAL_SECTION])) {
138
+            $this->setupSectionEntry($settings[IManager::KEY_PERSONAL_SECTION], 'personal');
139
+        }
140
+        if (isset($settings[IManager::KEY_PERSONAL_SETTINGS])) {
141
+            $this->setupSettingsEntry($settings[IManager::KEY_PERSONAL_SETTINGS], 'personal');
142
+        }
143
+    }
144
+
145
+    /**
146
+     * attempts to remove an apps section and/or settings entry. A listener is
147
+     * added centrally making sure that this method is called ones an app was
148
+     * disabled.
149
+     *
150
+     * @param string $appId
151
+     * @since 9.1.0
152
+     */
153
+    public function onAppDisabled($appId) {
154
+        $appInfo = \OC_App::getAppInfo($appId); // hello static legacy
155
+
156
+        if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
157
+            $this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
158
+        }
159
+        if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
160
+            $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
161
+        }
162
+
163
+        if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) {
164
+            $this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\'));
165
+        }
166
+        if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) {
167
+            $this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\'));
168
+        }
169
+    }
170
+
171
+    public function checkForOrphanedClassNames() {
172
+        $tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS];
173
+        foreach ($tables as $table) {
174
+            $classes = $this->mapper->getClasses($table);
175
+            foreach ($classes as $className) {
176
+                try {
177
+                    \OC::$server->query($className);
178
+                } catch (QueryException $e) {
179
+                    $this->mapper->remove($table, $className);
180
+                }
181
+            }
182
+        }
183
+    }
184
+
185
+    /**
186
+     * @param string $sectionClassName
187
+     * @param string $type either 'admin' or 'personal'
188
+     */
189
+    private function setupSectionEntry($sectionClassName, $type) {
190
+        if (!class_exists($sectionClassName)) {
191
+            $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName);
192
+            return;
193
+        }
194
+        try {
195
+            $section = $this->query($sectionClassName);
196
+        } catch (QueryException $e) {
197
+            // cancel
198
+            return;
199
+        }
200
+
201
+        if (!$section instanceof ISection) {
202
+            $this->log->error(
203
+                ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}',
204
+                ['class' => $sectionClassName]
205
+            );
206
+            return;
207
+        }
208
+        $table = $this->getSectionTableForType($type);
209
+        if(!$this->hasSection(get_class($section), $table)) {
210
+            $this->addSection($section, $table);
211
+        } else {
212
+            $this->updateSection($section, $table);
213
+        }
214
+    }
215
+
216
+    private function addSection(ISection $section, $table) {
217
+        $this->mapper->add($table, [
218
+            'id' => $section->getID(),
219
+            'class' => get_class($section),
220
+            'priority' => $section->getPriority(),
221
+        ]);
222
+    }
223
+
224
+    private function addSettings(ISettings $settings, $table) {
225
+        $this->mapper->add($table, [
226
+            'class' => get_class($settings),
227
+            'section' => $settings->getSection(),
228
+            'priority' => $settings->getPriority(),
229
+        ]);
230
+    }
231
+
232
+    private function updateSettings(ISettings $settings, $table) {
233
+        $this->mapper->update(
234
+            $table,
235
+            'class',
236
+            get_class($settings),
237
+            [
238
+                'section' => $settings->getSection(),
239
+                'priority' => $settings->getPriority(),
240
+            ]
241
+        );
242
+    }
243
+
244
+    private function updateSection(ISection $section, $table) {
245
+        $this->mapper->update(
246
+            $table,
247
+            'class',
248
+            get_class($section),
249
+            [
250
+                'id' => $section->getID(),
251
+                'priority' => $section->getPriority(),
252
+            ]
253
+        );
254
+    }
255
+
256
+    /**
257
+     * @param string $className
258
+     * @param string $table
259
+     * @return bool
260
+     */
261
+    private function hasSection($className, $table) {
262
+        return $this->mapper->has($table, $className);
263
+    }
264
+
265
+    /**
266
+     * @param string $className
267
+     * @return bool
268
+     */
269
+    private function hasSettings($className, $table) {
270
+        return $this->mapper->has($table, $className);
271
+    }
272
+
273
+    private function setupSettingsEntry($settingsClassName, $type) {
274
+        if (!class_exists($settingsClassName)) {
275
+            $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName);
276
+            return;
277
+        }
278
+
279
+        try {
280
+            /** @var ISettings $settings */
281
+            $settings = $this->query($settingsClassName);
282
+        } catch (QueryException $e) {
283
+            // cancel
284
+            return;
285
+        }
286
+
287
+        if (!$settings instanceof ISettings) {
288
+            $this->log->error(
289
+                ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}',
290
+                ['class' => $settingsClassName]
291
+            );
292
+            return;
293
+        }
294
+        $table = $this->getSettingsTableForType($type);
295
+        if (!$this->hasSettings(get_class($settings), $table)) {
296
+            $this->addSettings($settings, $table);
297
+        } else {
298
+            $this->updateSettings($settings, $table);
299
+        }
300
+    }
301
+
302
+    private function getSectionTableForType($type) {
303
+        if($type === 'admin') {
304
+            return Mapper::TABLE_ADMIN_SECTIONS;
305
+        } else if($type === 'personal') {
306
+            return Mapper::TABLE_PERSONAL_SECTIONS;
307
+        }
308
+        throw new \InvalidArgumentException('"admin" or "personal" expected');
309
+    }
310
+
311
+    private function getSettingsTableForType($type) {
312
+        if($type === 'admin') {
313
+            return Mapper::TABLE_ADMIN_SETTINGS;
314
+        } else if($type === 'personal') {
315
+            return Mapper::TABLE_PERSONAL_SETTINGS;
316
+        }
317
+        throw new \InvalidArgumentException('"admin" or "personal" expected');
318
+    }
319
+
320
+    private function query($className) {
321
+        try {
322
+            return \OC::$server->query($className);
323
+        } catch (QueryException $e) {
324
+            $this->log->logException($e);
325
+            throw $e;
326
+        }
327
+    }
328
+
329
+    /**
330
+     * @inheritdoc
331
+     */
332
+    public function getAdminSections() {
333
+        // built-in sections
334
+        $sections = [
335
+            0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))],
336
+            5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
337
+            10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
338
+            45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
339
+            98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
340
+            99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
341
+        ];
342
+
343
+        $rows = $this->mapper->getAdminSectionsFromDB();
344
+
345
+        foreach ($rows as $row) {
346
+            if (!isset($sections[$row['priority']])) {
347
+                $sections[$row['priority']] = [];
348
+            }
349
+            try {
350
+                $sections[$row['priority']][] = $this->query($row['class']);
351
+            } catch (QueryException $e) {
352
+                // skip
353
+            }
354
+        }
355
+
356
+        ksort($sections);
357
+
358
+        return $sections;
359
+    }
360
+
361
+    /**
362
+     * @param string $section
363
+     * @return ISection[]
364
+     */
365
+    private function getBuiltInAdminSettings($section) {
366
+        $forms = [];
367
+        try {
368
+            if ($section === 'server') {
369
+                /** @var ISettings $form */
370
+                $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
371
+                $forms[$form->getPriority()] = [$form];
372
+                $form = new Admin\ServerDevNotice();
373
+                $forms[$form->getPriority()] = [$form];
374
+            }
375
+            if ($section === 'encryption') {
376
+                /** @var ISettings $form */
377
+                $form = new Admin\Encryption($this->encryptionManager, $this->userManager);
378
+                $forms[$form->getPriority()] = [$form];
379
+            }
380
+            if ($section === 'sharing') {
381
+                /** @var ISettings $form */
382
+                $form = new Admin\Sharing($this->config);
383
+                $forms[$form->getPriority()] = [$form];
384
+            }
385
+            if ($section === 'additional') {
386
+                /** @var ISettings $form */
387
+                $form = new Admin\Additional($this->config);
388
+                $forms[$form->getPriority()] = [$form];
389
+            }
390
+            if ($section === 'tips-tricks') {
391
+                /** @var ISettings $form */
392
+                $form = new Admin\TipsTricks($this->config);
393
+                $forms[$form->getPriority()] = [$form];
394
+            }
395
+        } catch (QueryException $e) {
396
+            // skip
397
+        }
398
+        return $forms;
399
+    }
400
+
401
+    /**
402
+     * @param string $section
403
+     * @return ISection[]
404
+     */
405
+    private function getBuiltInPersonalSettings($section) {
406
+        $forms = [];
407
+        try {
408
+            if ($section === 'personal-info') {
409
+                /** @var ISettings $form */
410
+                $form = new Personal\PersonalInfo(
411
+                    $this->config,
412
+                    $this->userManager,
413
+                    $this->groupManager,
414
+                    $this->accountManager,
415
+                    $this->appManager,
416
+                    $this->l10nFactory,
417
+                    $this->l
418
+                );
419
+                $forms[$form->getPriority()] = [$form];
420
+            }
421
+            if($section === 'security') {
422
+                /** @var ISettings $form */
423
+                $form = new Personal\Security();
424
+                $forms[$form->getPriority()] = [$form];
425
+            }
426
+            if($section === 'sync-clients') {
427
+                /** @var ISettings $form */
428
+                $form = new Personal\SyncClients($this->config, $this->defaults);
429
+                $forms[$form->getPriority()] = [$form];
430
+            }
431
+            if ($section === 'additional') {
432
+                /** @var ISettings $form */
433
+                $form = new Personal\Additional($this->config);
434
+                $forms[$form->getPriority()] = [$form];
435
+            }
436
+        } catch (QueryException $e) {
437
+            // skip
438
+        }
439
+        return $forms;
440
+    }
441
+
442
+    /**
443
+     * @inheritdoc
444
+     */
445
+    public function getAdminSettings($section) {
446
+        $settings = $this->getBuiltInAdminSettings($section);
447
+        $dbRows = $this->mapper->getAdminSettingsFromDB($section);
448
+
449
+        foreach ($dbRows as $row) {
450
+            if (!isset($settings[$row['priority']])) {
451
+                $settings[$row['priority']] = [];
452
+            }
453
+            try {
454
+                $settings[$row['priority']][] = $this->query($row['class']);
455
+            } catch (QueryException $e) {
456
+                // skip
457
+            }
458
+        }
459
+
460
+        ksort($settings);
461
+        return $settings;
462
+    }
463
+
464
+    /**
465
+     * @inheritdoc
466
+     */
467
+    public function getPersonalSections() {
468
+        $sections = [
469
+            0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
470
+            5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],
471
+            15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))],
472
+            98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
473
+        ];
474
+
475
+        $rows = $this->mapper->getPersonalSectionsFromDB();
476
+
477
+        foreach ($rows as $row) {
478
+            if (!isset($sections[$row['priority']])) {
479
+                $sections[$row['priority']] = [];
480
+            }
481
+            try {
482
+                $sections[$row['priority']][] = $this->query($row['class']);
483
+            } catch (QueryException $e) {
484
+                // skip
485
+            }
486
+        }
487
+
488
+        ksort($sections);
489
+
490
+        return $sections;
491
+    }
492
+
493
+    /**
494
+     * @inheritdoc
495
+     */
496
+    public function getPersonalSettings($section) {
497
+        $settings = $this->getBuiltInPersonalSettings($section);
498
+        $dbRows = $this->mapper->getPersonalSettingsFromDB($section);
499
+
500
+        foreach ($dbRows as $row) {
501
+            if (!isset($settings[$row['priority']])) {
502
+                $settings[$row['priority']] = [];
503
+            }
504
+            try {
505
+                $settings[$row['priority']][] = $this->query($row['class']);
506
+            } catch (QueryException $e) {
507
+                // skip
508
+            }
509
+        }
510
+
511
+        ksort($settings);
512
+        return $settings;
513
+    }
514 514
 }
Please login to merge, or discard this patch.
lib/private/Settings/Personal/PersonalInfo.php 1 patch
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -39,237 +39,237 @@
 block discarded – undo
39 39
 use OCP\Settings\ISettings;
40 40
 
41 41
 class PersonalInfo implements ISettings {
42
-	/** @var IConfig */
43
-	private $config;
44
-	/** @var IUserManager */
45
-	private $userManager;
46
-	/** @var AccountManager */
47
-	private $accountManager;
48
-	/** @var IGroupManager */
49
-	private $groupManager;
50
-	/** @var IAppManager */
51
-	private $appManager;
52
-	/** @var IFactory */
53
-	private $l10nFactory;
42
+    /** @var IConfig */
43
+    private $config;
44
+    /** @var IUserManager */
45
+    private $userManager;
46
+    /** @var AccountManager */
47
+    private $accountManager;
48
+    /** @var IGroupManager */
49
+    private $groupManager;
50
+    /** @var IAppManager */
51
+    private $appManager;
52
+    /** @var IFactory */
53
+    private $l10nFactory;
54 54
 
55
-	const COMMON_LANGUAGE_CODES = [
56
-		'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it',
57
-		'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
58
-	];
55
+    const COMMON_LANGUAGE_CODES = [
56
+        'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it',
57
+        'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
58
+    ];
59 59
 
60
-	/** @var IL10N */
61
-	private $l;
60
+    /** @var IL10N */
61
+    private $l;
62 62
 
63
-	/**
64
-	 * @param IConfig $config
65
-	 * @param IUserManager $userManager
66
-	 * @param IGroupManager $groupManager
67
-	 * @param AccountManager $accountManager
68
-	 * @param IFactory $l10nFactory
69
-	 * @param IL10N $l
70
-	 */
71
-	public function __construct(
72
-		IConfig $config,
73
-		IUserManager $userManager,
74
-		IGroupManager $groupManager,
75
-		AccountManager $accountManager,
76
-		IAppManager $appManager,
77
-		IFactory $l10nFactory,
78
-		IL10N $l
79
-	) {
80
-		$this->config = $config;
81
-		$this->userManager = $userManager;
82
-		$this->accountManager = $accountManager;
83
-		$this->groupManager = $groupManager;
84
-		$this->appManager = $appManager;
85
-		$this->l10nFactory = $l10nFactory;
86
-		$this->l = $l;
87
-	}
63
+    /**
64
+     * @param IConfig $config
65
+     * @param IUserManager $userManager
66
+     * @param IGroupManager $groupManager
67
+     * @param AccountManager $accountManager
68
+     * @param IFactory $l10nFactory
69
+     * @param IL10N $l
70
+     */
71
+    public function __construct(
72
+        IConfig $config,
73
+        IUserManager $userManager,
74
+        IGroupManager $groupManager,
75
+        AccountManager $accountManager,
76
+        IAppManager $appManager,
77
+        IFactory $l10nFactory,
78
+        IL10N $l
79
+    ) {
80
+        $this->config = $config;
81
+        $this->userManager = $userManager;
82
+        $this->accountManager = $accountManager;
83
+        $this->groupManager = $groupManager;
84
+        $this->appManager = $appManager;
85
+        $this->l10nFactory = $l10nFactory;
86
+        $this->l = $l;
87
+    }
88 88
 
89
-	/**
90
-	 * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
91
-	 * @since 9.1
92
-	 */
93
-	public function getForm() {
94
-		$federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
95
-		$lookupServerUploadEnabled = false;
96
-		if($federatedFileSharingEnabled) {
97
-			$federatedFileSharing = new Application();
98
-			$shareProvider = $federatedFileSharing->getFederatedShareProvider();
99
-			$lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled();
100
-		}
89
+    /**
90
+     * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
91
+     * @since 9.1
92
+     */
93
+    public function getForm() {
94
+        $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
95
+        $lookupServerUploadEnabled = false;
96
+        if($federatedFileSharingEnabled) {
97
+            $federatedFileSharing = new Application();
98
+            $shareProvider = $federatedFileSharing->getFederatedShareProvider();
99
+            $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled();
100
+        }
101 101
 
102
-		$uid = \OC_User::getUser();
103
-		$user = $this->userManager->get($uid);
104
-		$userData = $this->accountManager->getUser($user);
102
+        $uid = \OC_User::getUser();
103
+        $user = $this->userManager->get($uid);
104
+        $userData = $this->accountManager->getUser($user);
105 105
 
106
-		$storageInfo = \OC_Helper::getStorageInfo('/');
107
-		if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) {
108
-			$totalSpace = $this->l->t('Unlimited');
109
-		} else {
110
-			$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
111
-		}
106
+        $storageInfo = \OC_Helper::getStorageInfo('/');
107
+        if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) {
108
+            $totalSpace = $this->l->t('Unlimited');
109
+        } else {
110
+            $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
111
+        }
112 112
 
113
-		list($activeLanguage, $commonLanguages, $languages) = $this->getLanguages($user);
114
-		$messageParameters = $this->getMessageParameters($userData);
113
+        list($activeLanguage, $commonLanguages, $languages) = $this->getLanguages($user);
114
+        $messageParameters = $this->getMessageParameters($userData);
115 115
 
116
-		$parameters = [
117
-			'total_space' => $totalSpace,
118
-			'usage' => \OC_Helper::humanFileSize($storageInfo['used']),
119
-			'usage_relative' => $storageInfo['relative'],
120
-			'quota' => $storageInfo['quota'],
121
-			'avatarChangeSupported' => \OC_User::canUserChangeAvatar($uid),
122
-			'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
123
-			'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'],
124
-			'displayNameChangeSupported' => \OC_User::canUserChangeDisplayName($uid),
125
-			'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'],
126
-			'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
127
-			'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'],
128
-			'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'],
129
-			'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'],
130
-			'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'],
131
-			'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'],
132
-			'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'],
133
-			'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'],
134
-			'website' =>  $userData[AccountManager::PROPERTY_WEBSITE]['value'],
135
-			'websiteScope' =>  $userData[AccountManager::PROPERTY_WEBSITE]['scope'],
136
-			'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'],
137
-			'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'],
138
-			'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'],
139
-			'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'],
140
-			'groups' => $this->getGroups($user),
141
-			'passwordChangeSupported' => \OC_User::canUserChangePassword($uid),
142
-			'activelanguage' => $activeLanguage,
143
-			'commonlanguages' => $commonLanguages,
144
-			'languages' => $languages,
145
-		] + $messageParameters;
116
+        $parameters = [
117
+            'total_space' => $totalSpace,
118
+            'usage' => \OC_Helper::humanFileSize($storageInfo['used']),
119
+            'usage_relative' => $storageInfo['relative'],
120
+            'quota' => $storageInfo['quota'],
121
+            'avatarChangeSupported' => \OC_User::canUserChangeAvatar($uid),
122
+            'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
123
+            'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'],
124
+            'displayNameChangeSupported' => \OC_User::canUserChangeDisplayName($uid),
125
+            'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'],
126
+            'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
127
+            'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'],
128
+            'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'],
129
+            'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'],
130
+            'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'],
131
+            'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'],
132
+            'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'],
133
+            'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'],
134
+            'website' =>  $userData[AccountManager::PROPERTY_WEBSITE]['value'],
135
+            'websiteScope' =>  $userData[AccountManager::PROPERTY_WEBSITE]['scope'],
136
+            'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'],
137
+            'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'],
138
+            'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'],
139
+            'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'],
140
+            'groups' => $this->getGroups($user),
141
+            'passwordChangeSupported' => \OC_User::canUserChangePassword($uid),
142
+            'activelanguage' => $activeLanguage,
143
+            'commonlanguages' => $commonLanguages,
144
+            'languages' => $languages,
145
+        ] + $messageParameters;
146 146
 
147 147
 
148
-		return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
149
-	}
148
+        return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
149
+    }
150 150
 
151
-	/**
152
-	 * @return string the section ID, e.g. 'sharing'
153
-	 * @since 9.1
154
-	 */
155
-	public function getSection() {
156
-		return 'personal-info';
157
-	}
151
+    /**
152
+     * @return string the section ID, e.g. 'sharing'
153
+     * @since 9.1
154
+     */
155
+    public function getSection() {
156
+        return 'personal-info';
157
+    }
158 158
 
159
-	/**
160
-	 * @return int whether the form should be rather on the top or bottom of
161
-	 * the admin section. The forms are arranged in ascending order of the
162
-	 * priority values. It is required to return a value between 0 and 100.
163
-	 *
164
-	 * E.g.: 70
165
-	 * @since 9.1
166
-	 */
167
-	public function getPriority() {
168
-		return 10;
169
-	}
159
+    /**
160
+     * @return int whether the form should be rather on the top or bottom of
161
+     * the admin section. The forms are arranged in ascending order of the
162
+     * priority values. It is required to return a value between 0 and 100.
163
+     *
164
+     * E.g.: 70
165
+     * @since 9.1
166
+     */
167
+    public function getPriority() {
168
+        return 10;
169
+    }
170 170
 
171
-	/**
172
-	 * returns a sorted list of the user's group GIDs
173
-	 *
174
-	 * @param IUser $user
175
-	 * @return array
176
-	 */
177
-	private function getGroups(IUser $user) {
178
-		$groups = array_map(
179
-			function(IGroup $group) {
180
-				return $group->getGID();
181
-			},
182
-			$this->groupManager->getUserGroups($user)
183
-		);
184
-		sort($groups);
171
+    /**
172
+     * returns a sorted list of the user's group GIDs
173
+     *
174
+     * @param IUser $user
175
+     * @return array
176
+     */
177
+    private function getGroups(IUser $user) {
178
+        $groups = array_map(
179
+            function(IGroup $group) {
180
+                return $group->getGID();
181
+            },
182
+            $this->groupManager->getUserGroups($user)
183
+        );
184
+        sort($groups);
185 185
 
186
-		return $groups;
187
-	}
186
+        return $groups;
187
+    }
188 188
 
189
-	/**
190
-	 * returns the user language, common language and other languages in an
191
-	 * associative array
192
-	 *
193
-	 * @param IUser $user
194
-	 * @return array
195
-	 */
196
-	private function getLanguages(IUser $user) {
197
-		$uid = $user->getUID();
189
+    /**
190
+     * returns the user language, common language and other languages in an
191
+     * associative array
192
+     *
193
+     * @param IUser $user
194
+     * @return array
195
+     */
196
+    private function getLanguages(IUser $user) {
197
+        $uid = $user->getUID();
198 198
 
199
-		$commonLanguages = [];
200
-		$userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
201
-		$languageCodes = $this->l10nFactory->findAvailableLanguages();
202
-		foreach($languageCodes as $lang) {
203
-			$l = \OC::$server->getL10N('settings', $lang);
204
-			// TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
205
-			$potentialName = (string) $l->t('__language_name__');
206
-			if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file
207
-				$ln = array('code' => $lang, 'name' => $potentialName);
208
-			} elseif ($lang === 'en') {
209
-				$ln = ['code' => $lang, 'name' => 'English (US)'];
210
-			}else{//fallback to language code
211
-				$ln=array('code'=>$lang, 'name'=>$lang);
212
-			}
199
+        $commonLanguages = [];
200
+        $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
201
+        $languageCodes = $this->l10nFactory->findAvailableLanguages();
202
+        foreach($languageCodes as $lang) {
203
+            $l = \OC::$server->getL10N('settings', $lang);
204
+            // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
205
+            $potentialName = (string) $l->t('__language_name__');
206
+            if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file
207
+                $ln = array('code' => $lang, 'name' => $potentialName);
208
+            } elseif ($lang === 'en') {
209
+                $ln = ['code' => $lang, 'name' => 'English (US)'];
210
+            }else{//fallback to language code
211
+                $ln=array('code'=>$lang, 'name'=>$lang);
212
+            }
213 213
 
214
-			// put appropriate languages into appropriate arrays, to print them sorted
215
-			// used language -> common languages -> divider -> other languages
216
-			if ($lang === $userLang) {
217
-				$userLang = $ln;
218
-			} elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) {
219
-				$commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln;
220
-			} else {
221
-				$languages[]=$ln;
222
-			}
223
-		}
214
+            // put appropriate languages into appropriate arrays, to print them sorted
215
+            // used language -> common languages -> divider -> other languages
216
+            if ($lang === $userLang) {
217
+                $userLang = $ln;
218
+            } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) {
219
+                $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln;
220
+            } else {
221
+                $languages[]=$ln;
222
+            }
223
+        }
224 224
 
225
-		// if user language is not available but set somehow: show the actual code as name
226
-		if (!is_array($userLang)) {
227
-			$userLang = [
228
-				'code' => $userLang,
229
-				'name' => $userLang,
230
-			];
231
-		}
225
+        // if user language is not available but set somehow: show the actual code as name
226
+        if (!is_array($userLang)) {
227
+            $userLang = [
228
+                'code' => $userLang,
229
+                'name' => $userLang,
230
+            ];
231
+        }
232 232
 
233
-		ksort($commonLanguages);
233
+        ksort($commonLanguages);
234 234
 
235
-		// sort now by displayed language not the iso-code
236
-		usort( $languages, function ($a, $b) {
237
-			if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
238
-				// If a doesn't have a name, but b does, list b before a
239
-				return 1;
240
-			}
241
-			if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) {
242
-				// If a does have a name, but b doesn't, list a before b
243
-				return -1;
244
-			}
245
-			// Otherwise compare the names
246
-			return strcmp($a['name'], $b['name']);
247
-		});
235
+        // sort now by displayed language not the iso-code
236
+        usort( $languages, function ($a, $b) {
237
+            if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
238
+                // If a doesn't have a name, but b does, list b before a
239
+                return 1;
240
+            }
241
+            if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) {
242
+                // If a does have a name, but b doesn't, list a before b
243
+                return -1;
244
+            }
245
+            // Otherwise compare the names
246
+            return strcmp($a['name'], $b['name']);
247
+        });
248 248
 
249
-		return [$userLang, $commonLanguages, $languages];
250
-	}
249
+        return [$userLang, $commonLanguages, $languages];
250
+    }
251 251
 
252
-	/**
253
-	 * @param array $userData
254
-	 * @return array
255
-	 */
256
-	private function getMessageParameters(array $userData) {
257
-		$needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER];
258
-		$messageParameters = [];
259
-		foreach ($needVerifyMessage as $property) {
260
-			switch ($userData[$property]['verified']) {
261
-				case AccountManager::VERIFIED:
262
-					$message = $this->l->t('Verifying');
263
-					break;
264
-				case AccountManager::VERIFICATION_IN_PROGRESS:
265
-					$message = $this->l->t('Verifying …');
266
-					break;
267
-				default:
268
-					$message = $this->l->t('Verify');
269
-			}
270
-			$messageParameters[$property . 'Message'] = $message;
271
-		}
272
-		return $messageParameters;
273
-	}
252
+    /**
253
+     * @param array $userData
254
+     * @return array
255
+     */
256
+    private function getMessageParameters(array $userData) {
257
+        $needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER];
258
+        $messageParameters = [];
259
+        foreach ($needVerifyMessage as $property) {
260
+            switch ($userData[$property]['verified']) {
261
+                case AccountManager::VERIFIED:
262
+                    $message = $this->l->t('Verifying');
263
+                    break;
264
+                case AccountManager::VERIFICATION_IN_PROGRESS:
265
+                    $message = $this->l->t('Verifying …');
266
+                    break;
267
+                default:
268
+                    $message = $this->l->t('Verify');
269
+            }
270
+            $messageParameters[$property . 'Message'] = $message;
271
+        }
272
+        return $messageParameters;
273
+    }
274 274
 
275 275
 }
Please login to merge, or discard this patch.
lib/private/Settings/Personal/Security.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -29,31 +29,31 @@
 block discarded – undo
29 29
 
30 30
 class Security implements ISettings {
31 31
 
32
-	/**
33
-	 * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
34
-	 * @since 9.1
35
-	 */
36
-	public function getForm() {
37
-		return new TemplateResponse('settings', 'settings/personal/security');
38
-	}
32
+    /**
33
+     * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
34
+     * @since 9.1
35
+     */
36
+    public function getForm() {
37
+        return new TemplateResponse('settings', 'settings/personal/security');
38
+    }
39 39
 
40
-	/**
41
-	 * @return string the section ID, e.g. 'sharing'
42
-	 * @since 9.1
43
-	 */
44
-	public function getSection() {
45
-		return 'security';
46
-	}
40
+    /**
41
+     * @return string the section ID, e.g. 'sharing'
42
+     * @since 9.1
43
+     */
44
+    public function getSection() {
45
+        return 'security';
46
+    }
47 47
 
48
-	/**
49
-	 * @return int whether the form should be rather on the top or bottom of
50
-	 * the admin section. The forms are arranged in ascending order of the
51
-	 * priority values. It is required to return a value between 0 and 100.
52
-	 *
53
-	 * E.g.: 70
54
-	 * @since 9.1
55
-	 */
56
-	public function getPriority() {
57
-		return 10;
58
-	}
48
+    /**
49
+     * @return int whether the form should be rather on the top or bottom of
50
+     * the admin section. The forms are arranged in ascending order of the
51
+     * priority values. It is required to return a value between 0 and 100.
52
+     *
53
+     * E.g.: 70
54
+     * @since 9.1
55
+     */
56
+    public function getPriority() {
57
+        return 10;
58
+    }
59 59
 }
Please login to merge, or discard this patch.