Completed
Push — master ( 88ba65...9a0892 )
by Christoph
24:20
created
apps/dav/lib/Connector/Sabre/FakeLockerPlugin.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -89,10 +89,10 @@
 block discarded – undo
89 89
 	 * @return void
90 90
 	 */
91 91
 	public function propFind(PropFind $propFind, INode $node) {
92
-		$propFind->handle('{DAV:}supportedlock', function () {
92
+		$propFind->handle('{DAV:}supportedlock', function() {
93 93
 			return new SupportedLock();
94 94
 		});
95
-		$propFind->handle('{DAV:}lockdiscovery', function () use ($propFind) {
95
+		$propFind->handle('{DAV:}lockdiscovery', function() use ($propFind) {
96 96
 			return new LockDiscovery([]);
97 97
 		});
98 98
 	}
Please login to merge, or discard this patch.
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -31,113 +31,113 @@
 block discarded – undo
31 31
  * @package OCA\DAV\Connector\Sabre
32 32
  */
33 33
 class FakeLockerPlugin extends ServerPlugin {
34
-	/** @var Server */
35
-	private $server;
34
+    /** @var Server */
35
+    private $server;
36 36
 
37
-	/** {@inheritDoc} */
38
-	public function initialize(Server $server) {
39
-		$this->server = $server;
40
-		$this->server->on('method:LOCK', [$this, 'fakeLockProvider'], 1);
41
-		$this->server->on('method:UNLOCK', [$this, 'fakeUnlockProvider'], 1);
42
-		$server->on('propFind', [$this, 'propFind']);
43
-		$server->on('validateTokens', [$this, 'validateTokens']);
44
-	}
37
+    /** {@inheritDoc} */
38
+    public function initialize(Server $server) {
39
+        $this->server = $server;
40
+        $this->server->on('method:LOCK', [$this, 'fakeLockProvider'], 1);
41
+        $this->server->on('method:UNLOCK', [$this, 'fakeUnlockProvider'], 1);
42
+        $server->on('propFind', [$this, 'propFind']);
43
+        $server->on('validateTokens', [$this, 'validateTokens']);
44
+    }
45 45
 
46
-	/**
47
-	 * Indicate that we support LOCK and UNLOCK
48
-	 *
49
-	 * @param string $path
50
-	 * @return string[]
51
-	 */
52
-	public function getHTTPMethods($path) {
53
-		return [
54
-			'LOCK',
55
-			'UNLOCK',
56
-		];
57
-	}
46
+    /**
47
+     * Indicate that we support LOCK and UNLOCK
48
+     *
49
+     * @param string $path
50
+     * @return string[]
51
+     */
52
+    public function getHTTPMethods($path) {
53
+        return [
54
+            'LOCK',
55
+            'UNLOCK',
56
+        ];
57
+    }
58 58
 
59
-	/**
60
-	 * Indicate that we support locking
61
-	 *
62
-	 * @return integer[]
63
-	 */
64
-	public function getFeatures() {
65
-		return [2];
66
-	}
59
+    /**
60
+     * Indicate that we support locking
61
+     *
62
+     * @return integer[]
63
+     */
64
+    public function getFeatures() {
65
+        return [2];
66
+    }
67 67
 
68
-	/**
69
-	 * Return some dummy response for PROPFIND requests with regard to locking
70
-	 *
71
-	 * @param PropFind $propFind
72
-	 * @param INode $node
73
-	 * @return void
74
-	 */
75
-	public function propFind(PropFind $propFind, INode $node) {
76
-		$propFind->handle('{DAV:}supportedlock', function () {
77
-			return new SupportedLock();
78
-		});
79
-		$propFind->handle('{DAV:}lockdiscovery', function () use ($propFind) {
80
-			return new LockDiscovery([]);
81
-		});
82
-	}
68
+    /**
69
+     * Return some dummy response for PROPFIND requests with regard to locking
70
+     *
71
+     * @param PropFind $propFind
72
+     * @param INode $node
73
+     * @return void
74
+     */
75
+    public function propFind(PropFind $propFind, INode $node) {
76
+        $propFind->handle('{DAV:}supportedlock', function () {
77
+            return new SupportedLock();
78
+        });
79
+        $propFind->handle('{DAV:}lockdiscovery', function () use ($propFind) {
80
+            return new LockDiscovery([]);
81
+        });
82
+    }
83 83
 
84
-	/**
85
-	 * Mark a locking token always as valid
86
-	 *
87
-	 * @param RequestInterface $request
88
-	 * @param array $conditions
89
-	 */
90
-	public function validateTokens(RequestInterface $request, &$conditions) {
91
-		foreach ($conditions as &$fileCondition) {
92
-			if (isset($fileCondition['tokens'])) {
93
-				foreach ($fileCondition['tokens'] as &$token) {
94
-					if (isset($token['token'])) {
95
-						if (str_starts_with($token['token'], 'opaquelocktoken:')) {
96
-							$token['validToken'] = true;
97
-						}
98
-					}
99
-				}
100
-			}
101
-		}
102
-	}
84
+    /**
85
+     * Mark a locking token always as valid
86
+     *
87
+     * @param RequestInterface $request
88
+     * @param array $conditions
89
+     */
90
+    public function validateTokens(RequestInterface $request, &$conditions) {
91
+        foreach ($conditions as &$fileCondition) {
92
+            if (isset($fileCondition['tokens'])) {
93
+                foreach ($fileCondition['tokens'] as &$token) {
94
+                    if (isset($token['token'])) {
95
+                        if (str_starts_with($token['token'], 'opaquelocktoken:')) {
96
+                            $token['validToken'] = true;
97
+                        }
98
+                    }
99
+                }
100
+            }
101
+        }
102
+    }
103 103
 
104
-	/**
105
-	 * Fakes a successful LOCK
106
-	 *
107
-	 * @param RequestInterface $request
108
-	 * @param ResponseInterface $response
109
-	 * @return bool
110
-	 */
111
-	public function fakeLockProvider(RequestInterface $request,
112
-		ResponseInterface $response) {
113
-		$lockInfo = new LockInfo();
114
-		$lockInfo->token = md5($request->getPath());
115
-		$lockInfo->uri = $request->getPath();
116
-		$lockInfo->depth = Server::DEPTH_INFINITY;
117
-		$lockInfo->timeout = 1800;
104
+    /**
105
+     * Fakes a successful LOCK
106
+     *
107
+     * @param RequestInterface $request
108
+     * @param ResponseInterface $response
109
+     * @return bool
110
+     */
111
+    public function fakeLockProvider(RequestInterface $request,
112
+        ResponseInterface $response) {
113
+        $lockInfo = new LockInfo();
114
+        $lockInfo->token = md5($request->getPath());
115
+        $lockInfo->uri = $request->getPath();
116
+        $lockInfo->depth = Server::DEPTH_INFINITY;
117
+        $lockInfo->timeout = 1800;
118 118
 
119
-		$body = $this->server->xml->write('{DAV:}prop', [
120
-			'{DAV:}lockdiscovery'
121
-					=> new LockDiscovery([$lockInfo])
122
-		]);
119
+        $body = $this->server->xml->write('{DAV:}prop', [
120
+            '{DAV:}lockdiscovery'
121
+                    => new LockDiscovery([$lockInfo])
122
+        ]);
123 123
 
124
-		$response->setStatus(Http::STATUS_OK);
125
-		$response->setBody($body);
124
+        $response->setStatus(Http::STATUS_OK);
125
+        $response->setBody($body);
126 126
 
127
-		return false;
128
-	}
127
+        return false;
128
+    }
129 129
 
130
-	/**
131
-	 * Fakes a successful LOCK
132
-	 *
133
-	 * @param RequestInterface $request
134
-	 * @param ResponseInterface $response
135
-	 * @return bool
136
-	 */
137
-	public function fakeUnlockProvider(RequestInterface $request,
138
-		ResponseInterface $response) {
139
-		$response->setStatus(Http::STATUS_NO_CONTENT);
140
-		$response->setHeader('Content-Length', '0');
141
-		return false;
142
-	}
130
+    /**
131
+     * Fakes a successful LOCK
132
+     *
133
+     * @param RequestInterface $request
134
+     * @param ResponseInterface $response
135
+     * @return bool
136
+     */
137
+    public function fakeUnlockProvider(RequestInterface $request,
138
+        ResponseInterface $response) {
139
+        $response->setStatus(Http::STATUS_NO_CONTENT);
140
+        $response->setHeader('Content-Length', '0');
141
+        return false;
142
+    }
143 143
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Capabilities.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@
 block discarded – undo
116 116
 			$res['group'] = [];
117 117
 			$res['group']['enabled'] = $this->shareManager->allowGroupSharing();
118 118
 			$res['group']['expire_date']['enabled'] = true;
119
-			$res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL);
119
+			$res['default_permissions'] = (int) $this->config->getAppValue('core', 'shareapi_default_permissions', (string) Constants::PERMISSION_ALL);
120 120
 		}
121 121
 
122 122
 		//Federated sharing
Please login to merge, or discard this patch.
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -21,173 +21,173 @@
 block discarded – undo
21 21
  * @package OCA\Files_Sharing
22 22
  */
23 23
 class Capabilities implements ICapability {
24
-	public function __construct(
25
-		private IConfig $config,
26
-		private readonly IAppConfig $appConfig,
27
-		private IManager $shareManager,
28
-		private IAppManager $appManager,
29
-	) {
30
-	}
31
-
32
-	/**
33
-	 * Return this classes capabilities
34
-	 *
35
-	 * @return array{
36
-	 *     files_sharing: array{
37
-	 *         api_enabled: bool,
38
-	 *         public: array{
39
-	 *             enabled: bool,
40
-	 *             password?: array{
41
-	 *                 enforced: bool,
42
-	 *                 askForOptionalPassword: bool
43
-	 *             },
44
-	 *     		   multiple_links?: bool,
45
-	 *             expire_date?: array{
46
-	 *                 enabled: bool,
47
-	 *                 days?: int,
48
-	 *                 enforced?: bool,
49
-	 *             },
50
-	 *             expire_date_internal?: array{
51
-	 *                 enabled: bool,
52
-	 *                 days?: int,
53
-	 *                 enforced?: bool,
54
-	 *             },
55
-	 *             expire_date_remote?: array{
56
-	 *                 enabled: bool,
57
-	 *                 days?: int,
58
-	 *                 enforced?: bool,
59
-	 *             },
60
-	 *             send_mail?: bool,
61
-	 *             upload?: bool,
62
-	 *             upload_files_drop?: bool,
63
-	 *             custom_tokens?: bool,
64
-	 *         },
65
-	 *         user: array{
66
-	 *             send_mail: bool,
67
-	 *             expire_date?: array{
68
-	 *                 enabled: bool,
69
-	 *             },
70
-	 *         },
71
-	 *         resharing: bool,
72
-	 *         group_sharing?: bool,
73
-	 *         group?: array{
74
-	 *             enabled: bool,
75
-	 *             expire_date?: array{
76
-	 *                 enabled: bool,
77
-	 *             },
78
-	 *         },
79
-	 *         default_permissions?: int,
80
-	 *         federation: array{
81
-	 *             outgoing: bool,
82
-	 *             incoming: bool,
83
-	 *             expire_date: array{
84
-	 *                 enabled: bool,
85
-	 *             },
86
-	 *             expire_date_supported: array{
87
-	 *                 enabled: bool,
88
-	 *             },
89
-	 *         },
90
-	 *         sharee: array{
91
-	 *             query_lookup_default: bool,
92
-	 *             always_show_unique: bool,
93
-	 *         },
94
-	 *	   },
95
-	 * }
96
-	 */
97
-	public function getCapabilities() {
98
-		$res = [];
99
-
100
-		if (!$this->shareManager->shareApiEnabled()) {
101
-			$res['api_enabled'] = false;
102
-			$res['public'] = ['enabled' => false];
103
-			$res['user'] = ['send_mail' => false];
104
-			$res['resharing'] = false;
105
-		} else {
106
-			$res['api_enabled'] = true;
107
-
108
-			$public = [];
109
-			$public['enabled'] = $this->shareManager->shareApiAllowLinks();
110
-			if ($public['enabled']) {
111
-				$public['password'] = [];
112
-				$public['password']['enforced'] = $this->shareManager->shareApiLinkEnforcePassword();
113
-
114
-				if ($public['password']['enforced']) {
115
-					$public['password']['askForOptionalPassword'] = false;
116
-				} else {
117
-					$public['password']['askForOptionalPassword'] = $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_PASSWORD_DEFAULT);
118
-				}
119
-
120
-				$public['expire_date'] = [];
121
-				$public['multiple_links'] = true;
122
-				$public['expire_date']['enabled'] = $this->shareManager->shareApiLinkDefaultExpireDate();
123
-				if ($public['expire_date']['enabled']) {
124
-					$public['expire_date']['days'] = $this->shareManager->shareApiLinkDefaultExpireDays();
125
-					$public['expire_date']['enforced'] = $this->shareManager->shareApiLinkDefaultExpireDateEnforced();
126
-				}
127
-
128
-				$public['expire_date_internal'] = [];
129
-				$public['expire_date_internal']['enabled'] = $this->shareManager->shareApiInternalDefaultExpireDate();
130
-				if ($public['expire_date_internal']['enabled']) {
131
-					$public['expire_date_internal']['days'] = $this->shareManager->shareApiInternalDefaultExpireDays();
132
-					$public['expire_date_internal']['enforced'] = $this->shareManager->shareApiInternalDefaultExpireDateEnforced();
133
-				}
134
-
135
-				$public['expire_date_remote'] = [];
136
-				$public['expire_date_remote']['enabled'] = $this->shareManager->shareApiRemoteDefaultExpireDate();
137
-				if ($public['expire_date_remote']['enabled']) {
138
-					$public['expire_date_remote']['days'] = $this->shareManager->shareApiRemoteDefaultExpireDays();
139
-					$public['expire_date_remote']['enforced'] = $this->shareManager->shareApiRemoteDefaultExpireDateEnforced();
140
-				}
141
-
142
-				$public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
143
-				$public['upload'] = $this->shareManager->shareApiLinkAllowPublicUpload();
144
-				$public['upload_files_drop'] = $public['upload'];
145
-				$public['custom_tokens'] = $this->shareManager->allowCustomTokens();
146
-			}
147
-			$res['public'] = $public;
148
-
149
-			$res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
150
-
151
-			$res['user']['send_mail'] = false;
152
-			$res['user']['expire_date']['enabled'] = true;
153
-
154
-			// deprecated in favour of 'group', but we need to keep it for now
155
-			// in order to stay compatible with older clients
156
-			$res['group_sharing'] = $this->shareManager->allowGroupSharing();
157
-
158
-			$res['group'] = [];
159
-			$res['group']['enabled'] = $this->shareManager->allowGroupSharing();
160
-			$res['group']['expire_date']['enabled'] = true;
161
-			$res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL);
162
-		}
163
-
164
-		//Federated sharing
165
-		if ($this->appManager->isEnabledForAnyone('federation')) {
166
-			$res['federation'] = [
167
-				'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(),
168
-				'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
169
-				// old bogus one, expire_date was not working before, keeping for compatibility
170
-				'expire_date' => ['enabled' => true],
171
-				// the real deal, signifies that expiration date can be set on federated shares
172
-				'expire_date_supported' => ['enabled' => true],
173
-			];
174
-		} else {
175
-			$res['federation'] = [
176
-				'outgoing' => false,
177
-				'incoming' => false,
178
-				'expire_date' => ['enabled' => false],
179
-				'expire_date_supported' => ['enabled' => false],
180
-			];
181
-		}
182
-
183
-		// Sharee searches
184
-		$res['sharee'] = [
185
-			'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false),
186
-			'always_show_unique' => $this->config->getAppValue('files_sharing', 'always_show_unique', 'yes') === 'yes',
187
-		];
188
-
189
-		return [
190
-			'files_sharing' => $res,
191
-		];
192
-	}
24
+    public function __construct(
25
+        private IConfig $config,
26
+        private readonly IAppConfig $appConfig,
27
+        private IManager $shareManager,
28
+        private IAppManager $appManager,
29
+    ) {
30
+    }
31
+
32
+    /**
33
+     * Return this classes capabilities
34
+     *
35
+     * @return array{
36
+     *     files_sharing: array{
37
+     *         api_enabled: bool,
38
+     *         public: array{
39
+     *             enabled: bool,
40
+     *             password?: array{
41
+     *                 enforced: bool,
42
+     *                 askForOptionalPassword: bool
43
+     *             },
44
+     *     		   multiple_links?: bool,
45
+     *             expire_date?: array{
46
+     *                 enabled: bool,
47
+     *                 days?: int,
48
+     *                 enforced?: bool,
49
+     *             },
50
+     *             expire_date_internal?: array{
51
+     *                 enabled: bool,
52
+     *                 days?: int,
53
+     *                 enforced?: bool,
54
+     *             },
55
+     *             expire_date_remote?: array{
56
+     *                 enabled: bool,
57
+     *                 days?: int,
58
+     *                 enforced?: bool,
59
+     *             },
60
+     *             send_mail?: bool,
61
+     *             upload?: bool,
62
+     *             upload_files_drop?: bool,
63
+     *             custom_tokens?: bool,
64
+     *         },
65
+     *         user: array{
66
+     *             send_mail: bool,
67
+     *             expire_date?: array{
68
+     *                 enabled: bool,
69
+     *             },
70
+     *         },
71
+     *         resharing: bool,
72
+     *         group_sharing?: bool,
73
+     *         group?: array{
74
+     *             enabled: bool,
75
+     *             expire_date?: array{
76
+     *                 enabled: bool,
77
+     *             },
78
+     *         },
79
+     *         default_permissions?: int,
80
+     *         federation: array{
81
+     *             outgoing: bool,
82
+     *             incoming: bool,
83
+     *             expire_date: array{
84
+     *                 enabled: bool,
85
+     *             },
86
+     *             expire_date_supported: array{
87
+     *                 enabled: bool,
88
+     *             },
89
+     *         },
90
+     *         sharee: array{
91
+     *             query_lookup_default: bool,
92
+     *             always_show_unique: bool,
93
+     *         },
94
+     *	   },
95
+     * }
96
+     */
97
+    public function getCapabilities() {
98
+        $res = [];
99
+
100
+        if (!$this->shareManager->shareApiEnabled()) {
101
+            $res['api_enabled'] = false;
102
+            $res['public'] = ['enabled' => false];
103
+            $res['user'] = ['send_mail' => false];
104
+            $res['resharing'] = false;
105
+        } else {
106
+            $res['api_enabled'] = true;
107
+
108
+            $public = [];
109
+            $public['enabled'] = $this->shareManager->shareApiAllowLinks();
110
+            if ($public['enabled']) {
111
+                $public['password'] = [];
112
+                $public['password']['enforced'] = $this->shareManager->shareApiLinkEnforcePassword();
113
+
114
+                if ($public['password']['enforced']) {
115
+                    $public['password']['askForOptionalPassword'] = false;
116
+                } else {
117
+                    $public['password']['askForOptionalPassword'] = $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_PASSWORD_DEFAULT);
118
+                }
119
+
120
+                $public['expire_date'] = [];
121
+                $public['multiple_links'] = true;
122
+                $public['expire_date']['enabled'] = $this->shareManager->shareApiLinkDefaultExpireDate();
123
+                if ($public['expire_date']['enabled']) {
124
+                    $public['expire_date']['days'] = $this->shareManager->shareApiLinkDefaultExpireDays();
125
+                    $public['expire_date']['enforced'] = $this->shareManager->shareApiLinkDefaultExpireDateEnforced();
126
+                }
127
+
128
+                $public['expire_date_internal'] = [];
129
+                $public['expire_date_internal']['enabled'] = $this->shareManager->shareApiInternalDefaultExpireDate();
130
+                if ($public['expire_date_internal']['enabled']) {
131
+                    $public['expire_date_internal']['days'] = $this->shareManager->shareApiInternalDefaultExpireDays();
132
+                    $public['expire_date_internal']['enforced'] = $this->shareManager->shareApiInternalDefaultExpireDateEnforced();
133
+                }
134
+
135
+                $public['expire_date_remote'] = [];
136
+                $public['expire_date_remote']['enabled'] = $this->shareManager->shareApiRemoteDefaultExpireDate();
137
+                if ($public['expire_date_remote']['enabled']) {
138
+                    $public['expire_date_remote']['days'] = $this->shareManager->shareApiRemoteDefaultExpireDays();
139
+                    $public['expire_date_remote']['enforced'] = $this->shareManager->shareApiRemoteDefaultExpireDateEnforced();
140
+                }
141
+
142
+                $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
143
+                $public['upload'] = $this->shareManager->shareApiLinkAllowPublicUpload();
144
+                $public['upload_files_drop'] = $public['upload'];
145
+                $public['custom_tokens'] = $this->shareManager->allowCustomTokens();
146
+            }
147
+            $res['public'] = $public;
148
+
149
+            $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
150
+
151
+            $res['user']['send_mail'] = false;
152
+            $res['user']['expire_date']['enabled'] = true;
153
+
154
+            // deprecated in favour of 'group', but we need to keep it for now
155
+            // in order to stay compatible with older clients
156
+            $res['group_sharing'] = $this->shareManager->allowGroupSharing();
157
+
158
+            $res['group'] = [];
159
+            $res['group']['enabled'] = $this->shareManager->allowGroupSharing();
160
+            $res['group']['expire_date']['enabled'] = true;
161
+            $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL);
162
+        }
163
+
164
+        //Federated sharing
165
+        if ($this->appManager->isEnabledForAnyone('federation')) {
166
+            $res['federation'] = [
167
+                'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(),
168
+                'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
169
+                // old bogus one, expire_date was not working before, keeping for compatibility
170
+                'expire_date' => ['enabled' => true],
171
+                // the real deal, signifies that expiration date can be set on federated shares
172
+                'expire_date_supported' => ['enabled' => true],
173
+            ];
174
+        } else {
175
+            $res['federation'] = [
176
+                'outgoing' => false,
177
+                'incoming' => false,
178
+                'expire_date' => ['enabled' => false],
179
+                'expire_date_supported' => ['enabled' => false],
180
+            ];
181
+        }
182
+
183
+        // Sharee searches
184
+        $res['sharee'] = [
185
+            'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false),
186
+            'always_show_unique' => $this->config->getAppValue('files_sharing', 'always_show_unique', 'yes') === 'yes',
187
+        ];
188
+
189
+        return [
190
+            'files_sharing' => $res,
191
+        ];
192
+    }
193 193
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/PriorityTrait.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -29,22 +29,22 @@
 block discarded – undo
