Small StorageType change

This commit is contained in:
the-djmaze 2024-02-26 16:44:25 +01:00
parent 2559c09b23
commit ab748aab99
5 changed files with 70 additions and 58 deletions

View file

@ -12,7 +12,7 @@ class NextcloudStorage extends \RainLoop\Providers\Storage\FileStorage
$sDataPath = parent::GenerateFilePath($mAccount, $iStorageType, $bMkDir);
if (StorageType::CONFIG === $iStorageType) {
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
$sDataPath .= "/.config/{$sUID}/";
$sDataPath .= ".config/{$sUID}/";
if ($bMkDir && !\is_dir($sDataPath) && !\mkdir($sDataPath, 0700, true)) {
throw new \RainLoop\Exceptions\Exception('Can\'t make storage directory "'.$sDataPath.'"');
}

View file

@ -306,4 +306,11 @@ abstract class Account implements \JsonSerializable
return $bResult;
}
/*
// Stores settings in AdditionalAccount else MainAccount
public function settingsLocal() : \RainLoop\Settings
{
return \RainLoop\Api::Actions()->SettingsProvider(true)->Load($this);
}
*/
}

View file

@ -63,4 +63,11 @@ class MainAccount extends Account
{
$this->sCryptKey = new SensitiveString($sKey);
}
/*
// Stores settings in MainAccount
public function settings() : \RainLoop\Settings
{
return \RainLoop\Api::Actions()->SettingsProvider()->Load($this);
}
*/
}

View file

@ -10,11 +10,10 @@ enum StorageType: int {
*/
abstract class StorageType
{
const USER = 1;
const CONFIG = 2;
const NOBODY = 3;
const SIGN_ME = 4;
const SESSION = 5;
const PGP = 6;
const ROOT = 7;
const CONFIG = 1;
const NOBODY = 2;
const SIGN_ME = 3;
const SESSION = 4;
const PGP = 5;
const ROOT = 6;
}

View file

@ -90,58 +90,57 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
*/
public function GenerateFilePath($mAccount, int $iStorageType, bool $bMkDir = false) : string
{
$sEmail = $sSubFolder = '';
if (null === $mAccount) {
$iStorageType = StorageType::NOBODY;
} else if ($mAccount instanceof \RainLoop\Model\MainAccount) {
$sEmail = $mAccount->Email();
} else if ($mAccount instanceof \RainLoop\Model\AdditionalAccount) {
$sEmail = $mAccount->ParentEmail();
if ($this->bLocal) {
$sSubFolder = $mAccount->Email();
}
} else if (\is_string($mAccount)) {
$sEmail = $mAccount;
}
if ($sEmail) {
if (StorageType::SIGN_ME === $iStorageType) {
$sSubFolder = '.sign_me';
} else if (StorageType::SESSION === $iStorageType) {
$sSubFolder = '.sessions';
} else if (StorageType::PGP === $iStorageType) {
$sSubFolder = '.pgp';
} else if (StorageType::ROOT === $iStorageType) {
$sSubFolder = '';
}
}
$sFilePath = '';
switch ($iStorageType)
{
case StorageType::NOBODY:
$sFilePath = $this->sDataPath.'/__nobody__/';
break;
case StorageType::SIGN_ME:
case StorageType::SESSION:
case StorageType::CONFIG:
case StorageType::PGP:
case StorageType::ROOT:
if (empty($sEmail)) {
return '';
$sEmail = $sSubFolder = $sFilePath = '';
if (null === $mAccount || StorageType::NOBODY === $iStorageType) {
$sFilePath = $this->sDataPath.'/__nobody__/';
} else {
if ($mAccount instanceof \RainLoop\Model\MainAccount) {
$sEmail = $mAccount->Email();
} else if ($mAccount instanceof \RainLoop\Model\AdditionalAccount) {
$sEmail = $mAccount->ParentEmail();
if ($this->bLocal) {
$sSubFolder = $mAccount->Email();
}
if (\is_dir("{$this->sDataPath}/cfg")) {
\SnappyMail\Upgrade::FileStorage($this->sDataPath);
} else if (\is_string($mAccount)) {
$sEmail = $mAccount;
}
if ($sEmail) {
// these are never local
if (StorageType::SIGN_ME === $iStorageType) {
$sSubFolder = '.sign_me';
} else if (StorageType::SESSION === $iStorageType) {
$sSubFolder = '.sessions';
} else if (StorageType::PGP === $iStorageType) {
$sSubFolder = '.pgp';
} else if (StorageType::ROOT === $iStorageType) {
$sSubFolder = '';
}
$aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld');
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
$sFilePath = $this->sDataPath
.'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld')
.'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown')
.'/'.($sSubFolder ? \MailSo\Base\Utils::SecureFileName($sSubFolder).'/' : '');
break;
default:
throw new \Exception("Invalid storage type {$iStorageType}");
}
switch ($iStorageType)
{
case StorageType::CONFIG:
case StorageType::SIGN_ME:
case StorageType::SESSION:
case StorageType::PGP:
case StorageType::ROOT:
if (empty($sEmail)) {
return '';
}
if (\is_dir("{$this->sDataPath}/cfg")) {
\SnappyMail\Upgrade::FileStorage($this->sDataPath);
}
$aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld');
$sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : '');
$sFilePath = $this->sDataPath
.'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld')
.'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown')
.'/'.($sSubFolder ? \MailSo\Base\Utils::SecureFileName($sSubFolder).'/' : '');
break;
default:
throw new \Exception("Invalid storage type {$iStorageType}");
}
}
if ($bMkDir && !empty($sFilePath) && !\is_dir($sFilePath) && !\mkdir($sFilePath, 0700, true))