Don't load Capa at login page and cleanup/speedup GetCapa

This commit is contained in:
the-djmaze 2022-02-03 23:04:55 +01:00
parent ad269597d6
commit 6df9aaae43
8 changed files with 34 additions and 31 deletions

View file

@ -509,7 +509,7 @@ class Actions
{
if (null === $this->oAddressBookProvider) {
$oDriver = null;
if ($this->GetCapa(false, Enumerations\Capa::CONTACTS, $oAccount)) {
if ($this->GetCapa(Enumerations\Capa::CONTACTS)) {
if ($this->oConfig->Get('contacts', 'enable', false) || $bForceEnable) {
$oDriver = $this->fabrica('address-book', $oAccount);
}
@ -643,7 +643,7 @@ class Actions
$oConfig = $this->oConfig;
$aAttachmentsActions = array();
if ($this->GetCapa(false, Enumerations\Capa::ATTACHMENTS_ACTIONS)) {
if ($this->GetCapa(Enumerations\Capa::ATTACHMENTS_ACTIONS)) {
if (\class_exists('PharData') || \class_exists('ZipArchive')) {
$aAttachmentsActions[] = 'zip';
}
@ -784,7 +784,6 @@ class Actions
$aResult['WeakPassword'] = \is_file($passfile);
}
$aResult['Capa'] = $this->Capa(true);
$aResult['LanguageAdmin'] = $this->ValidateLanguage($oConfig->Get('webmail', 'language_admin', 'en'), '', true);
$aResult['UserLanguageAdmin'] = $this->ValidateLanguage($UserLanguageRaw, '', true, true);
} else {
@ -867,11 +866,11 @@ class Actions
$aResult['AutoLogout'] = (int)$oSettings->GetConf('AutoLogout', $aResult['AutoLogout']);
$aResult['Layout'] = (int)$oSettings->GetConf('Layout', $aResult['Layout']);
if (!$this->GetCapa(false, Enumerations\Capa::AUTOLOGOUT, $oAccount)) {
if (!$this->GetCapa(Enumerations\Capa::AUTOLOGOUT)) {
$aResult['AutoLogout'] = 0;
}
if ($this->GetCapa(false, Enumerations\Capa::USER_BACKGROUND, $oAccount)) {
if ($this->GetCapa(Enumerations\Capa::USER_BACKGROUND)) {
$aResult['UserBackgroundName'] = (string)$oSettings->GetConf('UserBackgroundName', $aResult['UserBackgroundName']);
$aResult['UserBackgroundHash'] = (string)$oSettings->GetConf('UserBackgroundHash', $aResult['UserBackgroundHash']);
}
@ -894,11 +893,10 @@ class Actions
$aResult['AdditionalLoginError'] = $this->GetSpecLogoutCustomMgsWithDeletion();
}
}
$aResult['Capa'] = $this->Capa(false, $oAccount);
}
if ($aResult['Auth']) {
$aResult['Capa'] = $this->Capa($bAdmin, $oAccount);
$aResult['PhpUploadSizes'] = array(
'upload_max_filesize' => \ini_get('upload_max_filesize'),
'post_max_size' => \ini_get('post_max_size')
@ -1081,7 +1079,7 @@ class Actions
{
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(false, Enumerations\Capa::USER_BACKGROUND, $oAccount)) {
if (!$this->GetCapa(Enumerations\Capa::USER_BACKGROUND)) {
return $this->FalseResponse(__FUNCTION__);
}
@ -1160,9 +1158,16 @@ class Actions
public function Capa(bool $bAdmin, ?Model\Account $oAccount = null): array
{
static $aResult;
if ($aResult && !$oAccount) {
return $aResult;
}
$oConfig = $this->oConfig;
$aResult = array();
$aResult = array(
Enumerations\Capa::AUTOLOGOUT
);
if ($oConfig->Get('capa', 'dangerous_actions', true)) {
$aResult[] = Enumerations\Capa::DANGEROUS_ACTIONS;
@ -1231,14 +1236,12 @@ class Actions
$aResult[] = Enumerations\Capa::KOLAB;
}
$aResult[] = Enumerations\Capa::AUTOLOGOUT;
return $aResult;
}
public function GetCapa(bool $bAdmin, string $sName, ?Model\Account $oAccount = null): bool
public function GetCapa(string $sName, ?Model\Account $oAccount = null): bool
{
return \in_array($sName, $this->Capa($bAdmin, $oAccount));
return \in_array($sName, $this->Capa(false, $oAccount));
}
public function etag(string $sKey): string

View file

@ -36,7 +36,7 @@ trait Accounts
public function GetAccounts(MainAccount $oAccount): array
{
if ($this->GetCapa(false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) {
if ($this->GetCapa(Capa::ADDITIONAL_ACCOUNTS)) {
$sAccounts = $this->StorageProvider()->Get($oAccount,
StorageType::CONFIG,
'additionalaccounts'
@ -76,7 +76,7 @@ trait Accounts
{
$oMainAccount = $this->getMainAccountFromToken();
if (!$this->GetCapa(false, Capa::ADDITIONAL_ACCOUNTS, $oMainAccount)) {
if (!$this->GetCapa(Capa::ADDITIONAL_ACCOUNTS)) {
return $this->FalseResponse(__FUNCTION__);
}
@ -108,7 +108,7 @@ trait Accounts
{
$oMainAccount = $this->getMainAccountFromToken();
if (!$this->GetCapa(false, Capa::ADDITIONAL_ACCOUNTS, $oMainAccount)) {
if (!$this->GetCapa(Capa::ADDITIONAL_ACCOUNTS)) {
return $this->FalseResponse(__FUNCTION__);
}
@ -190,7 +190,7 @@ trait Accounts
{
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(false, Capa::IDENTITIES, $oAccount)) {
if (!$this->GetCapa(Capa::IDENTITIES)) {
return $this->FalseResponse(__FUNCTION__);
}
@ -254,7 +254,7 @@ trait Accounts
public function GetIdentities(Account $oAccount): array
{
// A custom name for a single identity is also stored in this system
$allowMultipleIdentities = $this->GetCapa(false, Capa::IDENTITIES, $oAccount);
$allowMultipleIdentities = $this->GetCapa(Capa::IDENTITIES);
// Get all identities
$identities = $this->IdentitiesProvider()->GetIdentities($oAccount, $allowMultipleIdentities);

View file

@ -18,7 +18,7 @@ trait Filters
{
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(false, Capa::SIEVE, $oAccount))
if (!$this->GetCapa(Capa::SIEVE, $oAccount))
{
return $this->FalseResponse(__FUNCTION__);
}
@ -33,7 +33,7 @@ trait Filters
{
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(false, Capa::SIEVE, $oAccount)) {
if (!$this->GetCapa(Capa::SIEVE, $oAccount)) {
return $this->FalseResponse(__FUNCTION__);
}
@ -68,7 +68,7 @@ trait Filters
{
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(false, Capa::SIEVE, $oAccount)) {
if (!$this->GetCapa(Capa::SIEVE, $oAccount)) {
return $this->FalseResponse(__FUNCTION__);
}
@ -84,7 +84,7 @@ trait Filters
{
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(false, Capa::SIEVE, $oAccount)) {
if (!$this->GetCapa(Capa::SIEVE, $oAccount)) {
return $this->FalseResponse(__FUNCTION__);
}

View file

@ -177,7 +177,7 @@ trait Folders
$this->Plugins()->RunHook('filter.folders-complete', array($oAccount, $oFolderCollection));
$aQuota = null;
if ($this->GetCapa(false, Capa::QUOTA, $this->getAccountFromToken())) {
if ($this->GetCapa(Capa::QUOTA)) {
try {
// $aQuota = $this->MailClient()->Quota();
$aQuota = $this->MailClient()->QuotaRoot();

View file

@ -210,7 +210,7 @@ trait Response
$mResult['Html'] = $mResponse->Html();
$mResult['Plain'] = $mResponse->Plain();
// $this->GetCapa(false, Capa::OPEN_PGP) || $this->GetCapa(false, Capa::GNUPG)
// $this->GetCapa(Capa::OPEN_PGP) || $this->GetCapa(Capa::GNUPG)
$mResult['isPgpEncrypted'] = $mResponse->isPgpEncrypted();
$mResult['PgpSigned'] = $mResponse->PgpSigned();
$mResult['PgpEncrypted'] = $mResponse->PgpEncrypted();
@ -248,7 +248,7 @@ trait Response
{
$mResult = $mResponse->jsonSerialize();
$mResult['Framed'] = $this->isFileHasFramedPreview($mResult['FileName']);
$mResult['IsThumbnail'] = $this->GetCapa(false, Capa::ATTACHMENT_THUMBNAILS) && $this->isFileHasThumbnail($mResult['FileName']);
$mResult['IsThumbnail'] = $this->GetCapa(Capa::ATTACHMENT_THUMBNAILS) && $this->isFileHasThumbnail($mResult['FileName']);
$mResult['Download'] = Utils::EncodeKeyValuesQ(array(
'V' => APP_VERSION,
'Account' => $this->getAccountFromToken()->Hash(),

View file

@ -11,7 +11,7 @@ trait Themes
$sTheme = $this->Config()->Get('webmail', 'theme', 'Default');
if (!$bAdmin
&& ($oAccount = $this->getAccountFromToken(false))
&& $this->GetCapa(false, \RainLoop\Enumerations\Capa::THEMES, $oAccount)
&& $this->GetCapa(\RainLoop\Enumerations\Capa::THEMES)
&& ($oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount))) {
$sTheme = (string) $oSettingsLocal->GetConf('Theme', $sTheme);
}

View file

@ -87,7 +87,7 @@ trait User
*/
public function DoAttachmentsActions() : array
{
if (!$this->GetCapa(false, Capa::ATTACHMENTS_ACTIONS))
if (!$this->GetCapa(Capa::ATTACHMENTS_ACTIONS))
{
return $this->FalseResponse(__FUNCTION__);
}
@ -320,7 +320,7 @@ trait User
$oSettings->SetConf('Language', $this->ValidateLanguage($oConfig->Get('webmail', 'language', 'en')));
}
if ($this->GetCapa(false, Capa::THEMES, $oAccount))
if ($this->GetCapa(Capa::THEMES))
{
$this->setSettingsFromParams($oSettingsLocal, 'Theme', 'string', function ($sTheme) use ($self) {
return $self->ValidateTheme($sTheme);
@ -367,7 +367,7 @@ trait User
{
$oAccount = $this->initMailClientConnection();
if (!$this->GetCapa(false, Capa::QUOTA, $oAccount))
if (!$this->GetCapa(Capa::QUOTA))
{
return $this->DefaultResponse(__FUNCTION__, array(0, 0, 0, 0));
}
@ -463,7 +463,7 @@ trait User
{
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(false, Capa::USER_BACKGROUND, $oAccount))
if (!$this->GetCapa(Capa::USER_BACKGROUND))
{
return $this->FalseResponse(__FUNCTION__);
}

View file

@ -160,7 +160,7 @@ trait UserAuth
{
$this->Http()->ServerNoCache();
$oMainAccount = $this->getMainAccountFromToken(false);
if ($sEmail && $oMainAccount && $this->GetCapa(false, \RainLoop\Enumerations\Capa::ADDITIONAL_ACCOUNTS, $oMainAccount)) {
if ($sEmail && $oMainAccount && $this->GetCapa(\RainLoop\Enumerations\Capa::ADDITIONAL_ACCOUNTS)) {
$oAccount = null;
if ($oMainAccount->Email() === $sEmail) {
$this->SetAdditionalAuthToken($oAccount);