Skip to content

Commit cb47b1b

Browse files
authored
Merge pull request #6790 from nextcloud/feature/update-channel-2
Add new update channels part 2.
2 parents 14a5f4c + 9bd4ef1 commit cb47b1b

File tree

10 files changed

+149
-10
lines changed

10 files changed

+149
-10
lines changed

src/gui/accountmanager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ constexpr auto legacyCfgFileNameC = "owncloud.cfg";
6161
// The maximum versions that this client can read
6262
constexpr auto maxAccountsVersion = 2;
6363
constexpr auto maxAccountVersion = 1;
64+
65+
constexpr auto serverHasValidSubscriptionC = "serverHasValidSubscription";
6466
}
6567

6668

@@ -321,6 +323,8 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s
321323
settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion);
322324
settings.setValue(QLatin1String(serverColorC), acc->_serverColor);
323325
settings.setValue(QLatin1String(serverTextColorC), acc->_serverTextColor);
326+
settings.setValue(QLatin1String(serverHasValidSubscriptionC), acc->capabilities().serverHasValidSubscription());
327+
324328
if (!acc->_skipE2eeMetadataChecksumValidation) {
325329
settings.remove(QLatin1String(skipE2eeMetadataChecksumValidationC));
326330
} else {

src/gui/generalsettings.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void GeneralSettings::loadMiscSettings()
281281
_ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons());
282282

283283
#if defined(BUILD_UPDATER)
284-
auto validUpdateChannels = cfgFile.validUpdateChannels();
284+
const auto validUpdateChannels = cfgFile.validUpdateChannels();
285285
_ui->updateChannel->addItems(validUpdateChannels);
286286
const auto currentUpdateChannelIndex = validUpdateChannels.indexOf(cfgFile.currentUpdateChannel());
287287
_ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1? currentUpdateChannelIndex : 0);
@@ -359,6 +359,10 @@ void GeneralSettings::slotUpdateChannelChanged()
359359
return tr("daily");
360360
}
361361

362+
if (channel == QStringLiteral("enterprise")) {
363+
return tr("enterprise");
364+
}
365+
362366
return QString{};
363367
};
364368

@@ -370,24 +374,32 @@ void GeneralSettings::slotUpdateChannelChanged()
370374
case 2:
371375
return QStringLiteral("daily");
372376
break;
377+
case 3:
378+
return QStringLiteral("enterprise");
379+
break;
373380
default:
374381
return QStringLiteral("stable");
375382
}
376383
};
377384

385+
ConfigFile configFile;
378386
const auto channel = updateChannelFromLocalized(_ui->updateChannel->currentIndex());
379-
if (channel == ConfigFile().currentUpdateChannel()) {
387+
if (channel == configFile.currentUpdateChannel()) {
380388
return;
381389
}
382390

391+
const auto enterprise = configFile.validUpdateChannels().contains("enterprise") ? tr("- enterprise: contains stable versions for customers.\n",
392+
"description of enterprise update channel for enterprise customers")
393+
: "";
383394
auto msgBox = new QMessageBox(
384395
QMessageBox::Warning,
385396
tr("Changing update channel?"),
386397
tr("The channel determines which upgrades will be offered to install:\n"
387398
"- stable: contains tested versions considered reliable\n"
388399
"- beta: contains versions with new features that may not be tested thoroughly\n"
389-
"- daily: contains versions created daily only for testing and development\n\n"
390-
"Downgrading versions is not possible immediately: changing from beta to stable means waiting for the new stable version."),
400+
"- daily: contains versions created daily only for testing and development\n"
401+
"%1\n"
402+
"Downgrading versions is not possible immediately: changing from beta to stable means waiting for the new stable version.").arg(enterprise),
391403
QMessageBox::NoButton,
392404
this);
393405
const auto acceptButton = msgBox->addButton(tr("Change update channel"), QMessageBox::AcceptRole);

src/libsync/account.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ void Account::setCapabilities(const QVariantMap &caps)
689689
_capabilities = Capabilities(caps);
690690

691691
updateServerColors();
692+
updateServerSubcription();
693+
updateDesktopEnterpriseChannel();
692694

693695
emit capabilitiesChanged();
694696

@@ -1068,4 +1070,23 @@ void Account::setAskUserForMnemonic(const bool ask)
10681070
emit askUserForMnemonicChanged();
10691071
}
10701072

1073+
void Account::updateServerSubcription()
1074+
{
1075+
ConfigFile currentConfig;
1076+
if (const auto serverHasValidSubscription = _capabilities.serverHasValidSubscription();
1077+
serverHasValidSubscription != currentConfig.serverHasValidSubscription()) {
1078+
currentConfig.setServerHasValidSubscription(serverHasValidSubscription);
1079+
}
1080+
}
1081+
1082+
void Account::updateDesktopEnterpriseChannel()
1083+
{
1084+
ConfigFile currentConfig;
1085+
if (const auto desktopEnterpriseChannel = _capabilities.desktopEnterpriseChannel();
1086+
desktopEnterpriseChannel != currentConfig.desktopEnterpriseChannel()) {
1087+
currentConfig.setDesktopEnterpriseChannel(desktopEnterpriseChannel);
1088+
}
1089+
}
1090+
1091+
10711092
} // namespace OCC