29 29
  */
30 30
 trait PriorityTrait {
31 31
 
32
-	/** @var int initial priority */
33
-	protected $priority = BackendService::PRIORITY_DEFAULT;
32
+    /** @var int initial priority */
33
+    protected $priority = BackendService::PRIORITY_DEFAULT;
34 34
 
35
-	/**
36
-	 * @return int
37
-	 */
38
-	public function getPriority() {
39
-		return $this->priority;
40
-	}
35
+    /**
36
+     * @return int
37
+     */
38
+    public function getPriority() {
39
+        return $this->priority;
40
+    }
41 41
 
42
-	/**
43
-	 * @param int $priority
44
-	 * @return self
45
-	 */
46
-	public function setPriority($priority) {
47
-		$this->priority = $priority;
48
-		return $this;
49
-	}
42
+    /**
43
+     * @param int $priority
44
+     * @return self
45
+     */
46
+    public function setPriority($priority) {
47
+        $this->priority = $priority;
48
+        return $this;
49
+    }
50 50
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -28,41 +28,41 @@
 block discarded – undo
28 28
  */
29 29
 trait LegacyDependencyCheckPolyfill {
30 30
 
31
-	/**
32
-	 * @return class-string<IStorage>
33
-	 */
34
-	abstract public function getStorageClass();
31
+    /**
32
+     * @return class-string<IStorage>
33
+     */
34
+    abstract public function getStorageClass();
35 35
 
36
-	/**
37
-	 * Check if object is valid for use
38
-	 *
39
-	 * @return MissingDependency[] Unsatisfied dependencies
40
-	 */
41
-	public function checkDependencies() {
42
-		$ret = [];
36
+    /**
37
+     * Check if object is valid for use
38
+     *
39
+     * @return MissingDependency[] Unsatisfied dependencies
40
+     */
41
+    public function checkDependencies() {
42
+        $ret = [];
43 43
 
44
-		$result = call_user_func([$this->getStorageClass(), 'checkDependencies']);
45
-		if ($result !== true) {
46
-			if (!is_array($result)) {
47
-				$result = [$result];
48
-			}
49
-			foreach ($result as $key => $value) {
50
-				if (!($value instanceof MissingDependency)) {
51
-					$module = null;
52
-					$message = null;
53
-					if (is_numeric($key)) {
54
-						$module = $value;
55
-					} else {
56
-						$module = $key;
57
-						$message = $value;
58
-					}
59
-					$value = new MissingDependency($module);
60
-					$value->setMessage($message);
61
-				}
62
-				$ret[] = $value;
63
-			}
64
-		}
44
+        $result = call_user_func([$this->getStorageClass(), 'checkDependencies']);
45
+        if ($result !== true) {
46
+            if (!is_array($result)) {
47
+                $result = [$result];
48
+            }
49
+            foreach ($result as $key => $value) {
50
+                if (!($value instanceof MissingDependency)) {
51
+                    $module = null;
52
+                    $message = null;
53
+                    if (is_numeric($key)) {
54
+                        $module = $value;
55
+                    } else {
56
+                        $module = $key;
57
+                        $message = $value;
58
+                    }
59
+                    $value = new MissingDependency($module);
60
+                    $value->setMessage($message);
61
+                }
62
+                $ret[] = $value;
63
+            }
64
+        }
65 65
 
66
-		return $ret;
67
-	}
66
+        return $ret;
67
+    }
68 68
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/IFrontendDefinition.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -21,36 +21,36 @@
 block discarded – undo
21 21
 
22 22
 interface IFrontendDefinition {
23 23
 
24
-	public function getText(): string;
24
+    public function getText(): string;
25 25
 
26
-	public function setText(string $text): self;
26
+    public function setText(string $text): self;
27 27
 
28
-	/**
29
-	 * @return array<string, DefinitionParameter>
30
-	 */
31
-	public function getParameters(): array;
28
+    /**
29
+     * @return array<string, DefinitionParameter>
30
+     */
31
+    public function getParameters(): array;
32 32
 
33
-	/**
34
-	 * @param list<DefinitionParameter> $parameters
35
-	 */
36
-	public function addParameters(array $parameters): self;
33
+    /**
34
+     * @param list<DefinitionParameter> $parameters
35
+     */
36
+    public function addParameters(array $parameters): self;
37 37
 
38
-	public function addParameter(DefinitionParameter $parameter): self;
38
+    public function addParameter(DefinitionParameter $parameter): self;
39 39
 
40
-	/**
41
-	 * @return string[]
42
-	 */
43
-	public function getCustomJs(): array;
40
+    /**
41
+     * @return string[]
42
+     */
43
+    public function getCustomJs(): array;
44 44
 
45
-	public function addCustomJs(string $custom): self;
45
+    public function addCustomJs(string $custom): self;
46 46
 
47
-	/**
48
-	 * Serialize into JSON for client-side JS
49
-	 */
50
-	public function jsonSerializeDefinition(): array;
47
+    /**
48
+     * Serialize into JSON for client-side JS
49
+     */
50
+    public function jsonSerializeDefinition(): array;
51 51
 
52
-	/**
53
-	 * Check if parameters are satisfied in a StorageConfig
54
-	 */
55
-	public function validateStorageDefinition(StorageConfig $storage): bool;
52
+    /**
53
+     * Check if parameters are satisfied in a StorageConfig
54
+     */
55
+    public function validateStorageDefinition(StorageConfig $storage): bool;
56 56
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Backend/Backend.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -59,102 +59,102 @@
 block discarded – undo
59 59
  *      Object can affect storage mounting
60 60
  */
61 61
 class Backend implements \JsonSerializable, IIdentifier, IFrontendDefinition {
62
-	use VisibilityTrait;
63
-	use FrontendDefinitionTrait;
64
-	use PriorityTrait;
65
-	use DependencyTrait;
66
-	use StorageModifierTrait;
67
-	use IdentifierTrait;
68
-
69
-	/** @var string storage class */
70
-	private $storageClass;
71
-
72
-	/** @var array 'scheme' => true, supported authentication schemes */
73
-	private $authSchemes = [];
74
-
75
-	/** @var AuthMechanism|callable authentication mechanism fallback */
76
-	private $legacyAuthMechanism;
77
-
78
-	/**
79
-	 * @return class-string<IStorage>
80
-	 */
81
-	public function getStorageClass() {
82
-		return $this->storageClass;
83
-	}
84
-
85
-	/**
86
-	 * @param string $class
87
-	 * @return $this
88
-	 */
89
-	public function setStorageClass($class) {
90
-		$this->storageClass = $class;
91
-		return $this;
92
-	}
93
-
94
-	/**
95
-	 * @return array
96
-	 */
97
-	public function getAuthSchemes() {
98
-		if (empty($this->authSchemes)) {
99
-			return [AuthMechanism::SCHEME_NULL => true];
100
-		}
101
-		return $this->authSchemes;
102
-	}
103
-
104
-	/**
105
-	 * @param string $scheme
106
-	 * @return self
107
-	 */
108
-	public function addAuthScheme($scheme) {
109
-		$this->authSchemes[$scheme] = true;
110
-		return $this;
111
-	}
112
-
113
-	/**
114
-	 * @param array $parameters storage parameters, for dynamic mechanism selection
115
-	 * @return AuthMechanism
116
-	 */
117
-	public function getLegacyAuthMechanism(array $parameters = []) {
118
-		if (is_callable($this->legacyAuthMechanism)) {
119
-			return call_user_func($this->legacyAuthMechanism, $parameters);
120
-		}
121
-		return $this->legacyAuthMechanism;
122
-	}
123
-
124
-	public function setLegacyAuthMechanism(AuthMechanism $authMechanism): self {
125
-		$this->legacyAuthMechanism = $authMechanism;
126
-		return $this;
127
-	}
128
-
129
-	/**
130
-	 * @param callable $callback dynamic auth mechanism selection
131
-	 */
132
-	public function setLegacyAuthMechanismCallback(callable $callback): self {
133
-		$this->legacyAuthMechanism = $callback;
134
-		return $this;
135
-	}
136
-
137
-	/**
138
-	 * Serialize into JSON for client-side JS
139
-	 */
140
-	public function jsonSerialize(): array {
141
-		$data = $this->jsonSerializeDefinition();
142
-		$data += $this->jsonSerializeIdentifier();
143
-
144
-		$data['backend'] = $data['name']; // legacy compat
145
-		$data['priority'] = $this->getPriority();
146
-		$data['authSchemes'] = $this->getAuthSchemes();
147
-
148
-		return $data;
149
-	}
150
-
151
-	/**
152
-	 * Check if parameters are satisfied in a StorageConfig
153
-	 *
154
-	 * @param StorageConfig $storage
155
-	 * @return bool
156
-	 */
157
-	public function validateStorage(StorageConfig $storage) {
158
-		return $this->validateStorageDefinition($storage);
159
-	}
62
+    use VisibilityTrait;
63
+    use FrontendDefinitionTrait;
64
+    use PriorityTrait;
65
+    use DependencyTrait;
66
+    use StorageModifierTrait;
67
+    use IdentifierTrait;
68
+
69
+    /** @var string storage class */
70
+    private $storageClass;
71
+
72
+    /** @var array 'scheme' => true, supported authentication schemes */
73
+    private $authSchemes = [];
74
+
75
+    /** @var AuthMechanism|callable authentication mechanism fallback */
76
+    private $legacyAuthMechanism;
77
+
78
+    /**
79
+     * @return class-string<IStorage>
80
+     */
81
+    public function getStorageClass() {
82
+        return $this->storageClass;
83
+    }
84
+
85
+    /**
86
+     * @param string $class
87
+     * @return $this
88
+     */
89
+    public function setStorageClass($class) {
90
+        $this->storageClass = $class;
91
+        return $this;
92
+    }
93
+
94
+    /**
95
+     * @return array
96
+     */
97
+    public function getAuthSchemes() {
98
+        if (empty($this->authSchemes)) {
99
+            return [AuthMechanism::SCHEME_NULL => true];
100
+        }
101
+        return $this->authSchemes;
102
+    }
103
+
104
+    /**
105
+     * @param string $scheme
106
+     * @return self
107
+     */
108
+    public function addAuthScheme($scheme) {
109
+        $this->authSchemes[$scheme] = true;
110
+        return $this;
111
+    }
112
+
113
+    /**
114
+     * @param array $parameters storage parameters, for dynamic mechanism selection
115
+     * @return AuthMechanism
116
+     */
117
+    public function getLegacyAuthMechanism(array $parameters = []) {
118
+        if (is_callable($this->legacyAuthMechanism)) {
119
+            return call_user_func($this->legacyAuthMechanism, $parameters);
120
+        }
121
+        return $this->legacyAuthMechanism;
122
+    }
123
+
124
+    public function setLegacyAuthMechanism(AuthMechanism $authMechanism): self {
125
+        $this->legacyAuthMechanism = $authMechanism;
126
+        return $this;
127
+    }
128
+
129
+    /**
130
+     * @param callable $callback dynamic auth mechanism selection
131
+     */
132
+    public function setLegacyAuthMechanismCallback(callable $callback): self {
133
+        $this->legacyAuthMechanism = $callback;
134
+        return $this;
135
+    }
136
+
137
+    /**
138
+     * Serialize into JSON for client-side JS
139
+     */
140
+    public function jsonSerialize(): array {
141
+        $data = $this->jsonSerializeDefinition();
142
+        $data += $this->jsonSerializeIdentifier();
143
+
144
+        $data['backend'] = $data['name']; // legacy compat
145
+        $data['priority'] = $this->getPriority();
146
+        $data['authSchemes'] = $this->getAuthSchemes();
147
+
148
+        return $data;
149
+    }
150
+
151
+    /**
152
+     * Check if parameters are satisfied in a StorageConfig
153
+     *
154
+     * @param StorageConfig $storage
155
+     * @return bool
156
+     */
157
+    public function validateStorage(StorageConfig $storage) {
158
+        return $this->validateStorageDefinition($storage);
159
+    }
160 160
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/IIdentifier.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
 
22 22
 interface IIdentifier {
23 23
 
24
-	public function getIdentifier(): string;
24
+    public function getIdentifier(): string;
25 25
 
26
-	public function setIdentifier(string $identifier): self;
26
+    public function setIdentifier(string $identifier): self;
27 27
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/ListCommand.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 			$mounts = $this->globalService->getStorageForAllUsers();
88 88
 			$userId = self::ALL;
89 89
 		} else {
90
-			$userId = (string)$input->getArgument('user_id');
90
+			$userId = (string) $input->getArgument('user_id');
91 91
 			$storageService = $this->getStorageService($userId);
92 92
 			$mounts = $storageService->getAllStorages();
93 93
 		}
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
 		}
141 141
 
142 142
 		if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
143
-			$keys = array_map(function ($header) {
143
+			$keys = array_map(function($header) {
144 144
 				return strtolower(str_replace(' ', '_', $header));
145 145
 			}, $headers);
146 146
 
147
-			$pairs = array_map(function (StorageConfig $config) use ($keys, $userId) {
147
+			$pairs = array_map(function(StorageConfig $config) use ($keys, $userId) {
148 148
 				$values = [
149 149
 					$config->getId(),
150 150
 					$config->getMountPoint(),
@@ -178,23 +178,23 @@  discard block
 block discarded – undo
178 178
 				'encoding_compatibility' => false,
179 179
 				'readonly' => false,
180 180
 			];
181
-			$rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) {
181
+			$rows = array_map(function(StorageConfig $config) use ($userId, $defaultMountOptions, $full) {
182 182
 				$storageConfig = $config->getBackendOptions();
183 183
 				$keys = array_keys($storageConfig);
184 184
 				$values = array_values($storageConfig);
185 185
 
186 186
 				if (!$full) {
187
-					$values = array_map(function ($value) {
187
+					$values = array_map(function($value) {
188 188
 						if (is_string($value) && strlen($value) > 32) {
189
-							return substr($value, 0, 6) . '...' . substr($value, -6, 6);
189
+							return substr($value, 0, 6).'...'.substr($value, -6, 6);
190 190
 						} else {
191 191
 							return $value;
192 192
 						}
193 193
 					}, $values);
194 194
 				}
195 195
 
196
-				$configStrings = array_map(function ($key, $value) {
197
-					return $key . ': ' . json_encode($value);
196
+				$configStrings = array_map(function($key, $value) {
197
+					return $key.': '.json_encode($value);
198 198
 				}, $keys, $values);
199 199
 				$configString = implode(', ', $configStrings);
200 200
 
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 				$keys = array_keys($mountOptions);
209 209
 				$values = array_values($mountOptions);
210 210
 
211
-				$optionsStrings = array_map(function ($key, $value) {
212
-					return $key . ': ' . json_encode($value);
211
+				$optionsStrings = array_map(function($key, $value) {
212
+					return $key.': '.json_encode($value);
213 213
 				}, $keys, $values);
214 214
 				$optionsString = implode(', ', $optionsStrings);
215 215
 
Please login to merge, or discard this patch.
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -21,218 +21,218 @@
 block discarded – undo
21 21
 use Symfony\Component\Console\Output\OutputInterface;
22 22
 
23 23
 class ListCommand extends Base {
24
-	public const ALL = -1;
25
-
26
-	public function __construct(
27
-		protected GlobalStoragesService $globalService,
28
-		protected UserStoragesService $userService,
29
-		protected IUserSession $userSession,
30
-		protected IUserManager $userManager,
31
-	) {
32
-		parent::__construct();
33
-	}
34
-
35
-	protected function configure(): void {
36
-		$this
37
-			->setName('files_external:list')
38
-			->setDescription('List configured admin or personal mounts')
39
-			->addArgument(
40
-				'user_id',
41
-				InputArgument::OPTIONAL,
42
-				'user id to list the personal mounts for, if no user is provided admin mounts will be listed'
43
-			)->addOption(
44
-				'show-password',
45
-				'',
46
-				InputOption::VALUE_NONE,
47
-				'show passwords and secrets'
48
-			)->addOption(
49
-				'full',
50
-				null,
51
-				InputOption::VALUE_NONE,
52
-				'don\'t truncate long values in table output'
53
-			)->addOption(
54
-				'all',
55
-				'a',
56
-				InputOption::VALUE_NONE,
57
-				'show both system wide mounts and all personal mounts'
58
-			);
59
-		parent::configure();
60
-	}
61
-
62
-	protected function execute(InputInterface $input, OutputInterface $output): int {
63
-		/** @var StorageConfig[] $mounts */
64
-		if ($input->getOption('all')) {
65
-			$mounts = $this->globalService->getStorageForAllUsers();
66
-			$userId = self::ALL;
67
-		} else {
68
-			$userId = (string)$input->getArgument('user_id');
69
-			$storageService = $this->getStorageService($userId);
70
-			$mounts = $storageService->getAllStorages();
71
-		}
72
-
73
-		$this->listMounts($userId, $mounts, $input, $output);
74
-		return self::SUCCESS;
75
-	}
76
-
77
-	/**
78
-	 * @param ?string|ListCommand::ALL $userId
79
-	 * @param StorageConfig[] $mounts
80
-	 */
81
-	public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output): void {
82
-		$outputType = $input->getOption('output');
83
-		if (count($mounts) === 0) {
84
-			if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
85
-				$output->writeln('[]');
86
-			} else {
87
-				if ($userId === self::ALL) {
88
-					$output->writeln('<info>No mounts configured</info>');
89
-				} elseif ($userId) {
90
-					$output->writeln("<info>No mounts configured by $userId</info>");
91
-				} else {
92
-					$output->writeln('<info>No admin mounts configured</info>');
93
-				}
94
-			}
95
-			return;
96
-		}
97
-
98
-		$headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options'];
99
-
100
-		if (!$userId || $userId === self::ALL) {
101
-			$headers[] = 'Applicable Users';
102
-			$headers[] = 'Applicable Groups';
103
-		}
104
-		if ($userId === self::ALL) {
105
-			$headers[] = 'Type';
106
-		}
107
-
108
-		if (!$input->getOption('show-password')) {
109
-			$hideKeys = ['key', 'bucket', 'secret', 'password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key'];
110
-			foreach ($mounts as $mount) {
111
-				$config = $mount->getBackendOptions();
112
-				foreach ($config as $key => $value) {
113
-					if (in_array($key, $hideKeys)) {
114
-						$mount->setBackendOption($key, '***REMOVED SENSITIVE VALUE***');
115
-					}
116
-				}
117
-			}
118
-		}
119
-
120
-		if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
121
-			$keys = array_map(function ($header) {
122
-				return strtolower(str_replace(' ', '_', $header));
123
-			}, $headers);
124
-
125
-			$pairs = array_map(function (StorageConfig $config) use ($keys, $userId) {
126
-				$values = [
127
-					$config->getId(),
128
-					$config->getMountPoint(),
129
-					$config->getBackend()->getStorageClass(),
130
-					$config->getAuthMechanism()->getIdentifier(),
131
-					$config->getBackendOptions(),
132
-					$config->getMountOptions()
133
-				];
134
-				if (!$userId || $userId === self::ALL) {
135
-					$values[] = $config->getApplicableUsers();
136
-					$values[] = $config->getApplicableGroups();
137
-				}
138
-				if ($userId === self::ALL) {
139
-					$values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal';
140
-				}
141
-
142
-				return array_combine($keys, $values);
143
-			}, $mounts);
144
-			if ($outputType === self::OUTPUT_FORMAT_JSON) {
145
-				$output->writeln(json_encode(array_values($pairs)));
146
-			} else {
147
-				$output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT));
148
-			}
149
-		} else {
150
-			$full = $input->getOption('full');
151
-			$defaultMountOptions = [
152
-				'encrypt' => true,
153
-				'previews' => true,
154
-				'filesystem_check_changes' => 1,
155
-				'enable_sharing' => false,
156
-				'encoding_compatibility' => false,
157
-				'readonly' => false,
158
-			];
159
-			$rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) {
160
-				$storageConfig = $config->getBackendOptions();
161
-				$keys = array_keys($storageConfig);
162
-				$values = array_values($storageConfig);
163
-
164
-				if (!$full) {
165
-					$values = array_map(function ($value) {
166
-						if (is_string($value) && strlen($value) > 32) {
167
-							return substr($value, 0, 6) . '...' . substr($value, -6, 6);
168
-						} else {
169
-							return $value;
170
-						}
171
-					}, $values);
172
-				}
173
-
174
-				$configStrings = array_map(function ($key, $value) {
175
-					return $key . ': ' . json_encode($value);
176
-				}, $keys, $values);
177
-				$configString = implode(', ', $configStrings);
178
-
179
-				$mountOptions = $config->getMountOptions();
180
-				// hide defaults
181
-				foreach ($mountOptions as $key => $value) {
182
-					if ($value === $defaultMountOptions[$key]) {
183
-						unset($mountOptions[$key]);
184
-					}
185
-				}
186
-				$keys = array_keys($mountOptions);
187
-				$values = array_values($mountOptions);
188
-
189
-				$optionsStrings = array_map(function ($key, $value) {
190
-					return $key . ': ' . json_encode($value);
191
-				}, $keys, $values);
192
-				$optionsString = implode(', ', $optionsStrings);
193
-
194
-				$values = [
195
-					$config->getId(),
196
-					$config->getMountPoint(),
197
-					$config->getBackend()->getText(),
198
-					$config->getAuthMechanism()->getText(),
199
-					$configString,
200
-					$optionsString
201
-				];
202
-
203
-				if (!$userId || $userId === self::ALL) {
204
-					$applicableUsers = implode(', ', $config->getApplicableUsers());
205
-					$applicableGroups = implode(', ', $config->getApplicableGroups());
206
-					if ($applicableUsers === '' && $applicableGroups === '') {
207
-						$applicableUsers = 'All';
208
-					}
209
-					$values[] = $applicableUsers;
210
-					$values[] = $applicableGroups;
211
-				}
212
-				if ($userId === self::ALL) {
213
-					$values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal';
214
-				}
215
-
216
-				return $values;
217
-			}, $mounts);
218
-
219
-			$table = new Table($output);
220
-			$table->setHeaders($headers);
221
-			$table->setRows($rows);
222
-			$table->render();
223
-		}
224
-	}
225
-
226
-	protected function getStorageService(string $userId): StoragesService {
227
-		if (empty($userId)) {
228
-			return $this->globalService;
229
-		}
230
-
231
-		$user = $this->userManager->get($userId);
232
-		if (is_null($user)) {
233
-			throw new NoUserException("user $userId not found");
234
-		}
235
-		$this->userSession->setUser($user);
236
-		return $this->userService;
237
-	}
24
+    public const ALL = -1;
25
+
26
+    public function __construct(
27
+        protected GlobalStoragesService $globalService,
28
+        protected UserStoragesService $userService,
29
+        protected IUserSession $userSession,
30
+        protected IUserManager $userManager,
31
+    ) {
32
+        parent::__construct();
33
+    }
34
+
35
+    protected function configure(): void {
36
+        $this
37
+            ->setName('files_external:list')
38
+            ->setDescription('List configured admin or personal mounts')
39
+            ->addArgument(
40
+                'user_id',
41
+                InputArgument::OPTIONAL,
42
+                'user id to list the personal mounts for, if no user is provided admin mounts will be listed'
43
+            )->addOption(
44
+                'show-password',
45
+                '',
46
+                InputOption::VALUE_NONE,
47
+                'show passwords and secrets'
48
+            )->addOption(
49
+                'full',
50
+                null,
51
+                InputOption::VALUE_NONE,
52
+                'don\'t truncate long values in table output'
53
+            )->addOption(
54
+                'all',
55
+                'a',
56
+                InputOption::VALUE_NONE,
57
+                'show both system wide mounts and all personal mounts'
58
+            );
59
+        parent::configure();
60
+    }
61
+
62
+    protected function execute(InputInterface $input, OutputInterface $output): int {
63
+        /** @var StorageConfig[] $mounts */
64
+        if ($input->getOption('all')) {
65
+            $mounts = $this->globalService->getStorageForAllUsers();
66
+            $userId = self::ALL;
67
+        } else {
68
+            $userId = (string)$input->getArgument('user_id');
69
+            $storageService = $this->getStorageService($userId);
70
+            $mounts = $storageService->getAllStorages();
71
+        }
72
+
73
+        $this->listMounts($userId, $mounts, $input, $output);
74
+        return self::SUCCESS;
75
+    }
76
+
77
+    /**
78
+     * @param ?string|ListCommand::ALL $userId
79
+     * @param StorageConfig[] $mounts
80
+     */
81
+    public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output): void {
82
+        $outputType = $input->getOption('output');
83
+        if (count($mounts) === 0) {
84
+            if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
85
+                $output->writeln('[]');
86
+            } else {
87
+                if ($userId === self::ALL) {
88
+                    $output->writeln('<info>No mounts configured</info>');
89
+                } elseif ($userId) {
90
+                    $output->writeln("<info>No mounts configured by $userId</info>");
91
+                } else {
92
+                    $output->writeln('<info>No admin mounts configured</info>');
93
+                }
94
+            }
95
+            return;
96
+        }
97
+
98
+        $headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options'];
99
+
100
+        if (!$userId || $userId === self::ALL) {
101
+            $headers[] = 'Applicable Users';
102
+            $headers[] = 'Applicable Groups';
103
+        }
104
+        if ($userId === self::ALL) {
105
+            $headers[] = 'Type';
106
+        }
107
+
108
+        if (!$input->getOption('show-password')) {
109
+            $hideKeys = ['key', 'bucket', 'secret', 'password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key'];
110
+            foreach ($mounts as $mount) {
111
+                $config = $mount->getBackendOptions();
112
+                foreach ($config as $key => $value) {
113
+                    if (in_array($key, $hideKeys)) {
114
+                        $mount->setBackendOption($key, '***REMOVED SENSITIVE VALUE***');
115
+                    }
116
+                }
117
+            }
118
+        }
119
+
120
+        if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
121
+            $keys = array_map(function ($header) {
122
+                return strtolower(str_replace(' ', '_', $header));
123
+            }, $headers);
124
+
125
+            $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) {
126
+                $values = [
127
+                    $config->getId(),
128
+                    $config->getMountPoint(),
129
+                    $config->getBackend()->getStorageClass(),
130
+                    $config->getAuthMechanism()->getIdentifier(),
131
+                    $config->getBackendOptions(),
132
+                    $config->getMountOptions()
133
+                ];
134
+                if (!$userId || $userId === self::ALL) {
135
+                    $values[] = $config->getApplicableUsers();
136
+                    $values[] = $config->getApplicableGroups();
137
+                }
138
+                if ($userId === self::ALL) {
139
+                    $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal';
140
+                }
141
+
142
+                return array_combine($keys, $values);
143
+            }, $mounts);
144
+            if ($outputType === self::OUTPUT_FORMAT_JSON) {
145
+                $output->writeln(json_encode(array_values($pairs)));
146
+            } else {
147
+                $output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT));
148
+            }
149
+        } else {
150
+            $full = $input->getOption('full');
151
+            $defaultMountOptions = [
152
+                'encrypt' => true,
153
+                'previews' => true,
154
+                'filesystem_check_changes' => 1,
155
+                'enable_sharing' => false,
156
+                'encoding_compatibility' => false,
157
+                'readonly' => false,
158
+            ];
159
+            $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) {
160
+                $storageConfig = $config->getBackendOptions();
161
+                $keys = array_keys($storageConfig);
162
+                $values = array_values($storageConfig);
163
+
164
+                if (!$full) {
165
+                    $values = array_map(function ($value) {
166
+                        if (is_string($value) && strlen($value) > 32) {
167
+                            return substr($value, 0, 6) . '...' . substr($value, -6, 6);
168
+                        } else {
169
+                            return $value;
170
+                        }
171
+                    }, $values);
172
+                }
173
+
174
+                $configStrings = array_map(function ($key, $value) {
175
+                    return $key . ': ' . json_encode($value);
176
+                }, $keys, $values);
177
+                $configString = implode(', ', $configStrings);
178
+
179
+                $mountOptions = $config->getMountOptions();
180
+                // hide defaults
181
+                foreach ($mountOptions as $key => $value) {
182
+                    if ($value === $defaultMountOptions[$key]) {
183
+                        unset($mountOptions[$key]);
184
+                    }
185
+                }
186
+                $keys = array_keys($mountOptions);
187
+                $values = array_values($mountOptions);
188
+
189
+                $optionsStrings = array_map(function ($key, $value) {
190
+                    return $key . ': ' . json_encode($value);
191
+                }, $keys, $values);
192
+                $optionsString = implode(', ', $optionsStrings);
193
+
194
+                $values = [
195
+                    $config->getId(),
196
+                    $config->getMountPoint(),
197
+                    $config->getBackend()->getText(),
198
+                    $config->getAuthMechanism()->getText(),
199
+                    $configString,
200
+                    $optionsString
201
+                ];
202
+
203
+                if (!$userId || $userId === self::ALL) {
204
+                    $applicableUsers = implode(', ', $config->getApplicableUsers());
205
+                    $applicableGroups = implode(', ', $config->getApplicableGroups());
206
+                    if ($applicableUsers === '' && $applicableGroups === '') {
207
+                        $applicableUsers = 'All';
208
+                    }
209
+                    $values[] = $applicableUsers;
210
+                    $values[] = $applicableGroups;
211
+                }
212
+                if ($userId === self::ALL) {
213
+                    $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal';
214
+                }
215
+
216
+                return $values;
217
+            }, $mounts);
218
+
219
+            $table = new Table($output);
220
+            $table->setHeaders($headers);
221
+            $table->setRows($rows);
222
+            $table->render();
223
+        }
224
+    }
225
+
226
+    protected function getStorageService(string $userId): StoragesService {
227
+        if (empty($userId)) {
228
+            return $this->globalService;
229
+        }
230
+
231
+        $user = $this->userManager->get($userId);
232
+        if (is_null($user)) {
233
+            throw new NoUserException("user $userId not found");
234
+        }
235
+        $this->userSession->setUser($user);
236
+        return $this->userService;
237
+    }
238 238
 }
Please login to merge, or discard this patch.
lib/public/Support/Subscription/IAssertion.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@
 block discarded – undo
32 32
  * @since 26.0.0
33 33
  */
34 34
 interface IAssertion {
35
-	/**
36
-	 * This method throws a localized exception when user limits are exceeded,
37
-	 * if applicable. Notifications are also created in that case. It is a
38
-	 * shorthand for a check against IRegistry::delegateIsHardUserLimitReached().
39
-	 *
40
-	 * @throws HintException
41
-	 * @since 26.0.0
42
-	 */
43
-	public function createUserIsLegit(): void;
35
+    /**
36
+     * This method throws a localized exception when user limits are exceeded,
37
+     * if applicable. Notifications are also created in that case. It is a
38
+     * shorthand for a check against IRegistry::delegateIsHardUserLimitReached().
39
+     *
40
+     * @throws HintException
41
+     * @since 26.0.0
42
+     */
43
+    public function createUserIsLegit(): void;
44 44
 }
Please login to merge, or discard this patch.