Passed
Push — master ( f0dd71...c56a27 )
by Christoph
11:49 queued 12s
created
apps/admin_audit/lib/AppInfo/Application.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -60,206 +60,206 @@
 block discarded – undo
60 60
 
61 61
 class Application extends App {
62 62
 
63
-	/** @var ILogger */
64
-	protected $logger;
65
-
66
-	public function __construct() {
67
-		parent::__construct('admin_audit');
68
-		$this->initLogger();
69
-	}
70
-
71
-	public function initLogger() {
72
-		$c = $this->getContainer()->getServer();
73
-		$config = $c->getConfig();
74
-
75
-		$default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
76
-		$logFile = $config->getAppValue('admin_audit', 'logfile', $default);
77
-		if($logFile === null) {
78
-			$this->logger = $c->getLogger();
79
-			return;
80
-		}
81
-		$this->logger = $c->getLogFactory()->getCustomLogger($logFile);
82
-
83
-	}
84
-
85
-	public function register() {
86
-		$this->registerHooks();
87
-	}
88
-
89
-	/**
90
-	 * Register hooks in order to log them
91
-	 */
92
-	protected function registerHooks() {
93
-		$this->userManagementHooks();
94
-		$this->groupHooks();
95
-		$this->authHooks();
96
-
97
-		$this->consoleHooks();
98
-		$this->appHooks();
99
-
100
-		$this->sharingHooks();
101
-
102
-		$this->fileHooks();
103
-		$this->trashbinHooks();
104
-		$this->versionsHooks();
105
-
106
-		$this->securityHooks();
107
-	}
108
-
109
-	protected function userManagementHooks() {
110
-		$userActions = new UserManagement($this->logger);
111
-
112
-		Util::connectHook('OC_User', 'post_createUser',	$userActions, 'create');
113
-		Util::connectHook('OC_User', 'post_deleteUser',	$userActions, 'delete');
114
-		Util::connectHook('OC_User', 'changeUser',	$userActions, 'change');
115
-
116
-		/** @var IUserSession|Session $userSession */
117
-		$userSession = $this->getContainer()->getServer()->getUserSession();
118
-		$userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']);
119
-		$userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']);
120
-		$userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']);
121
-	}
122
-
123
-	protected function groupHooks() {
124
-		$groupActions = new GroupManagement($this->logger);
125
-
126
-		/** @var IGroupManager|Manager $groupManager */
127
-		$groupManager = $this->getContainer()->getServer()->getGroupManager();
128
-		$groupManager->listen('\OC\Group', 'postRemoveUser',  [$groupActions, 'removeUser']);
129
-		$groupManager->listen('\OC\Group', 'postAddUser',  [$groupActions, 'addUser']);
130
-		$groupManager->listen('\OC\Group', 'postDelete',  [$groupActions, 'deleteGroup']);
131
-		$groupManager->listen('\OC\Group', 'postCreate',  [$groupActions, 'createGroup']);
132
-	}
133
-
134
-	protected function sharingHooks() {
135
-		$shareActions = new Sharing($this->logger);
136
-
137
-		Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared');
138
-		Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare');
139
-		Util::connectHook(Share::class, 'post_unshareFromSelf', $shareActions, 'unshare');
140
-		Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions');
141
-		Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword');
142
-		Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate');
143
-		Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed');
144
-	}
145
-
146
-	protected function authHooks() {
147
-		$authActions = new Auth($this->logger);
148
-
149
-		Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt');
150
-		Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful');
151
-		Util::connectHook('OC_User', 'logout', $authActions, 'logout');
152
-	}
153
-
154
-	protected function appHooks() {
155
-
156
-		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
157
-		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) {
158
-			$appActions = new AppManagement($this->logger);
159
-			$appActions->enableApp($event->getAppID());
160
-		});
161
-		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) {
162
-			$appActions = new AppManagement($this->logger);
163
-			$appActions->enableAppForGroups($event->getAppID(), $event->getGroups());
164
-		});
165
-		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) {
166
-			$appActions = new AppManagement($this->logger);
167
-			$appActions->disableApp($event->getAppID());
168
-		});
169
-
170
-	}
171
-
172
-	protected function consoleHooks() {
173
-		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
174
-		$eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) {
175
-			$appActions = new Console($this->logger);
176
-			$appActions->runCommand($event->getArguments());
177
-		});
178
-	}
179
-
180
-	protected function fileHooks() {
181
-		$fileActions = new Files($this->logger);
182
-		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
183
-		$eventDispatcher->addListener(
184
-			IPreview::EVENT,
185
-			function (GenericEvent $event) use ($fileActions) {
186
-				/** @var File $file */
187
-				$file = $event->getSubject();
188
-				$fileActions->preview([
189
-					'path' => mb_substr($file->getInternalPath(), 5),
190
-					'width' => $event->getArguments()['width'],
191
-					'height' => $event->getArguments()['height'],
192
-					'crop' => $event->getArguments()['crop'],
193
-					'mode'  => $event->getArguments()['mode']
194
-				]);
195
-			}
196
-		);
197
-
198
-		Util::connectHook(
199
-			Filesystem::CLASSNAME,
200
-			Filesystem::signal_post_rename,
201
-			$fileActions,
202
-			'rename'
203
-		);
204
-		Util::connectHook(
205
-			Filesystem::CLASSNAME,
206
-			Filesystem::signal_post_create,
207
-			$fileActions,
208
-			'create'
209
-		);
210
-		Util::connectHook(
211
-			Filesystem::CLASSNAME,
212
-			Filesystem::signal_post_copy,
213
-			$fileActions,
214
-			'copy'
215
-		);
216
-		Util::connectHook(
217
-			Filesystem::CLASSNAME,
218
-			Filesystem::signal_post_write,
219
-			$fileActions,
220
-			'write'
221
-		);
222
-		Util::connectHook(
223
-			Filesystem::CLASSNAME,
224
-			Filesystem::signal_post_update,
225
-			$fileActions,
226
-			'update'
227
-		);
228
-		Util::connectHook(
229
-			Filesystem::CLASSNAME,
230
-			Filesystem::signal_read,
231
-			$fileActions,
232
-			'read'
233
-		);
234
-		Util::connectHook(
235
-			Filesystem::CLASSNAME,
236
-			Filesystem::signal_delete,
237
-			$fileActions,
238
-			'delete'
239
-		);
240
-	}
241
-
242
-	protected function versionsHooks() {
243
-		$versionsActions = new Versions($this->logger);
244
-		Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback');
245
-		Util::connectHook('\OCP\Versions', 'delete',$versionsActions, 'delete');
246
-	}
247
-
248
-	protected function trashbinHooks() {
249
-		$trashActions = new Trashbin($this->logger);
250
-		Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete');
251
-		Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore');
252
-	}
253
-
254
-	protected function securityHooks() {
255
-		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
256
-		$eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) {
257
-			$security = new Security($this->logger);
258
-			$security->twofactorSuccess($event->getSubject(), $event->getArguments());
259
-		});
260
-		$eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) {
261
-			$security = new Security($this->logger);
262
-			$security->twofactorFailed($event->getSubject(), $event->getArguments());
263
-		});
264
-	}
63
+    /** @var ILogger */
64
+    protected $logger;
65
+
66
+    public function __construct() {
67
+        parent::__construct('admin_audit');
68
+        $this->initLogger();
69
+    }
70
+
71
+    public function initLogger() {
72
+        $c = $this->getContainer()->getServer();
73
+        $config = $c->getConfig();
74
+
75
+        $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
76
+        $logFile = $config->getAppValue('admin_audit', 'logfile', $default);
77
+        if($logFile === null) {
78
+            $this->logger = $c->getLogger();
79
+            return;
80
+        }
81
+        $this->logger = $c->getLogFactory()->getCustomLogger($logFile);
82
+
83
+    }
84
+
85
+    public function register() {
86
+        $this->registerHooks();
87
+    }
88
+
89
+    /**
90
+     * Register hooks in order to log them
91
+     */
92
+    protected function registerHooks() {
93
+        $this->userManagementHooks();
94
+        $this->groupHooks();
95
+        $this->authHooks();
96
+
97
+        $this->consoleHooks();
98
+        $this->appHooks();
99
+
100
+        $this->sharingHooks();
101
+
102
+        $this->fileHooks();
103
+        $this->trashbinHooks();
104
+        $this->versionsHooks();
105
+
106
+        $this->securityHooks();
107
+    }
108
+
109
+    protected function userManagementHooks() {
110
+        $userActions = new UserManagement($this->logger);
111
+
112
+        Util::connectHook('OC_User', 'post_createUser',	$userActions, 'create');
113
+        Util::connectHook('OC_User', 'post_deleteUser',	$userActions, 'delete');
114
+        Util::connectHook('OC_User', 'changeUser',	$userActions, 'change');
115
+
116
+        /** @var IUserSession|Session $userSession */
117
+        $userSession = $this->getContainer()->getServer()->getUserSession();
118
+        $userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']);
119
+        $userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']);
120
+        $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']);
121
+    }
122
+
123
+    protected function groupHooks() {
124
+        $groupActions = new GroupManagement($this->logger);
125
+
126
+        /** @var IGroupManager|Manager $groupManager */
127
+        $groupManager = $this->getContainer()->getServer()->getGroupManager();
128
+        $groupManager->listen('\OC\Group', 'postRemoveUser',  [$groupActions, 'removeUser']);
129
+        $groupManager->listen('\OC\Group', 'postAddUser',  [$groupActions, 'addUser']);
130
+        $groupManager->listen('\OC\Group', 'postDelete',  [$groupActions, 'deleteGroup']);
131
+        $groupManager->listen('\OC\Group', 'postCreate',  [$groupActions, 'createGroup']);
132
+    }
133
+
134
+    protected function sharingHooks() {
135
+        $shareActions = new Sharing($this->logger);
136
+
137
+        Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared');
138
+        Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare');
139
+        Util::connectHook(Share::class, 'post_unshareFromSelf', $shareActions, 'unshare');
140
+        Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions');
141
+        Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword');
142
+        Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate');
143
+        Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed');
144
+    }
145
+
146
+    protected function authHooks() {
147
+        $authActions = new Auth($this->logger);
148
+
149
+        Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt');
150
+        Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful');
151
+        Util::connectHook('OC_User', 'logout', $authActions, 'logout');
152
+    }
153
+
154
+    protected function appHooks() {
155
+
156
+        $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
157
+        $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) {
158
+            $appActions = new AppManagement($this->logger);
159
+            $appActions->enableApp($event->getAppID());
160
+        });
161
+        $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) {
162
+            $appActions = new AppManagement($this->logger);
163
+            $appActions->enableAppForGroups($event->getAppID(), $event->getGroups());
164
+        });
165
+        $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) {
166
+            $appActions = new AppManagement($this->logger);
167
+            $appActions->disableApp($event->getAppID());
168
+        });
169
+
170
+    }
171
+
172
+    protected function consoleHooks() {
173
+        $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
174
+        $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) {
175
+            $appActions = new Console($this->logger);
176
+            $appActions->runCommand($event->getArguments());
177
+        });
178
+    }
179
+
180
+    protected function fileHooks() {
181
+        $fileActions = new Files($this->logger);
182
+        $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
183
+        $eventDispatcher->addListener(
184
+            IPreview::EVENT,
185
+            function (GenericEvent $event) use ($fileActions) {
186
+                /** @var File $file */
187
+                $file = $event->getSubject();
188
+                $fileActions->preview([
189
+                    'path' => mb_substr($file->getInternalPath(), 5),
190
+                    'width' => $event->getArguments()['width'],
191
+                    'height' => $event->getArguments()['height'],
192
+                    'crop' => $event->getArguments()['crop'],
193
+                    'mode'  => $event->getArguments()['mode']
194
+                ]);
195
+            }
196
+        );
197
+
198
+        Util::connectHook(
199
+            Filesystem::CLASSNAME,
200
+            Filesystem::signal_post_rename,
201
+            $fileActions,
202
+            'rename'
203
+        );
204
+        Util::connectHook(
205
+            Filesystem::CLASSNAME,
206
+            Filesystem::signal_post_create,
207
+            $fileActions,
208
+            'create'
209
+        );
210
+        Util::connectHook(
211
+            Filesystem::CLASSNAME,
212
+            Filesystem::signal_post_copy,
213
+            $fileActions,
214
+            'copy'
215
+        );
216
+        Util::connectHook(
217
+            Filesystem::CLASSNAME,
218
+            Filesystem::signal_post_write,
219
+            $fileActions,
220
+            'write'
221
+        );
222
+        Util::connectHook(
223
+            Filesystem::CLASSNAME,
224
+            Filesystem::signal_post_update,
225
+            $fileActions,
226
+            'update'
227
+        );
228
+        Util::connectHook(
229
+            Filesystem::CLASSNAME,
230
+            Filesystem::signal_read,
231
+            $fileActions,
232
+            'read'
233
+        );
234
+        Util::connectHook(
235
+            Filesystem::CLASSNAME,
236
+            Filesystem::signal_delete,
237
+            $fileActions,
238
+            'delete'
239
+        );
240
+    }
241
+
242
+    protected function versionsHooks() {
243
+        $versionsActions = new Versions($this->logger);
244
+        Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback');
245
+        Util::connectHook('\OCP\Versions', 'delete',$versionsActions, 'delete');
246
+    }
247
+
248
+    protected function trashbinHooks() {
249
+        $trashActions = new Trashbin($this->logger);
250
+        Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete');
251
+        Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore');
252
+    }
253
+
254
+    protected function securityHooks() {
255
+        $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
256
+        $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) {
257
+            $security = new Security($this->logger);
258
+            $security->twofactorSuccess($event->getSubject(), $event->getArguments());
259
+        });
260
+        $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) {
261
+            $security = new Security($this->logger);
262
+            $security->twofactorFailed($event->getSubject(), $event->getArguments());
263
+        });
264
+    }
265 265
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
 		$c = $this->getContainer()->getServer();
