Skip to content

Commit 4b274a8

Browse files
Merge pull request #55830 from nextcloud/fix/noid/lazy-from-construct
fix(files-external): do not load lazy appconfig from construct
2 parents be1af13 + 07d3f1c commit 4b274a8

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

apps/files_external/lib/Service/BackendService.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace OCA\Files_External\Service;
99

10+
use OCA\Files_External\AppInfo\Application;
1011
use OCA\Files_External\Config\IConfigHandler;
1112
use OCA\Files_External\ConfigLexicon;
1213
use OCA\Files_External\Lib\Auth\AuthMechanism;
@@ -35,11 +36,9 @@ class BackendService {
3536
/** Priority constants for PriorityTrait */
3637
public const PRIORITY_DEFAULT = 100;
3738

38-
/** @var bool */
39-
private $userMountingAllowed = true;
40-
39+
private ?bool $userMountingAllowed = null;
4140
/** @var string[] */
42-
private $userMountingBackends = [];
41+
private array $userMountingBackends = [];
4342

4443
/** @var Backend[] */
4544
private $backends = [];
@@ -59,16 +58,8 @@ class BackendService {
5958
private $configHandlers = [];
6059

6160
public function __construct(
62-
protected IAppConfig $appConfig,
61+
protected readonly IAppConfig $appConfig,
6362
) {
64-
// Load config values
65-
$this->userMountingAllowed = $appConfig->getValueBool('files_external', ConfigLexicon::ALLOW_USER_MOUNTING);
66-
$this->userMountingBackends = explode(',', $appConfig->getValueString('files_external', ConfigLexicon::USER_MOUNTING_BACKENDS));
67-
68-
// if no backend is in the list an empty string is in the array and user mounting is disabled
69-
if ($this->userMountingBackends === ['']) {
70-
$this->userMountingAllowed = false;
71-
}
7263
}
7364

7465
/**
@@ -246,9 +237,23 @@ public function getAuthMechanism($identifier) {
246237
}
247238

248239
/**
249-
* @return bool
240+
* returns if user mounting is allowed.
241+
* also initiate the list of available backends.
242+
*
243+
* @psalm-assert bool $this->userMountingAllowed
250244
*/
251-
public function isUserMountingAllowed() {
245+
public function isUserMountingAllowed(): bool {
246+
if ($this->userMountingAllowed === null) {
247+
// Load config values
248+
$this->userMountingAllowed = $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::ALLOW_USER_MOUNTING);
249+
$this->userMountingBackends = explode(',', $this->appConfig->getValueString(Application::APP_ID, ConfigLexicon::USER_MOUNTING_BACKENDS));
250+
251+
// if no backend is in the list an empty string is in the array and user mounting is disabled
252+
if ($this->userMountingBackends === ['']) {
253+
$this->userMountingAllowed = false;
254+
}
255+
}
256+
252257
return $this->userMountingAllowed;
253258
}
254259

@@ -258,13 +263,8 @@ public function isUserMountingAllowed() {
258263
* @param Backend $backend
259264
* @return bool
260265
*/
261-
protected function isAllowedUserBackend(Backend $backend) {
262-
if ($this->userMountingAllowed
263-
&& array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends)
264-
) {
265-
return true;
266-
}
267-
return false;
266+
protected function isAllowedUserBackend(Backend $backend): bool {
267+
return ($this->isUserMountingAllowed() && array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends));
268268
}
269269

270270
/**

0 commit comments

Comments
 (0)