src/libsync/account.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject
335335

336336
[[nodiscard]] bool askUserForMnemonic() const;
337337

338+
void updateServerSubcription();
339+
void updateDesktopEnterpriseChannel();
340+
338341
public slots:
339342
/// Used when forgetting credentials
340343
void clearQNAMCache();

src/libsync/capabilities.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#include "capabilities.h"
16+
#include "configfile.h"
1617

1718
#include <QVariantMap>
1819
#include <QLoggingCategory>
@@ -388,6 +389,16 @@ bool Capabilities::groupFoldersAvailable() const
388389
return _capabilities[QStringLiteral("groupfolders")].toMap().value(QStringLiteral("hasGroupFolders"), false).toBool();
389390
}
390391

392+
bool Capabilities::serverHasValidSubscription() const
393+
{
394+
return _capabilities[QStringLiteral("support")].toMap().value(QStringLiteral("hasValidSubscription"), false).toBool();
395+
}
396+
397+
QString Capabilities::desktopEnterpriseChannel() const
398+
{
399+
return _capabilities[QStringLiteral("support")].toMap().value(QStringLiteral("desktopEnterpriseChannel"), ConfigFile().defaultUpdateChannel()).toString();
400+
}
401+
391402
QStringList Capabilities::blacklistedFiles() const
392403
{
393404
return _capabilities["files"].toMap()["blacklisted_files"].toStringList();

src/libsync/capabilities.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ class OWNCLOUDSYNC_EXPORT Capabilities
173173

174174
[[nodiscard]] bool groupFoldersAvailable() const;
175175

176+
[[nodiscard]] bool serverHasValidSubscription() const;
177+
[[nodiscard]] QString desktopEnterpriseChannel() const;
178+
176179
// Direct Editing
177180
void addDirectEditor(DirectEditor* directEditor);
178181
DirectEditor* getDirectEditorForMimetype(const QMimeType &mimeType);

src/libsync/configfile.cpp

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ static constexpr char forceLoginV2C[] = "forceLoginV2";
110110
static constexpr char certPath[] = "http_certificatePath";
111111
static constexpr char certPasswd[] = "http_certificatePasswd";
112112

113-
static const QStringList validUpdateChannelsList { QStringLiteral("stable"), QStringLiteral("beta"), QStringLiteral("daily") };
114-
static constexpr char defaultUpdateChannelName[] = "stable";
113+
static constexpr char serverHasValidSubscriptionC[] = "serverHasValidSubscription";
114+
static constexpr char desktopEnterpriseChannelName[] = "desktopEnterpriseChannel";
115+
116+
static const QStringList defaultUpdateChannelsList { QStringLiteral("stable"), QStringLiteral("beta"), QStringLiteral("daily") };
117+
static const QString defaultUpdateChannelName = "stable";
118+
static const QStringList enterpriseUpdateChannelsList { QStringLiteral("stable"), QStringLiteral("enterprise") };
119+
static const QString defaultEnterpriseChannel = "enterprise";
115120
}
116121

117122
namespace OCC {
@@ -689,17 +694,37 @@ int ConfigFile::updateSegment() const
689694

690695
QStringList ConfigFile::validUpdateChannels() const
691696
{
692-
return validUpdateChannelsList;
697+
const auto isBranded = Theme::instance()->isBranded();
698+
699+
if (isBranded) {
700+
return { defaultUpdateChannelName };
701+
}
702+
703+
if (serverHasValidSubscription()) {
704+
return enterpriseUpdateChannelsList;
705+
}
706+
707+
return defaultUpdateChannelsList;
693708
}
694709

695710
QString ConfigFile::defaultUpdateChannel() const
696711
{
712+
const auto isBranded = Theme::instance()->isBranded();
713+
if (serverHasValidSubscription() && !isBranded) {
714+
if (const auto serverChannel = desktopEnterpriseChannel();
715+
validUpdateChannels().contains(serverChannel)) {
716+
qCWarning(lcConfigFile()) << "Enforcing update channel" << serverChannel << "because that is the desktop enterprise channel returned by the server.";
717+
return serverChannel;
718+
}
719+
}
720+
697721
if (const auto currentVersionSuffix = Theme::instance()->versionSuffix();
698-
validUpdateChannels().contains(currentVersionSuffix)) {
722+
validUpdateChannels().contains(currentVersionSuffix) && !isBranded) {
699723
qCWarning(lcConfigFile()) << "Enforcing update channel" << currentVersionSuffix << "because of the version suffix of the current client.";
700724
return currentVersionSuffix;
701725
}
702726

727+
qCWarning(lcConfigFile()) << "Enforcing default update channel" << defaultUpdateChannelName;
703728
return defaultUpdateChannelName;
704729
}
705730

@@ -721,7 +746,7 @@ void ConfigFile::setUpdateChannel(const QString &channel)
721746
if (!validUpdateChannels().contains(channel)) {
722747
qCWarning(lcConfigFile()) << "Received invalid update channel:"
723748
<< channel
724-
<< "can only accept 'stable', 'beta' or 'daily'. Ignoring.";
749+
<< "can only accept" << validUpdateChannels() << ". Ignoring.";
725750
return;
726751
}
727752

@@ -1176,6 +1201,31 @@ void ConfigFile::setLaunchOnSystemStartup(const bool autostart)
11761201
settings.setValue(QLatin1String(launchOnSystemStartupC), autostart);
11771202
}
11781203