73 73
 		$config = $c->getConfig();
74 74
 
75
-		$default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
75
+		$default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/audit.log';
76 76
 		$logFile = $config->getAppValue('admin_audit', 'logfile', $default);
77
-		if($logFile === null) {
77
+		if ($logFile === null) {
78 78
 			$this->logger = $c->getLogger();
79 79
 			return;
80 80
 		}
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 	protected function userManagementHooks() {
110 110
 		$userActions = new UserManagement($this->logger);
111 111
 
112
-		Util::connectHook('OC_User', 'post_createUser',	$userActions, 'create');
113
-		Util::connectHook('OC_User', 'post_deleteUser',	$userActions, 'delete');
114
-		Util::connectHook('OC_User', 'changeUser',	$userActions, 'change');
112
+		Util::connectHook('OC_User', 'post_createUser', $userActions, 'create');
113
+		Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete');
114
+		Util::connectHook('OC_User', 'changeUser', $userActions, 'change');
115 115
 
116 116
 		/** @var IUserSession|Session $userSession */
117 117
 		$userSession = $this->getContainer()->getServer()->getUserSession();
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 
126 126
 		/** @var IGroupManager|Manager $groupManager */
127 127
 		$groupManager = $this->getContainer()->getServer()->getGroupManager();
128
-		$groupManager->listen('\OC\Group', 'postRemoveUser',  [$groupActions, 'removeUser']);
129
-		$groupManager->listen('\OC\Group', 'postAddUser',  [$groupActions, 'addUser']);
130
-		$groupManager->listen('\OC\Group', 'postDelete',  [$groupActions, 'deleteGroup']);
131
-		$groupManager->listen('\OC\Group', 'postCreate',  [$groupActions, 'createGroup']);
128
+		$groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']);
129
+		$groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']);
130
+		$groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']);
131
+		$groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']);
132 132
 	}
133 133
 
134 134
 	protected function sharingHooks() {
@@ -154,15 +154,15 @@  discard block
 block discarded – undo
154 154
 	protected function appHooks() {
155 155
 
156 156
 		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
157
-		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) {
157
+		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function(ManagerEvent $event) {
158 158
 			$appActions = new AppManagement($this->logger);
159 159
 			$appActions->enableApp($event->getAppID());
160 160
 		});
161
-		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) {
161
+		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function(ManagerEvent $event) {
162 162
 			$appActions = new AppManagement($this->logger);
163 163
 			$appActions->enableAppForGroups($event->getAppID(), $event->getGroups());
164 164
 		});
165
-		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) {
165
+		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function(ManagerEvent $event) {
166 166
 			$appActions = new AppManagement($this->logger);
167 167
 			$appActions->disableApp($event->getAppID());
168 168
 		});
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 
172 172
 	protected function consoleHooks() {
173 173
 		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
174
-		$eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) {
174
+		$eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function(ConsoleEvent $event) {
175 175
 			$appActions = new Console($this->logger);
176 176
 			$appActions->runCommand($event->getArguments());
177 177
 		});
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
183 183
 		$eventDispatcher->addListener(
184 184
 			IPreview::EVENT,
185
-			function (GenericEvent $event) use ($fileActions) {
185
+			function(GenericEvent $event) use ($fileActions) {
186 186
 				/** @var File $file */
187 187
 				$file = $event->getSubject();
188 188
 				$fileActions->preview([
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	protected function versionsHooks() {
243 243
 		$versionsActions = new Versions($this->logger);
244 244
 		Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback');
245
-		Util::connectHook('\OCP\Versions', 'delete',$versionsActions, 'delete');
245
+		Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete');
246 246
 	}
247 247
 
248 248
 	protected function trashbinHooks() {
@@ -253,11 +253,11 @@  discard block
 block discarded – undo
253 253
 
254 254
 	protected function securityHooks() {
255 255
 		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
256
-		$eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) {
256
+		$eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function(GenericEvent $event) {
257 257
 			$security = new Security($this->logger);
258 258
 			$security->twofactorSuccess($event->getSubject(), $event->getArguments());
259 259
 		});
260
-		$eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) {
260
+		$eventDispatcher->addListener(IProvider::EVENT_FAILED, function(GenericEvent $event) {
261 261
 			$security = new Security($this->logger);
262 262
 			$security->twofactorFailed($event->getSubject(), $event->getArguments());
263 263
 		});
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/BackgroundJob/CheckBackupCodes.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -36,35 +36,35 @@
 block discarded – undo
36 36
 
37 37
 class CheckBackupCodes extends QueuedJob {
38 38
 
39
-	/** @var IUserManager */
40
-	private $userManager;
39
+    /** @var IUserManager */
40
+    private $userManager;
41 41
 
42
-	/** @var IJobList */
43
-	private $jobList;
42
+    /** @var IJobList */
43
+    private $jobList;
44 44
 
45
-	/** @var Manager */
46
-	private $registry;
45
+    /** @var Manager */
46
+    private $registry;
47 47
 
48
-	/** @var Manager */
49
-	private $twofactorManager;
48
+    /** @var Manager */
49
+    private $twofactorManager;
50 50
 
51
-	public function __construct(ITimeFactory $timeFactory, IUserManager $userManager, IJobList $jobList, Manager $twofactorManager, IRegistry $registry) {
52
-		parent::__construct($timeFactory);
53
-		$this->userManager = $userManager;
54
-		$this->jobList = $jobList;
55
-		$this->twofactorManager = $twofactorManager;
56
-		$this->registry = $registry;
57
-	}
51
+    public function __construct(ITimeFactory $timeFactory, IUserManager $userManager, IJobList $jobList, Manager $twofactorManager, IRegistry $registry) {
52
+        parent::__construct($timeFactory);
53
+        $this->userManager = $userManager;
54
+        $this->jobList = $jobList;
55
+        $this->twofactorManager = $twofactorManager;
56
+        $this->registry = $registry;
57
+    }
58 58
 
59
-	protected function run($argument) {
60
-		$this->userManager->callForSeenUsers(function (IUser $user) {
61
-			$providers = $this->registry->getProviderStates($user);
62
-			$isTwoFactorAuthenticated = $this->twofactorManager->isTwoFactorAuthenticated($user);
59
+    protected function run($argument) {
60
+        $this->userManager->callForSeenUsers(function (IUser $user) {
61
+            $providers = $this->registry->getProviderStates($user);
62
+            $isTwoFactorAuthenticated = $this->twofactorManager->isTwoFactorAuthenticated($user);
63 63
 
64
-			if ($isTwoFactorAuthenticated && isset($providers['backup_codes']) && $providers['backup_codes'] === false) {
65
-				$this->jobList->add(RememberBackupCodesJob::class, ['uid' => $user->getUID()]);
66
-			}
67
-		});
68
-	}
64
+            if ($isTwoFactorAuthenticated && isset($providers['backup_codes']) && $providers['backup_codes'] === false) {
65
+                $this->jobList->add(RememberBackupCodesJob::class, ['uid' => $user->getUID()]);
66
+            }
67
+        });
68
+    }
69 69
 
70 70
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
 	}
58 58
 
59 59
 	protected function run($argument) {
60
-		$this->userManager->callForSeenUsers(function (IUser $user) {
60
+		$this->userManager->callForSeenUsers(function(IUser $user) {
61 61
 			$providers = $this->registry->getProviderStates($user);
62 62
 			$isTwoFactorAuthenticated = $this->twofactorManager->isTwoFactorAuthenticated($user);
63 63
 
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/BackgroundJob/RememberBackupCodesJob.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -35,66 +35,66 @@
 block discarded – undo
35 35
 
36 36
 class RememberBackupCodesJob extends TimedJob {
37 37
 
38
-	/** @var IRegistry */
39
-	private $registry;
40
-
41
-	/** @var IUserManager */
42
-	private $userManager;
43
-
44
-	/** @var IManager */
45
-	private $notificationManager;
46
-
47
-	/** @var IJobList */
48
-	private $jobList;
49
-
50
-	public function __construct(IRegistry $registry,
51
-								IUserManager $userManager,
52
-								ITimeFactory $timeFactory,
53
-								IManager $notificationManager,
54
-								IJobList $jobList) {
55
-		parent::__construct($timeFactory);
56
-		$this->registry = $registry;
57
-		$this->userManager = $userManager;
58
-		$this->time = $timeFactory;
59
-		$this->notificationManager = $notificationManager;
60
-		$this->jobList = $jobList;
61
-
62
-		$this->setInterval(60*60*24*14);
63
-	}
64
-
65
-	protected function run($argument) {
66
-		$uid = $argument['uid'];
67
-		$user = $this->userManager->get($uid);
68
-
69
-		if ($user === null) {
70
-			// We can't run with an invalid user
71
-			return;
72
-		}
73
-
74
-		$providers = $this->registry->getProviderStates($user);
75
-		$state2fa = array_reduce($providers, function (bool $carry, bool $state) {
76
-			return $carry || $state;
77
-		}, false);
78
-
79
-		/*
38
+    /** @var IRegistry */
39
+    private $registry;
40
+
41
+    /** @var IUserManager */
42
+    private $userManager;
43
+
44
+    /** @var IManager */
45
+    private $notificationManager;
46
+
47
+    /** @var IJobList */
48
+    private $jobList;
49
+
50
+    public function __construct(IRegistry $registry,
51
+                                IUserManager $userManager,
52
+                                ITimeFactory $timeFactory,
53
+                                IManager $notificationManager,
54
+                                IJobList $jobList) {
55
+        parent::__construct($timeFactory);
56
+        $this->registry = $registry;
57
+        $this->userManager = $userManager;
58
+        $this->time = $timeFactory;
59
+        $this->notificationManager = $notificationManager;
60
+        $this->jobList = $jobList;
61
+
62
+        $this->setInterval(60*60*24*14);
63
+    }
64
+
65
+    protected function run($argument) {
66
+        $uid = $argument['uid'];
67
+        $user = $this->userManager->get($uid);
68
+
69
+        if ($user === null) {
70
+            // We can't run with an invalid user
71
+            return;
72
+        }
73
+
74
+        $providers = $this->registry->getProviderStates($user);
75
+        $state2fa = array_reduce($providers, function (bool $carry, bool $state) {
76
+            return $carry || $state;
77
+        }, false);
78
+
79
+        /*
80 80
 		 * If no provider is active or if the backup codes are already generate
81 81
 		 * we can remove the job
82 82
 		 */
83
-		if ($state2fa === false || (isset($providers['backup_codes']) && $providers['backup_codes'] === true)) {
84
-			// Backup codes already generated lets remove this job
85
-			$this->jobList->remove(self::class, $argument);
86
-			return;
87
-		}
88
-
89
-		$date = new \DateTime();
90
-		$date->setTimestamp($this->time->getTime());
91
-
92
-		$notification = $this->notificationManager->createNotification();
93
-		$notification->setApp('twofactor_backupcodes')
94
-			->setUser($user->getUID())
95
-			->setDateTime($date)
96
-			->setObject('create', 'codes')
97
-			->setSubject('create_backupcodes');
98
-		$this->notificationManager->notify($notification);
99
-	}
83
+        if ($state2fa === false || (isset($providers['backup_codes']) && $providers['backup_codes'] === true)) {
84
+            // Backup codes already generated lets remove this job
85
+            $this->jobList->remove(self::class, $argument);
86
+            return;
87
+        }
88
+
89
+        $date = new \DateTime();
90
+        $date->setTimestamp($this->time->getTime());
91
+
92
+        $notification = $this->notificationManager->createNotification();
93
+        $notification->setApp('twofactor_backupcodes')
94
+            ->setUser($user->getUID())
95
+            ->setDateTime($date)
96
+            ->setObject('create', 'codes')
97
+            ->setSubject('create_backupcodes');
98
+        $this->notificationManager->notify($notification);
99
+    }
100 100
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		$this->notificationManager = $notificationManager;
60 60
 		$this->jobList = $jobList;
61 61
 
62
-		$this->setInterval(60*60*24*14);
62
+		$this->setInterval(60 * 60 * 24 * 14);
63 63
 	}
64 64
 
65 65
 	protected function run($argument) {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		}
73 73
 
74 74
 		$providers = $this->registry->getProviderStates($user);
75
-		$state2fa = array_reduce($providers, function (bool $carry, bool $state) {
75
+		$state2fa = array_reduce($providers, function(bool $carry, bool $state) {
76 76
 			return $carry || $state;
77 77
 		}, false);
78 78
 
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/Provider/BackupCodesProvider.php 2 patches
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -41,129 +41,129 @@
 block discarded – undo
41 41
 
42 42
 class BackupCodesProvider implements IProvider, IProvidesPersonalSettings {
43 43
 
44
-	/** @var string */
45
-	private $appName;
46
-
47
-	/** @var BackupCodeStorage */
48
-	private $storage;
49
-
50
-	/** @var IL10N */
51
-	private $l10n;
52
-
53
-	/** @var AppManager */
54
-	private $appManager;
55
-	/** @var IInitialStateService */
56
-	private $initialStateService;
57
-
58
-	/**
59
-	 * @param string $appName
60
-	 * @param BackupCodeStorage $storage
61
-	 * @param IL10N $l10n
62
-	 * @param AppManager $appManager
63
-	 */
64
-	public function __construct(string $appName,
65
-								BackupCodeStorage $storage,
66
-								IL10N $l10n,
67
-								AppManager $appManager,
68
-								IInitialStateService $initialStateService) {
69
-		$this->appName = $appName;
70
-		$this->l10n = $l10n;
71
-		$this->storage = $storage;
72
-		$this->appManager = $appManager;
73
-		$this->initialStateService = $initialStateService;
74
-	}
75
-
76
-	/**
77
-	 * Get unique identifier of this 2FA provider
78
-	 *
79
-	 * @return string
80
-	 */
81
-	public function getId(): string {
82
-		return 'backup_codes';
83
-	}
84
-
85
-	/**
86
-	 * Get the display name for selecting the 2FA provider
87
-	 *
88
-	 * @return string
89
-	 */
90
-	public function getDisplayName(): string {
91
-		return $this->l10n->t('Backup code');
92
-	}
93
-
94
-	/**
95
-	 * Get the description for selecting the 2FA provider
96
-	 *
97
-	 * @return string
98
-	 */
99
-	public function getDescription(): string {
100
-		return $this->l10n->t('Use backup code');
101
-	}
102
-
103
-	/**
104
-	 * Get the template for rending the 2FA provider view
105
-	 *
106
-	 * @param IUser $user
107
-	 * @return Template
108
-	 */
109
-	public function getTemplate(IUser $user): Template {
110
-		return new Template('twofactor_backupcodes', 'challenge');
111
-	}
112
-
113
-	/**
114
-	 * Verify the given challenge
115
-	 *
116
-	 * @param IUser $user
117
-	 * @param string $challenge
118
-	 * @return bool
119
-	 */
120
-	public function verifyChallenge(IUser $user, string $challenge): bool {
121
-		return $this->storage->validateCode($user, $challenge);
122
-	}
123
-
124
-	/**
125
-	 * Decides whether 2FA is enabled for the given user
126
-	 *
127
-	 * @param IUser $user
128
-	 * @return boolean
129
-	 */
130
-	public function isTwoFactorAuthEnabledForUser(IUser $user): bool {
131
-		return $this->storage->hasBackupCodes($user);
132
-	}
133
-
134
-	/**
135
-	 * Determine whether backup codes should be active or not
136
-	 *
137
-	 * Backup codes only make sense if at least one 2FA provider is active,
138
-	 * hence this method checks all enabled apps on whether they provide 2FA
139
-	 * functionality or not. If there's at least one app, backup codes are
140
-	 * enabled on the personal settings page.
141
-	 *
142
-	 * @param IUser $user
143
-	 * @return boolean
144
-	 */
145
-	public function isActive(IUser $user): bool {
146
-		$appIds = array_filter($this->appManager->getEnabledAppsForUser($user), function ($appId) {
147
-			return $appId !== $this->appName;
148
-		});
149
-		foreach ($appIds as $appId) {
150
-			$info = $this->appManager->getAppInfo($appId);
151
-			if (isset($info['two-factor-providers']) && count($info['two-factor-providers']) > 0) {
152
-				return true;
153
-			}
154
-		}
155
-		return false;
156
-	}
157
-
158
-	/**
159
-	 * @param IUser $user
160
-	 *
161
-	 * @return IPersonalProviderSettings
162
-	 */
163
-	public function getPersonalSettings(IUser $user): IPersonalProviderSettings {
164
-		$state = $this->storage->getBackupCodesState($user);
165
-		$this->initialStateService->provideInitialState($this->appName, 'state', $state);
166
-		return new Personal();
167
-	}
44
+    /** @var string */
45
+    private $appName;
46
+
47
+    /** @var BackupCodeStorage */
48
+    private $storage;
49
+
50
+    /** @var IL10N */
51
+    private $l10n;
52
+
53
+    /** @var AppManager */
54
+    private $appManager;
55
+    /** @var IInitialStateService */
56
+    private $initialStateService;
57
+
58
+    /**
59
+     * @param string $appName
60
+     * @param BackupCodeStorage $storage
61
+     * @param IL10N $l10n
62
+     * @param AppManager $appManager
63
+     */
64
+    public function __construct(string $appName,
65
+                                BackupCodeStorage $storage,
66
+                                IL10N $l10n,
67
+                                AppManager $appManager,
68
+                                IInitialStateService $initialStateService) {
69
+        $this->appName = $appName;
70
+        $this->l10n = $l10n;
71
+        $this->storage = $storage;
72
+        $this->appManager = $appManager;
73
+        $this->initialStateService = $initialStateService;
74
+    }
75
+
76
+    /**
77
+     * Get unique identifier of this 2FA provider
78
+     *
79
+     * @return string
80
+     */
81
+    public function getId(): string {
82
+        return 'backup_codes';
83
+    }
84
+
85
+    /**
86
+     * Get the display name for selecting the 2FA provider
87
+     *
88
+     * @return string
89
+     */
90
+    public function getDisplayName(): string {
91
+        return $this->l10n->t('Backup code');
92
+    }
93
+
94
+    /**
95
+     * Get the description for selecting the 2FA provider
96
+     *
97
+     * @return string
98
+     */
99
+    public function getDescription(): string {
100
+        return $this->l10n->t('Use backup code');
101
+    }
102
+
103
+    /**
104
+     * Get the template for rending the 2FA provider view
105
+     *
106
+     * @param IUser $user
107
+     * @return Template
108
+     */
109
+    public function getTemplate(IUser $user): Template {
110
+        return new Template('twofactor_backupcodes', 'challenge');
111
+    }
112
+
113
+    /**
114
+     * Verify the given challenge
115
+     *
116
+     * @param IUser $user
117
+     * @param string $challenge
118
+     * @return bool
119
+     */
120
+    public function verifyChallenge(IUser $user, string $challenge): bool {
121
+        return $this->storage->validateCode($user, $challenge);
122
+    }
123
+
124
+    /**
125
+     * Decides whether 2FA is enabled for the given user
126
+     *
127
+     * @param IUser $user
128
+     * @return boolean
129
+     */
130
+    public function isTwoFactorAuthEnabledForUser(IUser $user): bool {
131
+        return $this->storage->hasBackupCodes($user);
132
+    }
133
+
134
+    /**
135
+     * Determine whether backup codes should be active or not
136
+     *
137
+     * Backup codes only make sense if at least one 2FA provider is active,
138
+     * hence this method checks all enabled apps on whether they provide 2FA
139
+     * functionality or not. If there's at least one app, backup codes are
140
+     * enabled on the personal settings page.
141
+     *
142
+     * @param IUser $user
143
+     * @return boolean
144
+     */
145
+    public function isActive(IUser $user): bool {
146
+        $appIds = array_filter($this->appManager->getEnabledAppsForUser($user), function ($appId) {
147
+            return $appId !== $this->appName;
148
+        });
149
+        foreach ($appIds as $appId) {
150
+            $info = $this->appManager->getAppInfo($appId);
151
+            if (isset($info['two-factor-providers']) && count($info['two-factor-providers']) > 0) {
152
+                return true;
153
+            }
154
+        }
155
+        return false;
156
+    }
157
+
158
+    /**
159
+     * @param IUser $user
160
+     *
161
+     * @return IPersonalProviderSettings
162
+     */
163
+    public function getPersonalSettings(IUser $user): IPersonalProviderSettings {
164
+        $state = $this->storage->getBackupCodesState($user);
165
+        $this->initialStateService->provideInitialState($this->appName, 'state', $state);
166
+        return new Personal();
167
+    }
168 168
 
169 169
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@
 block discarded – undo
143 143
 	 * @return boolean
144 144
 	 */
145 145
 	public function isActive(IUser $user): bool {
146
-		$appIds = array_filter($this->appManager->getEnabledAppsForUser($user), function ($appId) {
146
+		$appIds = array_filter($this->appManager->getEnabledAppsForUser($user), function($appId) {
147 147
 			return $appId !== $this->appName;
148 148
 		});
149 149
 		foreach ($appIds as $appId) {
Please login to merge, or discard this patch.
apps/federation/lib/SyncJob.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -30,32 +30,32 @@
 block discarded – undo
30 30
 
31 31
 class SyncJob extends TimedJob {
32 32
 
33
-	/** @var SyncFederationAddressBooks */
34
-	protected $syncService;
33
+    /** @var SyncFederationAddressBooks */
34
+    protected $syncService;
35 35
 
36
-	/** @var ILogger */
37
-	protected $logger;
36
+    /** @var ILogger */
37
+    protected $logger;
38 38
 
39
-	/**
40
-	 * @param SyncFederationAddressBooks $syncService
41
-	 * @param ILogger $logger
42
-	 */
43
-	public function __construct(SyncFederationAddressBooks $syncService, ILogger $logger) {
44
-		// Run once a day
45
-		$this->setInterval(24 * 60 * 60);
46
-		$this->syncService = $syncService;
47
-		$this->logger = $logger;
48
-	}
39
+    /**
40
+     * @param SyncFederationAddressBooks $syncService
41
+     * @param ILogger $logger
42
+     */
43
+    public function __construct(SyncFederationAddressBooks $syncService, ILogger $logger) {
44
+        // Run once a day
45
+        $this->setInterval(24 * 60 * 60);
46
+        $this->syncService = $syncService;
47
+        $this->logger = $logger;
48
+    }
49 49
 
50
-	protected function run($argument) {
51
-		$this->syncService->syncThemAll(function ($url, $ex) {
52
-			if ($ex instanceof \Exception) {
53
-				$this->logger->logException($ex, [
54
-					'message' => "Error while syncing $url.",
55
-					'level' => ILogger::INFO,
56
-					'app' => 'fed-sync',
57
-				]);
58
-			}
59
-		});
60
-	}
50
+    protected function run($argument) {
51
+        $this->syncService->syncThemAll(function ($url, $ex) {
52
+            if ($ex instanceof \Exception) {
53
+                $this->logger->logException($ex, [
54
+                    'message' => "Error while syncing $url.",
55
+                    'level' => ILogger::INFO,
56
+                    'app' => 'fed-sync',
57
+                ]);
58
+            }
59
+        });
60
+    }
61 61
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
 	}
49 49
 
50 50
 	protected function run($argument) {
51
-		$this->syncService->syncThemAll(function ($url, $ex) {
51
+		$this->syncService->syncThemAll(function($url, $ex) {
52 52
 			if ($ex instanceof \Exception) {
53 53
 				$this->logger->logException($ex, [
54 54
 					'message' => "Error while syncing $url.",
Please login to merge, or discard this patch.
apps/federation/lib/AppInfo/Application.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -38,48 +38,48 @@
 block discarded – undo
38 38
 
39 39
 class Application extends App {
40 40
 
41
-	/**
42
-	 * @param array $urlParams
43
-	 */
44
-	public function __construct($urlParams = []) {
45
-		parent::__construct('federation', $urlParams);
46
-		$this->registerMiddleware();
47
-	}
41
+    /**
42
+     * @param array $urlParams
43
+     */
44
+    public function __construct($urlParams = []) {
45
+        parent::__construct('federation', $urlParams);
46
+        $this->registerMiddleware();
47
+    }
48 48
 
49
-	private function registerMiddleware() {
50
-		$container = $this->getContainer();
51
-		$container->registerAlias('AddServerMiddleware', AddServerMiddleware::class);
52
-		$container->registerMiddleWare('AddServerMiddleware');
53
-	}
49
+    private function registerMiddleware() {
50
+        $container = $this->getContainer();
51
+        $container->registerAlias('AddServerMiddleware', AddServerMiddleware::class);
52
+        $container->registerMiddleWare('AddServerMiddleware');
53
+    }
54 54
 
55
-	/**
56
-	 * listen to federated_share_added hooks to auto-add new servers to the
57
-	 * list of trusted servers.
58
-	 */
59
-	public function registerHooks() {
55
+    /**
56
+     * listen to federated_share_added hooks to auto-add new servers to the
57
+     * list of trusted servers.
58
+     */
59
+    public function registerHooks() {
60 60
 
61
-		$container = $this->getContainer();
62
-		$hooksManager = $container->query(Hooks::class);
61
+        $container = $this->getContainer();
62
+        $hooksManager = $container->query(Hooks::class);
63 63
 
64
-		Util::connectHook(
65
-				Share::class,
66
-				'federated_share_added',
67
-				$hooksManager,
68
-				'addServerHook'
69
-		);
64
+        Util::connectHook(
65
+                Share::class,
66
+                'federated_share_added',
67
+                $hooksManager,
68
+                'addServerHook'
69
+        );
70 70
 
71
-		$dispatcher = $container->getServer()->getEventDispatcher();
72
-		$dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function ($event) use ($container) {
73
-			if ($event instanceof SabrePluginEvent) {
74
-				$server = $event->getServer();
75
-				if ($server instanceof Server) {
76
-					$authPlugin = $server->getPlugin('auth');
77
-					if ($authPlugin instanceof Plugin) {
78
-						$authPlugin->addBackend($container->query(FedAuth::class));
79
-					}
80
-				}
81
-			}
82
-		});
83
-	}
71
+        $dispatcher = $container->getServer()->getEventDispatcher();
72
+        $dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function ($event) use ($container) {
73
+            if ($event instanceof SabrePluginEvent) {
74
+                $server = $event->getServer();
75
+                if ($server instanceof Server) {
76
+                    $authPlugin = $server->getPlugin('auth');
77
+                    if ($authPlugin instanceof Plugin) {
78
+                        $authPlugin->addBackend($container->query(FedAuth::class));
79
+                    }
80
+                }
81
+            }
82
+        });
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@
 block discarded – undo
69 69
 		);
70 70
 
71 71
 		$dispatcher = $container->getServer()->getEventDispatcher();
72
-		$dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function ($event) use ($container) {
72
+		$dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function($event) use ($container) {
73 73
 			if ($event instanceof SabrePluginEvent) {
74 74
 				$server = $event->getServer();
75 75
 				if ($server instanceof Server) {
Please login to merge, or discard this patch.
apps/federation/lib/Command/SyncFederationAddressBooks.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -33,45 +33,45 @@
 block discarded – undo
33 33
 
34 34
 class SyncFederationAddressBooks extends Command {
35 35
 
36
-	/** @var \OCA\Federation\SyncFederationAddressBooks */
37
-	private $syncService;
36
+    /** @var \OCA\Federation\SyncFederationAddressBooks */
37
+    private $syncService;
38 38
 
39
-	/**
40
-	 * @param \OCA\Federation\SyncFederationAddressBooks $syncService
41
-	 */
42
-	public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) {
43
-		parent::__construct();
39
+    /**
40
+     * @param \OCA\Federation\SyncFederationAddressBooks $syncService
41
+     */
42
+    public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) {
43
+        parent::__construct();
44 44
 
45
-		$this->syncService = $syncService;
46
-	}
45
+        $this->syncService = $syncService;
46
+    }
47 47
 
48
-	protected function configure() {
49
-		$this
50
-			->setName('federation:sync-addressbooks')
51
-			->setDescription('Synchronizes addressbooks of all federated clouds');
52
-	}
48
+    protected function configure() {
49
+        $this
50
+            ->setName('federation:sync-addressbooks')
51
+            ->setDescription('Synchronizes addressbooks of all federated clouds');
52
+    }
53 53
 
54
-	/**
55
-	 * @param InputInterface $input
56
-	 * @param OutputInterface $output
57
-	 * @return int
58
-	 */
59
-	protected function execute(InputInterface $input, OutputInterface $output) {
54
+    /**
55
+     * @param InputInterface $input
56
+     * @param OutputInterface $output
57
+     * @return int
58
+     */
59
+    protected function execute(InputInterface $input, OutputInterface $output) {
60 60
 
61
-		$progress = new ProgressBar($output);
62
-		$progress->start();
63
-		$this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output) {
64
-			if ($ex instanceof \Exception) {
65
-				$output->writeln("Error while syncing $url : " . $ex->getMessage());
61
+        $progress = new ProgressBar($output);
62
+        $progress->start();
63
+        $this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output) {
64
+            if ($ex instanceof \Exception) {
65
+                $output->writeln("Error while syncing $url : " . $ex->getMessage());
66 66
 
67
-			} else {
68
-				$progress->advance();
69
-			}
70
-		});
67
+            } else {
68
+                $progress->advance();
69
+            }
70
+        });
71 71
 
72
-		$progress->finish();
73
-		$output->writeln('');
72
+        $progress->finish();
73
+        $output->writeln('');
74 74
 
75
-		return 0;
76
-	}
75
+        return 0;
76
+    }
77 77
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -60,9 +60,9 @@
 block discarded – undo
60 60
 
61 61
 		$progress = new ProgressBar($output);
62 62
 		$progress->start();
63
-		$this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output) {
63
+		$this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) {
64 64
 			if ($ex instanceof \Exception) {
65
-				$output->writeln("Error while syncing $url : " . $ex->getMessage());
65
+				$output->writeln("Error while syncing $url : ".$ex->getMessage());
66 66
 
67 67
 			} else {
68 68
 				$progress->advance();
Please login to merge, or discard this patch.
apps/files_external/templates/settings.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,51 +1,51 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	use \OCA\Files_External\Lib\Backend\Backend;
3
-	use \OCA\Files_External\Lib\Auth\AuthMechanism;
4
-	use \OCA\Files_External\Lib\DefinitionParameter;
5
-	use \OCA\Files_External\Service\BackendService;
2
+    use \OCA\Files_External\Lib\Backend\Backend;
3
+    use \OCA\Files_External\Lib\Auth\AuthMechanism;
4
+    use \OCA\Files_External\Lib\DefinitionParameter;
5
+    use \OCA\Files_External\Service\BackendService;
6 6
 
7
-	$canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting'];
7
+    $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting'];
8 8
 
9
-	$l->t("Enable encryption");
10
-	$l->t("Enable previews");
11
-	$l->t("Enable sharing");
12
-	$l->t("Check for changes");
13
-	$l->t("Never");
14
-	$l->t("Once every direct access");
15
-	$l->t('Read only');
9
+    $l->t("Enable encryption");
10
+    $l->t("Enable previews");
11
+    $l->t("Enable sharing");
12
+    $l->t("Check for changes");
13
+    $l->t("Never");
14
+    $l->t("Once every direct access");
15
+    $l->t('Read only');
16 16
 
17
-	script('files_external', [
18
-		'settings',
19
-		'templates'
20
-	]);
21
-	style('files_external', 'settings');
17
+    script('files_external', [
18
+        'settings',
19
+        'templates'
20
+    ]);
21
+    style('files_external', 'settings');
22 22
 
23
-	// load custom JS
24
-	foreach ($_['backends'] as $backend) {
25
-		/** @var Backend $backend */
26
-		$scripts = $backend->getCustomJs();
27
-		foreach ($scripts as $script) {
28
-			script('files_external', $script);
29
-		}
30
-	}
31
-	foreach ($_['authMechanisms'] as $authMechanism) {
32
-		/** @var AuthMechanism $authMechanism */
33
-		$scripts = $authMechanism->getCustomJs();
34
-		foreach ($scripts as $script) {
35
-			script('files_external', $script);
36
-		}
37
-	}
23
+    // load custom JS
24
+    foreach ($_['backends'] as $backend) {
25
+        /** @var Backend $backend */
26
+        $scripts = $backend->getCustomJs();
27
+        foreach ($scripts as $script) {
28
+            script('files_external', $script);
29
+        }
30
+    }
31
+    foreach ($_['authMechanisms'] as $authMechanism) {
32
+        /** @var AuthMechanism $authMechanism */
33
+        $scripts = $authMechanism->getCustomJs();
34
+        foreach ($scripts as $script) {
35
+            script('files_external', $script);
36
+        }
37
+    }
38 38
 
39
-	function writeParameterInput($parameter, $options, $classes = []) {
40
-		$value = '';
41
-		if (isset($options[$parameter->getName()])) {
42
-			$value = $options[$parameter->getName()];
43
-		}
44
-		$placeholder = $parameter->getText();
45
-		$is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL);
39
+    function writeParameterInput($parameter, $options, $classes = []) {
40
+        $value = '';
41
+        if (isset($options[$parameter->getName()])) {
42
+            $value = $options[$parameter->getName()];
43
+        }
44
+        $placeholder = $parameter->getText();
45
+        $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL);
46 46
 
47
-		switch ($parameter->getType()) {
48
-		case DefinitionParameter::VALUE_PASSWORD: ?>
47
+        switch ($parameter->getType()) {
48
+        case DefinitionParameter::VALUE_PASSWORD: ?>
49 49
 			<?php if ($is_optional) { $classes[] = 'optional'; } ?>
50 50
 			<input type="password"
51 51
 				<?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?>
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 				placeholder="<?php p($placeholder); ?>"
55 55
 			/>
56 56
 			<?php
57
-			break;
58
-		case DefinitionParameter::VALUE_BOOLEAN: ?>
57
+            break;
58
+        case DefinitionParameter::VALUE_BOOLEAN: ?>
59 59
 			<?php $checkboxId = uniqid("checkbox_"); ?>
60 60
 			<div>
61 61
 			<label>
@@ -69,16 +69,16 @@  discard block
 block discarded – undo
69 69
 			</label>
70 70
 			</div>
71 71
 			<?php
72
-			break;
73
-		case DefinitionParameter::VALUE_HIDDEN: ?>
72
+            break;
73
+        case DefinitionParameter::VALUE_HIDDEN: ?>
74 74
 			<input type="hidden"
75 75
 				<?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?>
76 76
 				data-parameter="<?php p($parameter->getName()); ?>"
77 77
 				value="<?php p($value); ?>"
78 78
 			/>
79 79
 			<?php
80
-			break;
81
-		default: ?>
80
+            break;
81
+        default: ?>
82 82
 			<?php if ($is_optional) { $classes[] = 'optional'; } ?>
83 83
 			<input type="text"
84 84
 				<?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?>
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 				placeholder="<?php p($placeholder); ?>"
88 88
 			/>
89 89
 			<?php
90
-		}
91
-	}
90
+        }
91
+    }
92 92
 ?>
93 93
 
94 94
 <div id="emptycontent" class="hidden">
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
 							<?php p($l->t('Add storage')); ?>
135 135
 						</option>
136 136
 						<?php
137
-							$sortedBackends = array_filter($_['backends'], function ($backend) use ($_) {
138
-								return $backend->isVisibleFor($_['visibilityType']);
139
-							});
140
-							uasort($sortedBackends, function ($a, $b) {
141
-								return strcasecmp($a->getText(), $b->getText());
142
-							});
143
-						?>
137
+                            $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) {
138
+                                return $backend->isVisibleFor($_['visibilityType']);
139
+                            });
140
+                            uasort($sortedBackends, function ($a, $b) {
141
+                                return strcasecmp($a->getText(), $b->getText());
142
+                            });
143
+                        ?>
144 144
 						<?php foreach ($sortedBackends as $backend): ?>
145 145
 							<?php if ($backend->getDeprecateTo()) continue; // ignore deprecated backends ?>
146 146
 							<option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option>
@@ -172,10 +172,10 @@  discard block
 block discarded – undo
172 172
 
173 173
 		<p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>>
174 174
 			<?php
175
-				$userBackends = array_filter($_['backends'], function ($backend) {
176
-					return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL);
177
-				});
178
-			?>
175
+                $userBackends = array_filter($_['backends'], function ($backend) {
176
+                    return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL);
177
+                });
178
+            ?>
179 179
 			<?php $i = 0; foreach ($userBackends as $backend): ?>
180 180
 				<?php if ($deprecateTo = $backend->getDeprecateTo()): ?>
181 181
 					<input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" />
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
 	<h2><?php p($l->t('No external storage configured or you don\'t have the permission to configure them')); ?></h2>
97 97
 </div>
98 98
 
99
-<form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>">
99
+<form data-can-create="<?php echo $canCreateMounts ? 'true' : 'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled'] ? 'true' : 'false'; ?>">
100 100
 	<h2 class="inlineblock" data-anchor-name="external-storage"><?php p($l->t('External storages')); ?></h2>
101
-	<a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation'));?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a>
101
+	<a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation')); ?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a>
102 102
 	<p class="settings-hint"><?php p($l->t('External storage enables you to mount external storage services and devices as secondary Nextcloud storage devices. You may also allow users to mount their own external storage services.')); ?></p>
103 103
 	<?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) print_unescaped(''.$_['dependencies'].''); ?>
104 104
 	<table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'>
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
 							<?php p($l->t('Add storage')); ?>
135 135
 						</option>
136 136
 						<?php
137
-							$sortedBackends = array_filter($_['backends'], function ($backend) use ($_) {
137
+							$sortedBackends = array_filter($_['backends'], function($backend) use ($_) {
138 138
 								return $backend->isVisibleFor($_['visibilityType']);
139 139
 							});
140
-							uasort($sortedBackends, function ($a, $b) {
140
+							uasort($sortedBackends, function($a, $b) {
141 141
 								return strcasecmp($a->getText(), $b->getText());
142 142
 							});
143 143
 						?>
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 
173 173
 		<p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>>
174 174
 			<?php
175
-				$userBackends = array_filter($_['backends'], function ($backend) {
175
+				$userBackends = array_filter($_['backends'], function($backend) {
176 176
 					return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL);
177 177
 				});
178 178
 			?>
Please login to merge, or discard this patch.
apps/files_external/lib/Service/BackendService.php 2 patches
Indentation   +326 added lines, -326 removed lines patch added patch discarded remove patch
@@ -40,330 +40,330 @@
 block discarded – undo
40 40
  */
41 41
 class BackendService {
42 42
 
43
-	/** Visibility constants for VisibilityTrait */
44
-	const VISIBILITY_NONE = 0;
45
-	const VISIBILITY_PERSONAL = 1;
46
-	const VISIBILITY_ADMIN = 2;
47
-	//const VISIBILITY_ALIENS = 4;
48
-
49
-	const VISIBILITY_DEFAULT = 3; // PERSONAL | ADMIN
50
-
51
-	/** Priority constants for PriorityTrait */
52
-	const PRIORITY_DEFAULT = 100;
53
-
54
-	/** @var IConfig */
55
-	protected $config;
56
-
57
-	/** @var bool */
58
-	private $userMountingAllowed = true;
59
-
60
-	/** @var string[] */
61
-	private $userMountingBackends = [];
62
-
63
-	/** @var Backend[] */
64
-	private $backends = [];
65
-
66
-	/** @var IBackendProvider[] */
67
-	private $backendProviders = [];
68
-
69
-	/** @var AuthMechanism[] */
70
-	private $authMechanisms = [];
71
-
72
-	/** @var IAuthMechanismProvider[] */
73
-	private $authMechanismProviders = [];
74
-
75
-	/** @var callable[] */
76
-	private $configHandlerLoaders = [];
77
-
78
-	private $configHandlers = [];
79
-
80
-	/**
81
-	 * @param IConfig $config
82
-	 */
83
-	public function __construct(
84
-		IConfig $config
85
-	) {
86
-		$this->config = $config;
87
-
88
-		// Load config values
89
-		if ($this->config->getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') {
90
-			$this->userMountingAllowed = false;
91
-		}
92
-		$this->userMountingBackends = explode(',',
93
-			$this->config->getAppValue('files_external', 'user_mounting_backends', '')
94
-		);
95
-
96
-		// if no backend is in the list an empty string is in the array and user mounting is disabled
97
-		if ($this->userMountingBackends === ['']) {
98
-			$this->userMountingAllowed = false;
99
-		}
100
-	}
101
-
102
-	/**
103
-	 * Register a backend provider
104
-	 *
105
-	 * @since 9.1.0
106
-	 * @param IBackendProvider $provider
107
-	 */
108
-	public function registerBackendProvider(IBackendProvider $provider) {
109
-		$this->backendProviders[] = $provider;
110
-	}
111
-
112
-	private function callForRegistrations() {
113
-		static $eventSent = false;
114
-		if(!$eventSent) {
115
-			\OC::$server->getEventDispatcher()->dispatch(
116
-				'OCA\\Files_External::loadAdditionalBackends',
117
-				new GenericEvent()
118
-			);
119
-			$eventSent = true;
120
-		}
121
-	}
122
-
123
-	private function loadBackendProviders() {
124
-		$this->callForRegistrations();
125
-		foreach ($this->backendProviders as $provider) {
126
-			$this->registerBackends($provider->getBackends());
127
-		}
128
-		$this->backendProviders = [];
129
-	}
130
-
131
-	/**
132
-	 * Register an auth mechanism provider
133
-	 *
134
-	 * @since 9.1.0
135
-	 * @param IAuthMechanismProvider $provider
136
-	 */
137
-	public function registerAuthMechanismProvider(IAuthMechanismProvider $provider) {
138
-		$this->authMechanismProviders[] = $provider;
139
-	}
140
-
141
-	private function loadAuthMechanismProviders() {
142
-		$this->callForRegistrations();
143
-		foreach ($this->authMechanismProviders as $provider) {
144
-			$this->registerAuthMechanisms($provider->getAuthMechanisms());
145
-		}
146
-		$this->authMechanismProviders = [];
147
-	}
148
-
149
-	/**
150
-	 * Register a backend
151
-	 *
152
-	 * @deprecated 9.1.0 use registerBackendProvider()
153
-	 * @param Backend $backend
154
-	 */
155
-	public function registerBackend(Backend $backend) {
156
-		if (!$this->isAllowedUserBackend($backend)) {
157
-			$backend->removeVisibility(BackendService::VISIBILITY_PERSONAL);
158
-		}
159
-		foreach ($backend->getIdentifierAliases() as $alias) {
160
-			$this->backends[$alias] = $backend;
161
-		}
162
-	}
163
-
164
-	/**
165
-	 * @deprecated 9.1.0 use registerBackendProvider()
166
-	 * @param Backend[] $backends
167
-	 */
168
-	public function registerBackends(array $backends) {
169
-		foreach ($backends as $backend) {
170
-			$this->registerBackend($backend);
171
-		}
172
-	}
173
-	/**
174
-	 * Register an authentication mechanism
175
-	 *
176
-	 * @deprecated 9.1.0 use registerAuthMechanismProvider()
177
-	 * @param AuthMechanism $authMech
178
-	 */
179
-	public function registerAuthMechanism(AuthMechanism $authMech) {
180
-		if (!$this->isAllowedAuthMechanism($authMech)) {
181
-			$authMech->removeVisibility(BackendService::VISIBILITY_PERSONAL);
182
-		}
183
-		foreach ($authMech->getIdentifierAliases() as $alias) {
184
-			$this->authMechanisms[$alias] = $authMech;
185
-		}
186
-	}
187
-
188
-	/**
189
-	 * @deprecated 9.1.0 use registerAuthMechanismProvider()
190
-	 * @param AuthMechanism[] $mechanisms
191
-	 */
192
-	public function registerAuthMechanisms(array $mechanisms) {
193
-		foreach ($mechanisms as $mechanism) {
194
-			$this->registerAuthMechanism($mechanism);
195
-		}
196
-	}
197
-
198
-	/**
199
-	 * Get all backends
200
-	 *
201
-	 * @return Backend[]
202
-	 */
203
-	public function getBackends() {
204
-		$this->loadBackendProviders();
205
-		// only return real identifiers, no aliases
206
-		$backends = [];
207
-		foreach ($this->backends as $backend) {
208
-			$backends[$backend->getIdentifier()] = $backend;
209
-		}
210
-		return $backends;
211
-	}
212
-
213
-	/**
214
-	 * Get all available backends
215
-	 *
216
-	 * @return Backend[]
217
-	 */
218
-	public function getAvailableBackends() {
219
-		return array_filter($this->getBackends(), function ($backend) {
220
-			return !$backend->checkDependencies();
221
-		});
222
-	}
223
-
224
-	/**
225
-	 * @param string $identifier
226
-	 * @return Backend|null
227
-	 */
228
-	public function getBackend($identifier) {
229
-		$this->loadBackendProviders();
230
-		if (isset($this->backends[$identifier])) {
231
-			return $this->backends[$identifier];
232
-		}
233
-		return null;
234
-	}
235
-
236
-	/**
237
-	 * Get all authentication mechanisms
238
-	 *
239
-	 * @return AuthMechanism[]
240
-	 */
241
-	public function getAuthMechanisms() {
242
-		$this->loadAuthMechanismProviders();
243
-		// only return real identifiers, no aliases
244
-		$mechanisms = [];
245
-		foreach ($this->authMechanisms as $mechanism) {
246
-			$mechanisms[$mechanism->getIdentifier()] = $mechanism;
247
-		}
248
-		return $mechanisms;
249
-	}
250
-
251
-	/**
252
-	 * Get all authentication mechanisms for schemes
253
-	 *
254
-	 * @param string[] $schemes
255
-	 * @return AuthMechanism[]
256
-	 */
257
-	public function getAuthMechanismsByScheme(array $schemes) {
258
-		return array_filter($this->getAuthMechanisms(), function ($authMech) use ($schemes) {
259
-			return in_array($authMech->getScheme(), $schemes, true);
260
-		});
261
-	}
262
-
263
-	/**
264
-	 * @param string $identifier
265
-	 * @return AuthMechanism|null
266
-	 */
267
-	public function getAuthMechanism($identifier) {
268
-		$this->loadAuthMechanismProviders();
269
-		if (isset($this->authMechanisms[$identifier])) {
270
-			return $this->authMechanisms[$identifier];
271
-		}
272
-		return null;
273
-	}
274
-
275
-	/**
276
-	 * @return bool
277
-	 */
278
-	public function isUserMountingAllowed() {
279
-		return $this->userMountingAllowed;
280
-	}
281
-
282
-	/**
283
-	 * Check a backend if a user is allowed to mount it
284
-	 *
285
-	 * @param Backend $backend
286
-	 * @return bool
287
-	 */
288
-	protected function isAllowedUserBackend(Backend $backend) {
289
-		if ($this->userMountingAllowed &&
290
-			array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends)
291
-		) {
292
-			return true;
293
-		}
294
-		return false;
295
-	}
296
-
297
-	/**
298
-	 * Check an authentication mechanism if a user is allowed to use it
299
-	 *
300
-	 * @param AuthMechanism $authMechanism
301
-	 * @return bool
302
-	 */
303
-	protected function isAllowedAuthMechanism(AuthMechanism $authMechanism) {
304
-		return true; // not implemented
305
-	}
306
-
307
-	/**
308
-	 * registers a configuration handler
309
-	 *
310
-	 * The function of the provided $placeholder is mostly to act a sorting
311
-	 * criteria, so longer placeholders are replaced first. This avoids
312
-	 * "$user" overwriting parts of "$userMail" and "$userLang", for example.
313
-	 * The provided value should not contain the $ prefix, only a-z0-9 are
314
-	 * allowed. Upper case letters are lower cased, the replacement is case-
315
-	 * insensitive.
316
-	 *
317
-	 * The configHandlerLoader should just instantiate the handler on demand.
318
-	 * For now all handlers are instantiated when a mount is loaded, independent
319
-	 * of whether the placeholder is present or not. This may change in future.
320
-	 *
321
-	 * @since 16.0.0
322
-	 */
323
-	public function registerConfigHandler(string $placeholder, callable $configHandlerLoader) {
324
-		$placeholder = trim(strtolower($placeholder));
325
-		if(!(bool)\preg_match('/^[a-z0-9]*$/', $placeholder)) {
326
-			throw new \RuntimeException(sprintf(
327
-				'Invalid placeholder %s, only [a-z0-9] are allowed', $placeholder
328
-			));
329
-		}
330
-		if($placeholder === '') {
331
-			throw new \RuntimeException('Invalid empty placeholder');
332
-		}
333
-		if(isset($this->configHandlerLoaders[$placeholder]) || isset($this->configHandlers[$placeholder])) {
334
-			throw new \RuntimeException(sprintf('A handler is already registered for %s', $placeholder));
335
-		}
336
-		$this->configHandlerLoaders[$placeholder] = $configHandlerLoader;
337
-	}
338
-
339
-	protected function loadConfigHandlers():void {
340
-		$this->callForRegistrations();
341
-		$newLoaded = false;
342
-		foreach ($this->configHandlerLoaders as $placeholder => $loader) {
343
-			$handler = $loader();
344
-			if(!$handler instanceof IConfigHandler) {
345
-				throw new \RuntimeException(sprintf(
346
-					'Handler for %s is not an instance of IConfigHandler', $placeholder
347
-				));
348
-			}
349
-			$this->configHandlers[$placeholder] = $handler;
350
-			$newLoaded = true;
351
-		}
352
-		$this->configHandlerLoaders = [];
353
-		if($newLoaded) {
354
-			// ensure those with longest placeholders come first,
355
-			// to avoid substring matches
356
-			uksort($this->configHandlers, function ($phA, $phB) {
357
-				return strlen($phB) <=> strlen($phA);
358
-			});
359
-		}
360
-	}
361
-
362
-	/**
363
-	 * @since 16.0.0
364
-	 */
365
-	public function getConfigHandlers() {
366
-		$this->loadConfigHandlers();
367
-		return $this->configHandlers;
368
-	}
43
+    /** Visibility constants for VisibilityTrait */
44
+    const VISIBILITY_NONE = 0;
45
+    const VISIBILITY_PERSONAL = 1;
46
+    const VISIBILITY_ADMIN = 2;
47
+    //const VISIBILITY_ALIENS = 4;
48
+
49
+    const VISIBILITY_DEFAULT = 3; // PERSONAL | ADMIN
50
+
51
+    /** Priority constants for PriorityTrait */
52
+    const PRIORITY_DEFAULT = 100;
53
+
54
+    /** @var IConfig */
55
+    protected $config;
56
+
57
+    /** @var bool */
58
+    private $userMountingAllowed = true;
59
+
60
+    /** @var string[] */
61
+    private $userMountingBackends = [];
62
+
63
+    /** @var Backend[] */
64
+    private $backends = [];
65
+
66
+    /** @var IBackendProvider[] */
67
+    private $backendProviders = [];
68
+
69
+    /** @var AuthMechanism[] */
70
+    private $authMechanisms = [];
71
+
72
+    /** @var IAuthMechanismProvider[] */
73
+    private $authMechanismProviders = [];
74
+
75
+    /** @var callable[] */
76
+    private $configHandlerLoaders = [];
77
+
78
+    private $configHandlers = [];
79
+
80
+    /**
81
+     * @param IConfig $config
82
+     */
83
+    public function __construct(
84
+        IConfig $config
85
+    ) {
86
+        $this->config = $config;
87
+
88
+        // Load config values
89
+        if ($this->config->getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') {
90
+            $this->userMountingAllowed = false;
91
+        }
92
+        $this->userMountingBackends = explode(',',
93
+            $this->config->getAppValue('files_external', 'user_mounting_backends', '')
94
+        );
95
+
96
+        // if no backend is in the list an empty string is in the array and user mounting is disabled
97
+        if ($this->userMountingBackends === ['']) {
98
+            $this->userMountingAllowed = false;
99
+        }
100
+    }
101
+
102
+    /**
103
+     * Register a backend provider
104
+     *
105
+     * @since 9.1.0
106
+     * @param IBackendProvider $provider
107
+     */
108
+    public function registerBackendProvider(IBackendProvider $provider) {
109
+        $this->backendProviders[] = $provider;
110
+    }
111
+
112
+    private function callForRegistrations() {
113
+        static $eventSent = false;
114
+        if(!$eventSent) {
115
+            \OC::$server->getEventDispatcher()->dispatch(
116
+                'OCA\\Files_External::loadAdditionalBackends',
117
+                new GenericEvent()
118
+            );
119
+            $eventSent = true;
120
+        }
121
+    }
122
+
123
+    private function loadBackendProviders() {
124
+        $this->callForRegistrations();
125
+        foreach ($this->backendProviders as $provider) {
126
+            $this->registerBackends($provider->getBackends());
127
+        }
128
+        $this->backendProviders = [];
129
+    }
130
+
131
+    /**
132
+     * Register an auth mechanism provider
133
+     *
134
+     * @since 9.1.0
135
+     * @param IAuthMechanismProvider $provider
136
+     */
137
+    public function registerAuthMechanismProvider(IAuthMechanismProvider $provider) {
138
+        $this->authMechanismProviders[] = $provider;
139
+    }
140
+
141
+    private function loadAuthMechanismProviders() {
142
+        $this->callForRegistrations();
143
+        foreach ($this->authMechanismProviders as $provider) {
144
+            $this->registerAuthMechanisms($provider->getAuthMechanisms());
145
+        }
146
+        $this->authMechanismProviders = [];
147
+    }
148
+
149
+    /**
150
+     * Register a backend
151
+     *
152
+     * @deprecated 9.1.0 use registerBackendProvider()
153
+     * @param Backend $backend
154
+     */
155
+    public function registerBackend(Backend $backend) {
156
+        if (!$this->isAllowedUserBackend($backend)) {
157
+            $backend->removeVisibility(BackendService::VISIBILITY_PERSONAL);
158
+        }
159
+        foreach ($backend->getIdentifierAliases() as $alias) {
160
+            $this->backends[$alias] = $backend;
161
+        }
162
+    }
163
+
164
+    /**
165
+     * @deprecated 9.1.0 use registerBackendProvider()
166
+     * @param Backend[] $backends
167
+     */
168
+    public function registerBackends(array $backends) {
169
+        foreach ($backends as $backend) {
170
+            $this->registerBackend($backend);
171
+        }
172
+    }
173
+    /**
174
+     * Register an authentication mechanism
175
+     *
176
+     * @deprecated 9.1.0 use registerAuthMechanismProvider()
177
+     * @param AuthMechanism $authMech
178
+     */
179
+    public function registerAuthMechanism(AuthMechanism $authMech) {
180
+        if (!$this->isAllowedAuthMechanism($authMech)) {
181
+            $authMech->removeVisibility(BackendService::VISIBILITY_PERSONAL);
182
+        }
183
+        foreach ($authMech->getIdentifierAliases() as $alias) {
184
+            $this->authMechanisms[$alias] = $authMech;
185
+        }
186
+    }
187
+
188
+    /**
189
+     * @deprecated 9.1.0 use registerAuthMechanismProvider()
190
+     * @param AuthMechanism[] $mechanisms
191
+     */
192
+    public function registerAuthMechanisms(array $mechanisms) {
193
+        foreach ($mechanisms as $mechanism) {
194
+            $this->registerAuthMechanism($mechanism);
195
+        }
196
+    }
197
+
198
+    /**
199
+     * Get all backends
200
+     *
201
+     * @return Backend[]
202
+     */
203
+    public function getBackends() {
204
+        $this->loadBackendProviders();
205
+        // only return real identifiers, no aliases
206
+        $backends = [];
207
+        foreach ($this->backends as $backend) {
208
+            $backends[$backend->getIdentifier()] = $backend;
209
+        }
210
+        return $backends;
211
+    }
212
+
213
+    /**
214
+     * Get all available backends
215
+     *
216
+     * @return Backend[]
217
+     */
218
+    public function getAvailableBackends() {
219
+        return array_filter($this->getBackends(), function ($backend) {
220
+            return !$backend->checkDependencies();
221
+        });
222
+    }
223
+
224
+    /**
225
+     * @param string $identifier
226
+     * @return Backend|null
227
+     */
228
+    public function getBackend($identifier) {
229
+        $this->loadBackendProviders();
230
+        if (isset($this->backends[$identifier])) {
231
+            return $this->backends[$identifier];
232
+        }
233
+        return null;
234
+    }
235
+
236
+    /**
237
+     * Get all authentication mechanisms
238
+     *
239
+     * @return AuthMechanism[]
240
+     */
241
+    public function getAuthMechanisms() {
242
+        $this->loadAuthMechanismProviders();
243
+        // only return real identifiers, no aliases
244
+        $mechanisms = [];
245
+        foreach ($this->authMechanisms as $mechanism) {
246
+            $mechanisms[$mechanism->getIdentifier()] = $mechanism;
247
+        }
248
+        return $mechanisms;
249
+    }
250
+
251
+    /**
252
+     * Get all authentication mechanisms for schemes
253
+     *
254
+     * @param string[] $schemes
255
+     * @return AuthMechanism[]
256
+     */
257
+    public function getAuthMechanismsByScheme(array $schemes) {
258
+        return array_filter($this->getAuthMechanisms(), function ($authMech) use ($schemes) {
259
+            return in_array($authMech->getScheme(), $schemes, true);
260
+        });
261
+    }
262
+
263
+    /**
264
+     * @param string $identifier
265
+     * @return AuthMechanism|null
266
+     */
267
+    public function getAuthMechanism($identifier) {
268
+        $this->loadAuthMechanismProviders();
269
+        if (isset($this->authMechanisms[$identifier])) {
270
+            return $this->authMechanisms[$identifier];
271
+        }
272
+        return null;
273
+    }
274
+
275
+    /**
276
+     * @return bool
277
+     */
278
+    public function isUserMountingAllowed() {
279
+        return $this->userMountingAllowed;
280
+    }
281
+
282
+    /**
283
+     * Check a backend if a user is allowed to mount it
284
+     *
285
+     * @param Backend $backend
286
+     * @return bool
287
+     */
288
+    protected function isAllowedUserBackend(Backend $backend) {
289
+        if ($this->userMountingAllowed &&
290
+            array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends)
291
+        ) {
292
+            return true;
293
+        }
294
+        return false;
295
+    }
296
+
297
+    /**
298
+     * Check an authentication mechanism if a user is allowed to use it
299
+     *
300
+     * @param AuthMechanism $authMechanism
301
+     * @return bool
302
+     */
303
+    protected function isAllowedAuthMechanism(AuthMechanism $authMechanism) {
304
+        return true; // not implemented
305
+    }
306
+
307
+    /**
308
+     * registers a configuration handler
309
+     *
310
+     * The function of the provided $placeholder is mostly to act a sorting
311
+     * criteria, so longer placeholders are replaced first. This avoids
312
+     * "$user" overwriting parts of "$userMail" and "$userLang", for example.
313
+     * The provided value should not contain the $ prefix, only a-z0-9 are
314
+     * allowed. Upper case letters are lower cased, the replacement is case-
315
+     * insensitive.
316
+     *
317
+     * The configHandlerLoader should just instantiate the handler on demand.
318
+     * For now all handlers are instantiated when a mount is loaded, independent
319
+     * of whether the placeholder is present or not. This may change in future.
320
+     *
321
+     * @since 16.0.0
322
+     */
323
+    public function registerConfigHandler(string $placeholder, callable $configHandlerLoader) {
324
+        $placeholder = trim(strtolower($placeholder));
325
+        if(!(bool)\preg_match('/^[a-z0-9]*$/', $placeholder)) {
326
+            throw new \RuntimeException(sprintf(
327
+                'Invalid placeholder %s, only [a-z0-9] are allowed', $placeholder
328
+            ));
329
+        }
330
+        if($placeholder === '') {
331
+            throw new \RuntimeException('Invalid empty placeholder');
332
+        }
333
+        if(isset($this->configHandlerLoaders[$placeholder]) || isset($this->configHandlers[$placeholder])) {
334
+            throw new \RuntimeException(sprintf('A handler is already registered for %s', $placeholder));
335
+        }
336
+        $this->configHandlerLoaders[$placeholder] = $configHandlerLoader;
337
+    }
338
+
339
+    protected function loadConfigHandlers():void {
340
+        $this->callForRegistrations();
341
+        $newLoaded = false;
342
+        foreach ($this->configHandlerLoaders as $placeholder => $loader) {
343
+            $handler = $loader();
344
+            if(!$handler instanceof IConfigHandler) {
345
+                throw new \RuntimeException(sprintf(
346
+                    'Handler for %s is not an instance of IConfigHandler', $placeholder
347
+                ));
348
+            }
349
+            $this->configHandlers[$placeholder] = $handler;
350
+            $newLoaded = true;
351
+        }
352
+        $this->configHandlerLoaders = [];
353
+        if($newLoaded) {
354
+            // ensure those with longest placeholders come first,
355
+            // to avoid substring matches
356
+            uksort($this->configHandlers, function ($phA, $phB) {
357
+                return strlen($phB) <=> strlen($phA);
358
+            });
359
+        }
360
+    }
361
+
362
+    /**
363
+     * @since 16.0.0
364
+     */
365
+    public function getConfigHandlers() {
366
+        $this->loadConfigHandlers();
367
+        return $this->configHandlers;
368
+    }
369 369
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 
112 112
 	private function callForRegistrations() {
113 113
 		static $eventSent = false;
114
-		if(!$eventSent) {
114
+		if (!$eventSent) {
115 115
 			\OC::$server->getEventDispatcher()->dispatch(
116 116
 				'OCA\\Files_External::loadAdditionalBackends',
117 117
 				new GenericEvent()
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	 * @return Backend[]
217 217
 	 */
218 218
 	public function getAvailableBackends() {
219
-		return array_filter($this->getBackends(), function ($backend) {
219
+		return array_filter($this->getBackends(), function($backend) {
220 220
 			return !$backend->checkDependencies();
221 221
 		});
222 222
 	}
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	 * @return AuthMechanism[]
256 256
 	 */
257 257
 	public function getAuthMechanismsByScheme(array $schemes) {
258
-		return array_filter($this->getAuthMechanisms(), function ($authMech) use ($schemes) {
258
+		return array_filter($this->getAuthMechanisms(), function($authMech) use ($schemes) {
259 259
 			return in_array($authMech->getScheme(), $schemes, true);
260 260
 		});
261 261
 	}
@@ -322,15 +322,15 @@  discard block
 block discarded – undo
322 322
 	 */
323 323
 	public function registerConfigHandler(string $placeholder, callable $configHandlerLoader) {
324 324
 		$placeholder = trim(strtolower($placeholder));
325
-		if(!(bool)\preg_match('/^[a-z0-9]*$/', $placeholder)) {
325
+		if (!(bool) \preg_match('/^[a-z0-9]*$/', $placeholder)) {
326 326
 			throw new \RuntimeException(sprintf(
327 327
 				'Invalid placeholder %s, only [a-z0-9] are allowed', $placeholder
328 328
 			));
329 329
 		}
330
-		if($placeholder === '') {
330
+		if ($placeholder === '') {
331 331
 			throw new \RuntimeException('Invalid empty placeholder');
332 332
 		}
333
-		if(isset($this->configHandlerLoaders[$placeholder]) || isset($this->configHandlers[$placeholder])) {
333
+		if (isset($this->configHandlerLoaders[$placeholder]) || isset($this->configHandlers[$placeholder])) {
334 334
 			throw new \RuntimeException(sprintf('A handler is already registered for %s', $placeholder));
335 335
 		}
336 336
 		$this->configHandlerLoaders[$placeholder] = $configHandlerLoader;
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 		$newLoaded = false;
342 342
 		foreach ($this->configHandlerLoaders as $placeholder => $loader) {
343 343
 			$handler = $loader();
344
-			if(!$handler instanceof IConfigHandler) {
344
+			if (!$handler instanceof IConfigHandler) {
345 345
 				throw new \RuntimeException(sprintf(
346 346
 					'Handler for %s is not an instance of IConfigHandler', $placeholder
347 347
 				));
@@ -350,10 +350,10 @@  discard block
 block discarded – undo
350 350
 			$newLoaded = true;
351 351
 		}
352 352
 		$this->configHandlerLoaders = [];
353
-		if($newLoaded) {
353
+		if ($newLoaded) {
354 354
 			// ensure those with longest placeholders come first,
355 355
 			// to avoid substring matches
356
-			uksort($this->configHandlers, function ($phA, $phB) {
356
+			uksort($this->configHandlers, function($phA, $phB) {
357 357
 				return strlen($phB) <=> strlen($phA);
358 358
 			});
359 359
 		}
Please login to merge, or discard this patch.