Merge pull request #7160 from nextcloud/feature/hard-coded-servers

Add ability to provide multiple hardcoded server URLs via CMake define
This commit is contained in:
Matthieu Gallien 2024-09-24 10:39:54 +02:00 коммит произвёл GitHub
Родитель 3edc2094d4 c16b6205f1
Коммит 432369a504
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 65 добавлений и 12 удалений

Просмотреть файл

@ -23,7 +23,7 @@
#cmakedefine APPLICATION_HELP_URL "@APPLICATION_HELP_URL@" #cmakedefine APPLICATION_HELP_URL "@APPLICATION_HELP_URL@"
#cmakedefine APPLICATION_ICON_NAME "@APPLICATION_ICON_NAME@" #cmakedefine APPLICATION_ICON_NAME "@APPLICATION_ICON_NAME@"
#cmakedefine APPLICATION_ICON_SET "@APPLICATION_ICON_SET@" #cmakedefine APPLICATION_ICON_SET "@APPLICATION_ICON_SET@"
#cmakedefine APPLICATION_SERVER_URL "@APPLICATION_SERVER_URL@" #cmakedefine APPLICATION_SERVER_URL R"(@APPLICATION_SERVER_URL@)"
#cmakedefine APPLICATION_SERVER_URL_ENFORCE "@APPLICATION_SERVER_URL_ENFORCE@" #cmakedefine APPLICATION_SERVER_URL_ENFORCE "@APPLICATION_SERVER_URL_ENFORCE@"
#cmakedefine LINUX_APPLICATION_ID "@LINUX_APPLICATION_ID@" #cmakedefine LINUX_APPLICATION_ID "@LINUX_APPLICATION_ID@"
#cmakedefine APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR "@APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR@" #cmakedefine APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR "@APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR@"

Просмотреть файл

