Fix webmail account switcher and improve error handling

- Fix apiSSO() resetting selected account to first one on every call,
  now preserves previously selected account if still valid
- Fix webmail.conf ownership to use cyberpanel:cyberpanel (Django runs
  as cyberpanel user, not nobody)
- Add error notifications when SSO or folder loading fails
This commit is contained in:
usmannasir
2026-03-05 05:01:45 +05:00
parent fd7960f790
commit 6a61e294a9
4 changed files with 12 additions and 5 deletions

View File

@@ -740,7 +740,7 @@ module cyberpanel_ols {
with open('/etc/cyberpanel/webmail.conf', 'w') as f:
json_module.dump(webmail_conf, f)
os.chmod('/etc/cyberpanel/webmail.conf', 0o600)
subprocess.call(['chown', 'nobody:nobody', '/etc/cyberpanel/webmail.conf'])
subprocess.call(['chown', 'cyberpanel:cyberpanel', '/etc/cyberpanel/webmail.conf'])
InstallCyberPanel.stdOut("Webmail master user setup complete!", 1)
return 1

View File

@@ -2846,7 +2846,7 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL
with open('/etc/cyberpanel/webmail.conf', 'w') as f:
json.dump(webmail_conf, f)
os.chmod('/etc/cyberpanel/webmail.conf', 0o600)
subprocess.call(['chown', 'nobody:nobody', '/etc/cyberpanel/webmail.conf'])
subprocess.call(['chown', 'cyberpanel:cyberpanel', '/etc/cyberpanel/webmail.conf'])
# Patch dovecot.conf if master user config not present
dovecot_conf_path = '/etc/dovecot/dovecot.conf'

View File

@@ -171,6 +171,8 @@ app.controller('webmailCtrl', ['$scope', '$http', '$sce', '$timeout', function($
$scope.switchEmail = data.email;
$scope.loadFolders();
$scope.loadSettings();
} else {
notify(data.error_message || 'No email accounts found. Create an email account first or use the standalone login.', 'error');
}
});
};
@@ -199,6 +201,8 @@ app.controller('webmailCtrl', ['$scope', '$http', '$sce', '$timeout', function($
if (data.status === 1) {
$scope.folders = data.folders;
$scope.loadMessages();
} else {
notify(data.error_message || 'Failed to load folders.', 'error');
}
});
};

View File

@@ -184,9 +184,12 @@ class WebmailManager:
accounts = self._get_managed_accounts()
if not accounts:
return self._error('No email accounts found for your user.')
email = accounts[0]
self.request.session['webmail_email'] = email
return self._success({'email': email, 'accounts': accounts})
# Preserve previously selected account if still valid
current = self.request.session.get('webmail_email')
if not current or current not in accounts:
current = accounts[0]
self.request.session['webmail_email'] = current
return self._success({'email': current, 'accounts': accounts})
def apiListAccounts(self):
accounts = self._get_managed_accounts()