Skip to content

Commit

Permalink
Merge pull request #7443 from nextcloud/backport/7350/stable-3.14
Browse files Browse the repository at this point in the history
[stable-3.14] Bugfix update channels
  • Loading branch information
mgallien authored Oct 31, 2024
2 parents 0775b3d + 3b2a1cc commit e582c96
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 24 deletions.
29 changes: 28 additions & 1 deletion src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s
settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion);
settings.setValue(QLatin1String(serverColorC), acc->_serverColor);
settings.setValue(QLatin1String(serverTextColorC), acc->_serverTextColor);
settings.setValue(QLatin1String(serverHasValidSubscriptionC), acc->capabilities().serverHasValidSubscription());
settings.setValue(QLatin1String(serverHasValidSubscriptionC), acc->serverHasValidSubscription());

if (!acc->_skipE2eeMetadataChecksumValidation) {
settings.remove(QLatin1String(skipE2eeMetadataChecksumValidationC));
Expand Down Expand Up @@ -606,10 +606,30 @@ void AccountManager::deleteAccount(OCC::AccountState *account)

account->account()->deleteAppToken();

// clean up config from subscriptions if the account removed was the only with valid subscription
if (account->account()->serverHasValidSubscription()) {
updateServerHasValidSubscriptionConfig();
}

emit accountSyncConnectionRemoved(account);
emit accountRemoved(account);
}

void AccountManager::updateServerHasValidSubscriptionConfig()
{
auto serverHasValidSubscription = false;
for (const auto &account : _accounts) {
if (!account->account()->serverHasValidSubscription()) {
continue;
}

serverHasValidSubscription = true;
break;
}

ConfigFile().setServerHasValidSubscription(serverHasValidSubscription);
}

AccountPtr AccountManager::createAccount()
{
const auto acc = Account::create();
Expand Down Expand Up @@ -665,10 +685,17 @@ void AccountManager::addAccountState(AccountState *const accountState)
Q_ASSERT(accountState->account());

QObject::connect(accountState->account().data(), &Account::wantsAccountSaved, this, &AccountManager::saveAccount);
QObject::connect(accountState->account().data(), &Account::capabilitiesChanged, this, &AccountManager::capabilitiesChanged);

AccountStatePtr ptr(accountState);
_accounts << ptr;
ptr->trySignIn();

// update config subscriptions if the account added is the only with valid subscription
if (accountState->account()->serverHasValidSubscription() && !ConfigFile().serverHasValidSubscription()) {
updateServerHasValidSubscriptionConfig();
}

emit accountAdded(accountState);
}

Expand Down
4 changes: 4 additions & 0 deletions src/gui/accountmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public slots:
void accountSyncConnectionRemoved(OCC::AccountState *account);
void removeAccountFolders(OCC::AccountState *account);
void forceLegacyImportChanged();
void capabilitiesChanged();

private:
// saving and loading Account to settings
Expand All @@ -128,6 +129,9 @@ public slots:
// Adds an account to the tracked list, emitting accountAdded()
void addAccountState(AccountState *const accountState);

// update config serverHasValidSubscription when accounts list changes
void updateServerHasValidSubscriptionConfig();

AccountManager() = default;
QList<AccountStatePtr> _accounts;
/// Account ids from settings that weren't read
Expand Down
22 changes: 15 additions & 7 deletions src/gui/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ GeneralSettings::GeneralSettings(QWidget *parent)
// accountAdded means the wizard was finished and the wizard might change some options.
connect(AccountManager::instance(), &AccountManager::accountAdded, this, &GeneralSettings::loadMiscSettings);

#if defined(BUILD_UPDATER)
loadUpdateChannelsList();
#endif

customizeStyle();
}

Expand Down Expand Up @@ -284,18 +288,22 @@ void GeneralSettings::loadMiscSettings()
_ui->stopExistingFolderNowBigSyncCheckBox->setChecked(_ui->existingFolderLimitCheckBox->isChecked() && cfgFile.stopSyncingExistingFoldersOverLimit());
_ui->newExternalStorage->setChecked(cfgFile.confirmExternalStorage());
_ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons());
}

#if defined(BUILD_UPDATER)
void GeneralSettings::loadUpdateChannelsList() {
ConfigFile cfgFile;
const auto validUpdateChannels = cfgFile.validUpdateChannels();
_ui->updateChannel->clear();
_ui->updateChannel->addItems(validUpdateChannels);
const auto currentUpdateChannelIndex = validUpdateChannels.indexOf(cfgFile.currentUpdateChannel());
_ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1? currentUpdateChannelIndex : 0);
connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged);
#endif
if (_currentUpdateChannelList.isEmpty() || (_currentUpdateChannelList != validUpdateChannels && !cfgFile.serverHasValidSubscription())) {
_currentUpdateChannelList = validUpdateChannels;
_ui->updateChannel->clear();
_ui->updateChannel->addItems(_currentUpdateChannelList);
const auto currentUpdateChannelIndex = _currentUpdateChannelList.indexOf(cfgFile.currentUpdateChannel());
_ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1 ? currentUpdateChannelIndex : 0);
connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged);
}
}