@ -456,7 +456,8 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
const auto overrideUrl = Theme::instance()->overrideServerUrl(); const auto overrideUrl = Theme::instance()->overrideServerUrl();
const auto forceAuth = Theme::instance()->forceConfigAuthType(); const auto forceAuth = Theme::instance()->forceConfigAuthType();
if (!forceAuth.isEmpty() && !overrideUrl.isEmpty()) { const auto multipleOverrideServers = Theme::instance()->multipleOverrideServers();
if (!forceAuth.isEmpty() && !overrideUrl.isEmpty() && !multipleOverrideServers) {
// If forceAuth is set, this might also mean the overrideURL has changed. // If forceAuth is set, this might also mean the overrideURL has changed.
// See enterprise issues #1126 // See enterprise issues #1126
acc->setUrl(overrideUrl); acc->setUrl(overrideUrl);

Просмотреть файл

@ -103,7 +103,9 @@ void OwncloudSetupWizard::startWizard()
{ {
AccountPtr account = AccountManager::createAccount(); AccountPtr account = AccountManager::createAccount();
account->setCredentials(CredentialsFactory::create("dummy")); account->setCredentials(CredentialsFactory::create("dummy"));
account->setUrl(Theme::instance()->overrideServerUrl()); const auto defaultUrl =
Theme::instance()->multipleOverrideServers() ? QString{} : Theme::instance()->overrideServerUrl();
account->setUrl(defaultUrl);
_ocWizard->setAccount(account); _ocWizard->setAccount(account);
_ocWizard->setOCUrl(account->url().toString()); _ocWizard->setOCUrl(account->url().toString());

Просмотреть файл

@ -199,6 +199,9 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QComboBox" name="comboBox"/>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="topMargin"> <property name="topMargin">

Просмотреть файл

@ -25,6 +25,8 @@
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QGraphicsPixmapItem> #include <QGraphicsPixmapItem>
#include <QBuffer> #include <QBuffer>
#include <QJsonArray>
#include <QJsonDocument>
#include "QProgressIndicator.h" #include "QProgressIndicator.h"
@ -47,14 +49,29 @@ OwncloudSetupPage::OwncloudSetupPage(QWidget *parent)
setupServerAddressDescriptionLabel(); setupServerAddressDescriptionLabel();
Theme *theme = Theme::instance(); const auto theme = Theme::instance();
if (theme->overrideServerUrl().isEmpty()) { if (theme->overrideServerUrl().isEmpty()) {
_ui.comboBox->hide();
_ui.leUrl->setPostfix(theme->wizardUrlPostfix()); _ui.leUrl->setPostfix(theme->wizardUrlPostfix());
_ui.leUrl->setPlaceholderText(theme->wizardUrlHint()); _ui.leUrl->setPlaceholderText(theme->wizardUrlHint());
} else if (Theme::instance()->forceOverrideServerUrl()) { } else if (theme->multipleOverrideServers() && theme->forceOverrideServerUrl()) {
_ui.leUrl->setEnabled(false); _ui.leUrl->hide();
} const auto overrideJsonUtf8 = theme->overrideServerUrl().toUtf8();
const auto serversJsonArray = QJsonDocument::fromJson(overrideJsonUtf8).array();
for (const auto &serverJson : serversJsonArray) {
const auto serverObject = serverJson.toObject();
const auto serverName = serverObject.value("name").toString();
const auto serverUrl = serverObject.value("url").toString();
const auto serverDisplayString = QString("%1 (%2)").arg(serverName, serverUrl);
_ui.comboBox->addItem(serverDisplayString, serverUrl);
}
} else if (theme->forceOverrideServerUrl()) {
_ui.comboBox->hide();
_ui.leUrl->setEnabled(false);
} else {
_ui.comboBox->hide();
}
registerField(QLatin1String("OCUrl*"), _ui.leUrl); registerField(QLatin1String("OCUrl*"), _ui.leUrl);
@ -165,7 +182,7 @@ void OwncloudSetupPage::slotUrlEditFinished()
bool OwncloudSetupPage::isComplete() const bool OwncloudSetupPage::isComplete() const
{ {
return !_ui.leUrl->text().isEmpty() && !_checking; return (!_ui.leUrl->text().isEmpty() || !_ui.comboBox->currentData().toString().isEmpty()) && !_checking;
} }
void OwncloudSetupPage::initializePage() void OwncloudSetupPage::initializePage()
@ -192,7 +209,7 @@ void OwncloudSetupPage::initializePage()
if (nextButton) { if (nextButton) {
nextButton->setFocus(); nextButton->setFocus();
} }
} else if (isServerUrlOverridden) { } else if (isServerUrlOverridden && !Theme::instance()->multipleOverrideServers()) {
// If the overwritten url is not empty and we force this overwritten url // If the overwritten url is not empty and we force this overwritten url
// we just check the server type and switch to next page // we just check the server type and switch to next page
// immediately. // immediately.
@ -226,8 +243,12 @@ int OwncloudSetupPage::nextId() const
QString OwncloudSetupPage::url() const QString OwncloudSetupPage::url() const
{ {
QString url = _ui.leUrl->fullText().simplified(); const auto theme = Theme::instance();
return url; if (theme->multipleOverrideServers() && theme->forceOverrideServerUrl()) {
return _ui.comboBox->currentData().toString();
} else {
return _ui.leUrl->fullText().simplified();
}
} }
bool OwncloudSetupPage::validatePage() bool OwncloudSetupPage::validatePage()
@ -270,7 +291,8 @@ void OwncloudSetupPage::setErrorString(const QString &err, bool retryHTTPonly)
_ui.errorLabel->setVisible(false); _ui.errorLabel->setVisible(false);
} else { } else {
if (retryHTTPonly) { if (retryHTTPonly) {
QUrl url(_ui.leUrl->fullText()); const auto urlString = url();
QUrl url(urlString);
if (url.scheme() == "https") { if (url.scheme() == "https") {
// Ask the user how to proceed when connecting to a https:// URL fails. // Ask the user how to proceed when connecting to a https:// URL fails.
// It is possible that the server is secured with client-side TLS certificates, // It is possible that the server is secured with client-side TLS certificates,

Просмотреть файл

@ -30,6 +30,8 @@
#include <QSslSocket> #include <QSslSocket>
#include <QSvgRenderer> #include <QSvgRenderer>
#include <QPainter> #include <QPainter>
#include <QJsonDocument>
#include <QJsonArray>
#include "nextcloudtheme.h" #include "nextcloudtheme.h"
@ -383,6 +385,7 @@ Theme::Theme()
#endif #endif
#ifdef APPLICATION_SERVER_URL #ifdef APPLICATION_SERVER_URL
_overrideServerUrl = QString::fromLatin1(APPLICATION_SERVER_URL); _overrideServerUrl = QString::fromLatin1(APPLICATION_SERVER_URL);
updateMultipleOverrideServers();
#endif #endif
} }
@ -432,6 +435,18 @@ bool Theme::forceOverrideServerUrl() const
return _forceOverrideServerUrl; return _forceOverrideServerUrl;
} }
void Theme::updateMultipleOverrideServers()
{
const auto json = overrideServerUrl().toUtf8();
const auto doc = QJsonDocument::fromJson(json);
_multipleOverrideServers = doc.isArray() && !doc.array().empty();
}
bool Theme::multipleOverrideServers() const
{
return _multipleOverrideServers;
}
bool Theme::isVfsEnabled() const bool Theme::isVfsEnabled() const
{ {
return _isVfsEnabled; return _isVfsEnabled;
@ -954,6 +969,7 @@ void Theme::setOverrideServerUrl(const QString &overrideServerUrl)
{ {
if (_overrideServerUrl != overrideServerUrl) { if (_overrideServerUrl != overrideServerUrl) {
_overrideServerUrl = overrideServerUrl; _overrideServerUrl = overrideServerUrl;
updateMultipleOverrideServers();
emit overrideServerUrlChanged(); emit overrideServerUrlChanged();
} }
} }

Просмотреть файл

@ -232,11 +232,18 @@ public:
/** /**
* Setting a value here will pre-define the server url. * Setting a value here will pre-define the server url.
* Can be a url OR a JSON array of servers description objects: {"name": "x", "url": "y"}
* *
* The respective UI controls will be disabled only if forceOverrideServerUrl() is true * The respective UI controls will be disabled only if forceOverrideServerUrl() is true
*/ */
[[nodiscard]] QString overrideServerUrl() const; [[nodiscard]] QString overrideServerUrl() const;
/**
* Indicates whether the override server URL is in fact a JSON array of server description
* objects.
*/
[[nodiscard]] bool multipleOverrideServers() const;
/** /**
* Enforce a pre-defined server url. * Enforce a pre-defined server url.
* *
@ -627,6 +634,7 @@ private:
Theme(Theme const &); Theme(Theme const &);
Theme &operator=(Theme const &); Theme &operator=(Theme const &);
void updateMultipleOverrideServers();
void connectToPaletteSignal(); void connectToPaletteSignal();
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
QPalette reserveDarkPalette; // Windows 11 button and window dark colours QPalette reserveDarkPalette; // Windows 11 button and window dark colours
@ -638,6 +646,7 @@ private:
QString _overrideServerUrl; QString _overrideServerUrl;
bool _forceOverrideServerUrl = false; bool _forceOverrideServerUrl = false;
bool _multipleOverrideServers = false;
bool _isVfsEnabled = false; bool _isVfsEnabled = false;
bool _startLoginFlowAutomatically = false; bool _startLoginFlowAutomatically = false;