From e7c7b8ed53c0f772db2f0f1087ced87e6ccced62 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Thu, 24 Feb 2022 12:22:27 +0100 Subject: [PATCH] Restructure Capa --- dev/Common/Enums.js | 27 ++--- dev/Screen/User/Settings.js | 2 +- dev/Settings/Admin/General.js | 2 +- dev/Settings/Admin/Security.js | 4 +- dev/Settings/User/Folders.js | 5 +- dev/Settings/User/Security.js | 4 +- dev/Settings/User/Themes.js | 9 +- dev/View/Popup/OpenPgpGenerate.js | 4 +- dev/View/User/MailBox/MessageList.js | 2 +- dev/View/User/MailBox/MessageView.js | 9 +- dev/View/User/SystemDropDown.js | 4 +- dev/boot.js | 2 +- .../0.0.0/app/libraries/RainLoop/Actions.php | 101 +++++------------- .../libraries/RainLoop/Enumerations/Capa.php | 37 ++++--- .../templates/Views/User/SettingsThemes.html | 2 +- 15 files changed, 74 insertions(+), 140 deletions(-) diff --git a/dev/Common/Enums.js b/dev/Common/Enums.js index f161a3cda..d7514b8eb 100644 --- a/dev/Common/Enums.js +++ b/dev/Common/Enums.js @@ -4,23 +4,16 @@ * @enum {string} */ export const Capa = { - GnuPG: 'GNUPG', - OpenPGP: 'OPEN_PGP', - Prefetch: 'PREFETCH', - Contacts: 'CONTACTS', - Search: 'SEARCH', - SearchAdv: 'SEARCH_ADV', - MessageActions: 'MESSAGE_ACTIONS', - AttachmentsActions: 'ATTACHMENTS_ACTIONS', - DangerousActions: 'DANGEROUS_ACTIONS', - Themes: 'THEMES', - UserBackground: 'USER_BACKGROUND', - Sieve: 'SIEVE', - AttachmentThumbnails: 'ATTACHMENT_THUMBNAILS', - AutoLogout: 'AUTOLOGOUT', - Kolab: 'KOLAB', - AdditionalAccounts: 'ADDITIONAL_ACCOUNTS', - Identities: 'IDENTITIES' + AdditionalAccounts: 'AdditionalAccounts', + AutoLogout: 'AutoLogout', + DangerousActions: 'DangerousActions', + GnuPG: 'GnuPG', + Identities: 'Identities', + OpenPGP: 'OpenPGP', + Search: 'Search', + SearchAdv: 'SearchAdv', + Themes: 'Themes', + UserBackground: 'UserBackground' }; /** diff --git a/dev/Screen/User/Settings.js b/dev/Screen/User/Settings.js index 2fca3dfad..643edeb40 100644 --- a/dev/Screen/User/Settings.js +++ b/dev/Screen/User/Settings.js @@ -43,7 +43,7 @@ export class SettingsUserScreen extends AbstractSettingsScreen { ); } - if (SettingsCapa(Capa.Sieve)) { + if (SettingsCapa('Sieve')) { settingsAddViewModel(FiltersUserSettings, 'SettingsFilters', 'SETTINGS_LABELS/LABEL_FILTERS_NAME', 'filters'); } diff --git a/dev/Settings/Admin/General.js b/dev/Settings/Admin/General.js index 3aed04b4a..516cc5ab6 100644 --- a/dev/Settings/Admin/General.js +++ b/dev/Settings/Admin/General.js @@ -46,7 +46,7 @@ export class GeneralAdminSettings /*extends AbstractViewSettings*/ { capaUserBackground: SettingsCapa(Capa.UserBackground), capaAdditionalAccounts: SettingsCapa(Capa.AdditionalAccounts), capaIdentities: SettingsCapa(Capa.Identities), - capaAttachmentThumbnails: SettingsCapa(Capa.AttachmentThumbnails), + capaAttachmentThumbnails: SettingsCapa('AttachmentThumbnails'), dataFolderAccess: false }); diff --git a/dev/Settings/Admin/Security.js b/dev/Settings/Admin/Security.js index 5d06197ee..50880c7ca 100644 --- a/dev/Settings/Admin/Security.js +++ b/dev/Settings/Admin/Security.js @@ -1,5 +1,5 @@ import { Capa } from 'Common/Enums'; -import { Settings, SettingsGet } from 'Common/Globals'; +import { SettingsGet, SettingsCapa } from 'Common/Globals'; import { addObservablesTo, addSubscribablesTo } from 'External/ko'; import Remote from 'Remote/Admin/Fetch'; @@ -27,7 +27,7 @@ export class SecurityAdminSettings /*extends AbstractViewSettings*/ { adminPasswordUpdateError: false, adminPasswordUpdateSuccess: false, - capaOpenPGP: Settings.capa(Capa.OpenPGP) + capaOpenPGP: SettingsCapa(Capa.OpenPGP) }); addSubscribablesTo(this, { diff --git a/dev/Settings/User/Folders.js b/dev/Settings/User/Folders.js index a6d9aba3b..5087babc0 100644 --- a/dev/Settings/User/Folders.js +++ b/dev/Settings/User/Folders.js @@ -3,11 +3,10 @@ import { koComputable } from 'External/ko'; import { Notification } from 'Common/Enums'; import { FolderMetadataKeys } from 'Common/EnumsUser'; -import { Settings } from 'Common/Globals'; +import { SettingsCapa } from 'Common/Globals'; import { getNotification } from 'Common/Translator'; import { setFolder, getFolderFromCacheList, removeFolderFromCacheList } from 'Common/Cache'; -import { Capa } from 'Common/Enums'; import { defaultOptionsAfterRender } from 'Common/Utils'; import { sortFolders } from 'Common/Folders'; import { initOnStartOrLangChange, i18n } from 'Common/Translator'; @@ -27,7 +26,7 @@ const folderForDeletion = ko.observable(null).askDeleteHelper(); export class FoldersUserSettings /*extends AbstractViewSettings*/ { constructor() { - this.showKolab = koComputable(() => FolderUserStore.hasCapability('METADATA') && Settings.capa(Capa.Kolab)); + this.showKolab = koComputable(() => FolderUserStore.hasCapability('METADATA') && SettingsCapa('Kolab')); this.defaultOptionsAfterRender = defaultOptionsAfterRender; this.kolabTypeOptions = ko.observableArray(); let i18nFilter = key => i18n('SETTINGS_FOLDERS/TYPE_' + key); diff --git a/dev/Settings/User/Security.js b/dev/Settings/User/Security.js index 8c765b71b..8a77f25e8 100644 --- a/dev/Settings/User/Security.js +++ b/dev/Settings/User/Security.js @@ -3,7 +3,7 @@ import { koComputable } from 'External/ko'; import { pInt, settingsSaveHelperSimpleFunction } from 'Common/Utils'; import { Capa, SaveSettingsStep } from 'Common/Enums'; -import { Settings } from 'Common/Globals'; +import { SettingsCapa } from 'Common/Globals'; import { i18n, trigger as translatorTrigger } from 'Common/Translator'; import { SettingsUserStore } from 'Stores/User/Settings'; @@ -12,7 +12,7 @@ import Remote from 'Remote/User/Fetch'; export class SecurityUserSettings /*extends AbstractViewSettings*/ { constructor() { - this.capaAutoLogout = Settings.capa(Capa.AutoLogout); + this.capaAutoLogout = SettingsCapa(Capa.AutoLogout); this.autoLogout = SettingsUserStore.autoLogout; this.autoLogoutTrigger = ko.observable(SaveSettingsStep.Idle); diff --git a/dev/Settings/User/Themes.js b/dev/Settings/User/Themes.js index 22c378545..02eef62a9 100644 --- a/dev/Settings/User/Themes.js +++ b/dev/Settings/User/Themes.js @@ -4,7 +4,7 @@ import { SaveSettingsStep, UploadErrorCode, Capa } from 'Common/Enums'; import { changeTheme, convertThemeName } from 'Common/Utils'; import { themePreviewLink, serverRequest } from 'Common/Links'; import { i18n } from 'Common/Translator'; -import { Settings } from 'Common/Globals'; +import { SettingsCapa } from 'Common/Globals'; import { ThemeStore } from 'Stores/Theme'; @@ -26,10 +26,9 @@ export class ThemesUserSettings /*extends AbstractViewSettings*/ { this.themes = ThemeStore.themes; this.themesObjects = ko.observableArray(); + themeBackground.enabled = SettingsCapa(Capa.UserBackground); this.background = themeBackground; - this.capaUserBackground = Settings.capa(Capa.UserBackground); - this.themeTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 }); ThemeStore.theme.subscribe(value => { @@ -59,7 +58,7 @@ export class ThemesUserSettings /*extends AbstractViewSettings*/ { // initUploader - if (themeBackground.uploaderButton() && this.capaUserBackground) { + if (themeBackground.uploaderButton() && themeBackground.enabled) { const oJua = new Jua({ action: serverRequest('UploadBackground'), limit: 1, @@ -112,7 +111,7 @@ export class ThemesUserSettings /*extends AbstractViewSettings*/ { } clearBackground() { - if (this.capaUserBackground) { + if (themeBackground.enabled) { Remote.request('ClearUserBackground', () => { themeBackground.name(''); themeBackground.hash(''); diff --git a/dev/View/Popup/OpenPgpGenerate.js b/dev/View/Popup/OpenPgpGenerate.js index 35dee3c80..2f807d466 100644 --- a/dev/View/Popup/OpenPgpGenerate.js +++ b/dev/View/Popup/OpenPgpGenerate.js @@ -8,7 +8,7 @@ import { IdentityUserStore } from 'Stores/User/Identity'; import { AbstractViewPopup } from 'Knoin/AbstractViews'; import { Capa } from 'Common/Enums'; -import { Settings } from 'Common/Globals'; +import { SettingsCapa } from 'Common/Globals'; export class OpenPgpGeneratePopupView extends AbstractViewPopup { constructor() { @@ -34,7 +34,7 @@ export class OpenPgpGeneratePopupView extends AbstractViewPopup { saveGnuPGPrivate: false }); - this.canGnuPG = Settings.capa(Capa.GnuPG); + this.canGnuPG = SettingsCapa(Capa.GnuPG); this.email.subscribe(() => this.emailError(false)); } diff --git a/dev/View/User/MailBox/MessageList.js b/dev/View/User/MailBox/MessageList.js index 2d6e10d37..3af9ece31 100644 --- a/dev/View/User/MailBox/MessageList.js +++ b/dev/View/User/MailBox/MessageList.js @@ -828,7 +828,7 @@ export class MailMessageList extends AbstractViewRight { shortcuts.add('arrowleft', 'meta', Scope.MessageView, ()=>false); shortcuts.add('arrowright', 'meta', Scope.MessageView, ()=>false); - if (!ThemeStore.isMobile() && SettingsCapa(Capa.Prefetch)) { + if (!ThemeStore.isMobile() && SettingsCapa('Prefetch')) { ifvisible.idle(this.prefetchNextTick.bind(this)); } } diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index d4b83eefc..e8a5d7f79 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -2,10 +2,7 @@ import ko from 'ko'; import { UNUSED_OPTION_VALUE } from 'Common/Consts'; -import { - Capa, - Scope -} from 'Common/Enums'; +import { Scope } from 'Common/Enums'; import { ComposeType, @@ -93,7 +90,7 @@ export class MailMessageView extends AbstractViewRight { this.moveAction = moveAction; - this.allowMessageActions = SettingsCapa(Capa.MessageActions); + this.allowMessageActions = SettingsCapa('MessageActions'); const attachmentsActions = Settings.app('attachmentsActions'); this.attachmentsActions = ko.observableArray(arrayLength(attachmentsActions) ? attachmentsActions : []); @@ -132,7 +129,7 @@ export class MailMessageView extends AbstractViewRight { this.viewHash = ''; this.addComputables({ - allowAttachmentControls: () => this.attachmentsActions.length && SettingsCapa(Capa.AttachmentsActions), + allowAttachmentControls: () => this.attachmentsActions.length && SettingsCapa('AttachmentsActions'), downloadAsZipAllowed: () => this.attachmentsActions.includes('zip') && this.allowAttachmentControls(), diff --git a/dev/View/User/SystemDropDown.js b/dev/View/User/SystemDropDown.js index cfd769390..c15aae9df 100644 --- a/dev/View/User/SystemDropDown.js +++ b/dev/View/User/SystemDropDown.js @@ -13,7 +13,7 @@ import { KeyboardShortcutsHelpPopupView } from 'View/Popup/KeyboardShortcutsHelp import { AccountPopupView } from 'View/Popup/Account'; import { ContactsPopupView } from 'View/Popup/Contacts'; -import { doc, Settings/*, SettingsGet*/, leftPanelDisabled, fireEvent } from 'Common/Globals'; +import { doc, leftPanelDisabled, fireEvent, SettingsCapa } from 'Common/Globals'; import { ThemeStore } from 'Stores/Theme'; @@ -26,7 +26,7 @@ export class SystemDropDownUserView extends AbstractViewRight { constructor() { super('SystemDropDown'); - this.allowAccounts = Settings.capa(Capa.AdditionalAccounts); + this.allowAccounts = SettingsCapa(Capa.AdditionalAccounts); this.accountEmail = AccountUserStore.email; diff --git a/dev/boot.js b/dev/boot.js index 9ab583139..fde765ffb 100644 --- a/dev/boot.js +++ b/dev/boot.js @@ -45,7 +45,7 @@ win.rl = { get: name => RL_APP_DATA[name], set: (name, value) => RL_APP_DATA[name] = value, app: name => RL_APP_DATA.System[name], - capa: name => name && (RL_APP_DATA.Capa || []).includes(name) + capa: name => name && !!(RL_APP_DATA.Capa || {})[name] }, setWindowTitle: title => doc.title = RL_APP_DATA.Title ? (title ? title + ' - ' : '') + RL_APP_DATA.Title : (title ? '' + title : ''), diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 0cd30f777..4b151047b 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -1165,89 +1165,36 @@ class Actions public function Capa(bool $bAdmin, ?Model\Account $oAccount = null): array { static $aResult; - if ($aResult && !$oAccount) { - return $aResult; + if (!$aResult) { + $oConfig = $this->oConfig; + $aResult = array( + 'AutoLogout' => true, + 'AdditionalAccounts' => (bool) $oConfig->Get('webmail', 'allow_additional_accounts', false), + 'AttachmentThumbnails' => (bool) $oConfig->Get('interface', 'show_attachment_thumbnail', true), + 'AttachmentsActions' => (bool) $oConfig->Get('capa', 'attachments_actions', false), + 'Contacts' => (bool) $oConfig->Get('capa', 'contacts', true), + 'DangerousActions' => (bool) $oConfig->Get('capa', 'dangerous_actions', true), + 'GnuPG' => (bool) $oConfig->Get('security', 'openpgp', false) && \SnappyMail\PGP\GnuPG::isSupported(), + 'Identities' => (bool) $oConfig->Get('webmail', 'allow_additional_identities', false), + 'Kolab' => (bool) $oConfig->Get('labs', 'kolab_enabled', false), + 'MessageActions' => (bool) $oConfig->Get('capa', 'message_actions', true), + 'OpenPGP' => (bool) $oConfig->Get('security', 'openpgp', false), + 'Prefetch' => (bool) $oConfig->Get('labs', 'allow_prefetch', false), + 'Quota' => (bool) $oConfig->Get('capa', 'quota', true), + 'Search' => (bool) $oConfig->Get('capa', 'search', true), + 'SearchAdv' => (bool) $oConfig->Get('capa', 'search', true) && $oConfig->Get('capa', 'search_adv', true), + 'Sieve' => false, + 'Themes' => (bool) $oConfig->Get('webmail', 'allow_themes', false), + 'UserBackground' => (bool) $oConfig->Get('webmail', 'allow_user_background', false) + ); } - - $oConfig = $this->oConfig; - - $aResult = array( - Enumerations\Capa::AUTOLOGOUT - ); - - if ($oConfig->Get('capa', 'dangerous_actions', true)) { - $aResult[] = Enumerations\Capa::DANGEROUS_ACTIONS; - } - - if ($oConfig->Get('capa', 'quota', true)) { - $aResult[] = Enumerations\Capa::QUOTA; - } - - if ($oConfig->Get('webmail', 'allow_additional_accounts', false)) { - $aResult[] = Enumerations\Capa::ADDITIONAL_ACCOUNTS; - } - - if ($oConfig->Get('webmail', 'allow_additional_identities', false)) { - $aResult[] = Enumerations\Capa::IDENTITIES; - } - - if ($oConfig->Get('webmail', 'allow_themes', false)) { - $aResult[] = Enumerations\Capa::THEMES; - } - - if ($oConfig->Get('webmail', 'allow_user_background', false)) { - $aResult[] = Enumerations\Capa::USER_BACKGROUND; - } - - if ($oConfig->Get('security', 'openpgp', false)) { - $aResult[] = Enumerations\Capa::OPEN_PGP; - if (\SnappyMail\PGP\GnuPG::isSupported()) { - $aResult[] = Enumerations\Capa::GNUPG; - } - } - - if ($bAdmin || ($oAccount && $oAccount->Domain()->UseSieve())) { - $aResult[] = Enumerations\Capa::SIEVE; - } - - if ($oConfig->Get('capa', 'attachments_actions', false)) { - $aResult[] = Enumerations\Capa::ATTACHMENTS_ACTIONS; - } - - if ($oConfig->Get('capa', 'message_actions', true)) { - $aResult[] = Enumerations\Capa::MESSAGE_ACTIONS; - } - - if ($oConfig->Get('capa', 'contacts', true)) { - $aResult[] = Enumerations\Capa::CONTACTS; - } - - if ($oConfig->Get('capa', 'search', true)) { - $aResult[] = Enumerations\Capa::SEARCH; - - if ($oConfig->Get('capa', 'search_adv', true)) { - $aResult[] = Enumerations\Capa::SEARCH_ADV; - } - } - - if ($oConfig->Get('interface', 'show_attachment_thumbnail', true)) { - $aResult[] = Enumerations\Capa::ATTACHMENT_THUMBNAILS; - } - - if ($oConfig->Get('labs', 'allow_prefetch', false)) { - $aResult[] = Enumerations\Capa::PREFETCH; - } - - if ($oConfig->Get('labs', 'kolab_enabled', false)) { - $aResult[] = Enumerations\Capa::KOLAB; - } - + $aResult['Sieve'] = $bAdmin || ($oAccount && $oAccount->Domain()->UseSieve()); return $aResult; } public function GetCapa(string $sName, ?Model\Account $oAccount = null): bool { - return \in_array($sName, $this->Capa(false, $oAccount)); + return !empty($this->Capa(false, $oAccount)[$sName]); } public function etag(string $sKey): string diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Enumerations/Capa.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Enumerations/Capa.php index 46a314a63..57f8712a3 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Enumerations/Capa.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Enumerations/Capa.php @@ -4,23 +4,22 @@ namespace RainLoop\Enumerations; class Capa { - const GNUPG = 'GNUPG'; - const OPEN_PGP = 'OPEN_PGP'; - const PREFETCH = 'PREFETCH'; - const THEMES = 'THEMES'; - const USER_BACKGROUND = 'USER_BACKGROUND'; - const SIEVE = 'SIEVE'; - const ATTACHMENT_THUMBNAILS = 'ATTACHMENT_THUMBNAILS'; - const ADDITIONAL_ACCOUNTS = 'ADDITIONAL_ACCOUNTS'; - const IDENTITIES = 'IDENTITIES'; - const CONTACTS = 'CONTACTS'; - const SEARCH = 'SEARCH'; - const SEARCH_ADV = 'SEARCH_ADV'; - const QUOTA = 'QUOTA'; - const TEMPLATES = 'TEMPLATES'; - const MESSAGE_ACTIONS = 'MESSAGE_ACTIONS'; - const ATTACHMENTS_ACTIONS = 'ATTACHMENTS_ACTIONS'; - const DANGEROUS_ACTIONS = 'DANGEROUS_ACTIONS'; - const AUTOLOGOUT = 'AUTOLOGOUT'; - const KOLAB = 'KOLAB'; + const GNUPG = 'GnuPG'; + const OPEN_PGP = 'OpenPGP'; + const PREFETCH = 'Prefetch'; + const THEMES = 'Themes'; + const USER_BACKGROUND = 'UserBackground'; + const SIEVE = 'Sieve'; + const ATTACHMENT_THUMBNAILS = 'AttachmentThumbnails'; + const ADDITIONAL_ACCOUNTS = 'AdditionalAccounts'; + const IDENTITIES = 'Identities'; + const CONTACTS = 'Contacts'; + const SEARCH = 'Search'; + const SEARCH_ADV = 'SearchAdv'; + const QUOTA = 'Quota'; + const MESSAGE_ACTIONS = 'MessageActions'; + const ATTACHMENTS_ACTIONS = 'AttachmentsActions'; + const DANGEROUS_ACTIONS = 'DangerousActions'; + const AUTOLOGOUT = 'AutoLogout'; + const KOLAB = 'Kolab'; } diff --git a/snappymail/v/0.0.0/app/templates/Views/User/SettingsThemes.html b/snappymail/v/0.0.0/app/templates/Views/User/SettingsThemes.html index 23cf960cf..9eb279c1b 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/SettingsThemes.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/SettingsThemes.html @@ -10,7 +10,7 @@

-
+