#if defined(BUILD_UPDATER)
void GeneralSettings::slotUpdateInfo()
{
ConfigFile config;
Expand Down
5 changes: 5 additions & 0 deletions src/gui/generalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OCC {
class IgnoreListEditor;
class SyncLogDialog;
class AccountState;

namespace Ui {
class GeneralSettings;
Expand All @@ -43,6 +44,9 @@ class GeneralSettings : public QWidget

public slots:
void slotStyleChanged();
#if defined(BUILD_UPDATER)
void loadUpdateChannelsList();
#endif

private slots:
void saveMiscSettings();
Expand All @@ -67,6 +71,7 @@ private slots:
Ui::GeneralSettings *_ui;
QPointer<IgnoreListEditor> _ignoreEditor;
bool _currentlyLoading = false;
QStringList _currentUpdateChannelList;
};


Expand Down
11 changes: 9 additions & 2 deletions src/gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent)
// Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
connect(this, &SettingsDialog::styleChanged, generalSettings, &GeneralSettings::slotStyleChanged);

#if defined(BUILD_UPDATER)
connect(AccountManager::instance(), &AccountManager::accountAdded, generalSettings, &GeneralSettings::loadUpdateChannelsList);
connect(AccountManager::instance(), &AccountManager::accountRemoved, generalSettings, &GeneralSettings::loadUpdateChannelsList);
connect(AccountManager::instance(), &AccountManager::capabilitiesChanged, generalSettings, &GeneralSettings::loadUpdateChannelsList);
#endif

QAction *networkAction = createColorAwareAction(QLatin1String(":/client/theme/network.svg"), tr("Network"));
_actionGroup->addAction(networkAction);
_toolBar->addAction(networkAction);
Expand All @@ -137,8 +143,9 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent)
_actionGroupWidgets.insert(generalAction, generalSettings);
_actionGroupWidgets.insert(networkAction, networkSettings);

foreach(auto ai, AccountManager::instance()->accounts()) {
accountAdded(ai.data());
const auto accountsList = AccountManager::instance()->accounts();
for (const auto &account : accountsList) {
accountAdded(account.data());
}

QTimer::singleShot(1, this, &SettingsDialog::showFirstPage);
Expand Down
19 changes: 16 additions & 3 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,13 +1075,26 @@ void Account::setAskUserForMnemonic(const bool ask)
emit askUserForMnemonicChanged();
}

bool Account::serverHasValidSubscription() const
{
return _serverHasValidSubscription;
}

void Account::setServerHasValidSubscription(bool valid)
{
_serverHasValidSubscription = valid;
}

void Account::updateServerSubcription()
{
ConfigFile currentConfig;
if (const auto serverHasValidSubscription = _capabilities.serverHasValidSubscription();
serverHasValidSubscription != currentConfig.serverHasValidSubscription()) {
currentConfig.setServerHasValidSubscription(serverHasValidSubscription);
const auto capabilityValidSubscription = _capabilities.serverHasValidSubscription();
const auto configValidSubscription = currentConfig.serverHasValidSubscription();
if (capabilityValidSubscription != configValidSubscription && !configValidSubscription) {
currentConfig.setServerHasValidSubscription(capabilityValidSubscription);
}

setServerHasValidSubscription(capabilityValidSubscription);
}

void Account::updateDesktopEnterpriseChannel()
Expand Down
5 changes: 5 additions & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject
[[nodiscard]] unsigned int downloadLimit() const;
void setDownloadLimit(unsigned int kbytes);

[[nodiscard]] bool serverHasValidSubscription() const;
void setServerHasValidSubscription(bool valid);

public slots:
/// Used when forgetting credentials
void clearQNAMCache();
Expand Down Expand Up @@ -553,6 +556,8 @@ private slots:
unsigned int _uploadLimit = 0;
unsigned int _downloadLimit = 0;

bool _serverHasValidSubscription = false;

/* IMPORTANT - remove later - FIXME MS@2019-12-07 -->
* TODO: For "Log out" & "Remove account": Remove client CA certs and KEY!
*
Expand Down
15 changes: 4 additions & 11 deletions src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,32 +707,25 @@ QString ConfigFile::defaultUpdateChannel() const
if (serverHasValidSubscription() && !isBranded) {
if (const auto serverChannel = desktopEnterpriseChannel();
validUpdateChannels().contains(serverChannel)) {
qCWarning(lcConfigFile()) << "Enforcing update channel" << serverChannel << "because that is the desktop enterprise channel returned by the server.";
qCWarning(lcConfigFile()) << "Default update channel is" << serverChannel << "because that is the desktop enterprise channel returned by the server.";
return serverChannel;
}
}

if (const auto currentVersionSuffix = Theme::instance()->versionSuffix();
validUpdateChannels().contains(currentVersionSuffix) && !isBranded) {
qCWarning(lcConfigFile()) << "Enforcing update channel" << currentVersionSuffix << "because of the version suffix of the current client.";
qCWarning(lcConfigFile()) << "Default update channel is" << currentVersionSuffix << "because of the version suffix of the current client.";
return currentVersionSuffix;
}

qCWarning(lcConfigFile()) << "Enforcing default update channel" << defaultUpdateChannelName;
qCWarning(lcConfigFile()) << "Default update channel is" << defaultUpdateChannelName;
return defaultUpdateChannelName;
}

QString ConfigFile::currentUpdateChannel() const
{
auto updateChannel = defaultUpdateChannel();
QSettings settings(configFile(), QSettings::IniFormat);
if (const auto configUpdateChannel = settings.value(QLatin1String(updateChannelC), updateChannel).toString();
validUpdateChannels().contains(configUpdateChannel)) {
qCWarning(lcConfigFile()) << "Config file has a valid update channel:" << configUpdateChannel;
updateChannel = configUpdateChannel;
}

return updateChannel;
return settings.value(QLatin1String(updateChannelC), defaultUpdateChannel()).toString();
}

void ConfigFile::setUpdateChannel(const QString &channel)
Expand Down

0 comments on commit e582c96

Please sign in to comment.