Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions apps/files_external/lib/Service/BackendService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OCA\Files_External\Service;

use OCA\Files_External\AppInfo\Application;
use OCA\Files_External\Config\IConfigHandler;
use OCA\Files_External\ConfigLexicon;
use OCA\Files_External\Lib\Auth\AuthMechanism;
Expand Down Expand Up @@ -35,11 +36,9 @@ class BackendService {
/** Priority constants for PriorityTrait */
public const PRIORITY_DEFAULT = 100;

/** @var bool */
private $userMountingAllowed = true;

private ?bool $userMountingAllowed = null;
/** @var string[] */
private $userMountingBackends = [];
private array $userMountingBackends = [];

/** @var Backend[] */
private $backends = [];
Expand All @@ -59,16 +58,8 @@ class BackendService {
private $configHandlers = [];

public function __construct(
protected IAppConfig $appConfig,
protected readonly IAppConfig $appConfig,
) {
// Load config values
$this->userMountingAllowed = $appConfig->getValueBool('files_external', ConfigLexicon::ALLOW_USER_MOUNTING);
$this->userMountingBackends = explode(',', $appConfig->getValueString('files_external', ConfigLexicon::USER_MOUNTING_BACKENDS));

// if no backend is in the list an empty string is in the array and user mounting is disabled
if ($this->userMountingBackends === ['']) {
$this->userMountingAllowed = false;
}
}

/**
Expand Down Expand Up @@ -246,9 +237,23 @@ public function getAuthMechanism($identifier) {
}

/**
* @return bool
* returns if user mounting is allowed.
* also initiate the list of available backends.
*
* @psalm-assert bool $this->userMountingAllowed
*/
public function isUserMountingAllowed() {
public function isUserMountingAllowed(): bool {
if ($this->userMountingAllowed === null) {
// Load config values
$this->userMountingAllowed = $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::ALLOW_USER_MOUNTING);
$this->userMountingBackends = explode(',', $this->appConfig->getValueString(Application::APP_ID, ConfigLexicon::USER_MOUNTING_BACKENDS));

// if no backend is in the list an empty string is in the array and user mounting is disabled
if ($this->userMountingBackends === ['']) {
$this->userMountingAllowed = false;
}
}

return $this->userMountingAllowed;
}

Expand All @@ -258,13 +263,8 @@ public function isUserMountingAllowed() {
* @param Backend $backend
* @return bool
*/
protected function isAllowedUserBackend(Backend $backend) {
if ($this->userMountingAllowed
&& array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends)
) {
return true;
}
return false;
protected function isAllowedUserBackend(Backend $backend): bool {
return ($this->isUserMountingAllowed() && array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends));
}

/**
Expand Down
Loading