1204+
bool ConfigFile::serverHasValidSubscription() const
1205+
{
1206+
QSettings settings(configFile(), QSettings::IniFormat);
1207+
return settings.value(QLatin1String(serverHasValidSubscriptionC), false).toBool();
1208+
}
1209+
1210+
void ConfigFile::setServerHasValidSubscription(const bool valid)
1211+
{
1212+
QSettings settings(configFile(), QSettings::IniFormat);
1213+
settings.setValue(QLatin1String(serverHasValidSubscriptionC), valid);
1214+
}
1215+
1216+
QString ConfigFile::desktopEnterpriseChannel() const
1217+
{
1218+
QSettings settings(configFile(), QSettings::IniFormat);
1219+
return settings.value(QLatin1String(desktopEnterpriseChannelName), defaultUpdateChannel()).toString();
1220+
}
1221+
1222+
void ConfigFile::setDesktopEnterpriseChannel(const QString &channel)
1223+
{
1224+
QSettings settings(configFile(), QSettings::IniFormat);
1225+
settings.setValue(QLatin1String(desktopEnterpriseChannelName), channel);
1226+
}
1227+
1228+
11791229
Q_GLOBAL_STATIC(QString, g_configFileName)
11801230

11811231
std::unique_ptr<QSettings> ConfigFile::settingsWithGroup(const QString &group, QObject *parent)

src/libsync/configfile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ class OWNCLOUDSYNC_EXPORT ConfigFile
227227
[[nodiscard]] bool launchOnSystemStartup() const;
228228
void setLaunchOnSystemStartup(const bool autostart);
229229

230+
[[nodiscard]] bool serverHasValidSubscription() const;
231+
void setServerHasValidSubscription(bool valid);
232+
233+
[[nodiscard]] QString desktopEnterpriseChannel() const;
234+
void setDesktopEnterpriseChannel(const QString &channel);
235+
230236
/** Returns a new settings pre-set in a specific group. The Settings will be created
231237
with the given parent. If no parent is specified, the caller must destroy the settings */
232238
static std::unique_ptr<QSettings> settingsWithGroup(const QString &group, QObject *parent = nullptr);

src/libsync/theme.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ QString Theme::statusHeaderText(SyncResult::Status status) const
117117

118118
bool Theme::isBranded() const
119119
{
120-
return appNameGUI() != QStringLiteral("Nextcloud");
120+
return (appNameGUI() != QStringLiteral("Nextcloud") && NEXTCLOUD_DEV == 0);
121121
}
122122

123123
QString Theme::appNameGUI() const

test/testcapabilities.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,35 @@ private slots:
282282

283283
QCOMPARE(filesLockAvailable, true);
284284
}
285+
286+
void testSupport_hasValidSubscription_returnTrue()
287+
{
288+
QVariantMap supportMap;
289+
supportMap["hasValidSubscription"] = "true";
290+
291+
QVariantMap capabilitiesMap;
292+
capabilitiesMap["support"] = supportMap;
293+
294+
const auto &capabilities = OCC::Capabilities(capabilitiesMap);
295+
const auto serverHasValidSubscription = capabilities.serverHasValidSubscription();
296+
297+
QCOMPARE(serverHasValidSubscription, true);
298+
}
299+
300+
void testSupport_desktopEnterpriseChannel_returnString()
301+
{
302+
QVariantMap supportMap;
303+
const auto defaultChannel = "stable";
304+
supportMap["desktopEnterpriseChannel"] = defaultChannel;
305+
306+
QVariantMap capabilitiesMap;
307+
capabilitiesMap["support"] = supportMap;
308+
309+
const auto &capabilities = OCC::Capabilities(capabilitiesMap);
310+
const auto enterpriseChannel = capabilities.desktopEnterpriseChannel();
311+
312+
QCOMPARE(enterpriseChannel, defaultChannel);
313+
}
285314
};
286315

287316
QTEST_GUILESS_MAIN(TestCapabilities)

0 commit comments

Comments
 (0)