Skip to content

Commit

Permalink
detect the need to sign the terms of service during login web flow v2
Browse files Browse the repository at this point in the history
should avoid being blocked by terms_of_service blocking WebDAV access

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
  • Loading branch information
mgallien committed Feb 17, 2025
1 parent 6203d8a commit 20af49e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/gui/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ void TermsOfServiceChecker::slotServerTermsOfServiceRecieved(const QJsonDocument
if (reply.object().contains("ocs")) {
const auto needToSign = !reply.object().value("ocs").toObject().value("data").toObject().value("hasSigned").toBool(false);
if (needToSign != _needToSign) {
qCInfo(lcConnectionValidator) << "_needToSign" << (_needToSign ? "need to sign" : "no need to sign");
_needToSign = needToSign;
qCInfo(lcConnectionValidator) << "_needToSign" << (_needToSign ? "need to sign" : "no need to sign");
emit needToSignChanged();

Check warning on line 395 in src/gui/connectionvalidator.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:395:18 [modernize-use-trailing-return-type]

use a trailing return type for this function
}
} else if (_needToSign) {
Expand Down
46 changes: 38 additions & 8 deletions src/gui/owncloudsetupwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
* for more details.
*/

#include <QAbstractButton>
#include <QtCore>
#include <QProcess>
#include <QMessageBox>
#include <QDesktopServices>
#include <QApplication>

#include "accessmanager.h"

Check failure on line 16 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudsetupwizard.cpp:16:10 [clang-diagnostic-error]

'accessmanager.h' file not found
#include "account.h"
#include "accountmanager.h"
Expand All @@ -35,11 +28,19 @@
#include "sslerrordialog.h"
#include "wizard/owncloudwizard.h"
#include "wizard/owncloudwizardcommon.h"
#include "connectionvalidator.h"

#include "creds/credentialsfactory.h"
#include "creds/abstractcredentials.h"
#include "creds/dummycredentials.h"

#include <QAbstractButton>
#include <QtCore>
#include <QProcess>
#include <QMessageBox>
#include <QDesktopServices>
#include <QApplication>

namespace OCC {

OwncloudSetupWizard::OwncloudSetupWizard(QObject *parent)
Expand Down Expand Up @@ -377,7 +378,14 @@ void OwncloudSetupWizard::testOwnCloudConnect()
job->setFollowRedirects(false);
job->setProperties(QList<QByteArray>() << "getlastmodified");
connect(job, &PropfindJob::result, _ocWizard, &OwncloudWizard::successfulStep);
connect(job, &PropfindJob::finishedWithError, this, &OwncloudSetupWizard::slotAuthError);
connect(job, &PropfindJob::finishedWithError, this, [this] (QNetworkReply *reply) {
if (reply && reply->error() == QNetworkReply::ContentAccessDenied) {
testTermsOfService();
} else {
slotAuthError();
}
});

job->start();
}

Expand Down Expand Up @@ -416,6 +424,9 @@ void OwncloudSetupWizard::slotAuthError()

// A 404 is actually a success: we were authorized to know that the folder does
// not exist. It will be created later...
} else if (reply->error() == QNetworkReply::ContentAccessDenied) {
testTermsOfService();
return;
} else if (reply->error() == QNetworkReply::ContentNotFoundError) {
_ocWizard->successfulStep();
return;
Expand Down Expand Up @@ -473,6 +484,14 @@ bool OwncloudSetupWizard::checkDowngradeAdvised(QNetworkReply *reply)
return true;
}

void OwncloudSetupWizard::testTermsOfService()
{
_termsOfServiceChecker = new TermsOfServiceChecker{_ocWizard->account(), this};

Check warning on line 489 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudsetupwizard.cpp:489:5 [cppcoreguidelines-owning-memory]

assigning newly created 'gsl::owner<>' to non-owner 'OCC::TermsOfServiceChecker *'

connect(_termsOfServiceChecker, &TermsOfServiceChecker::done, this, &OwncloudSetupWizard::termsOfServiceChecked);
_termsOfServiceChecker->start();
}

void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString &localFolder, const QString &remoteFolder)

Check warning on line 495 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudsetupwizard.cpp:495:59 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'slotCreateLocalAndRemoteFolders' of similar type ('const QString &') are easily swapped by mistake
{
qCInfo(lcWizard) << "Setup local sync folder for new oC connection " << localFolder;
Expand Down Expand Up @@ -726,6 +745,17 @@ void OwncloudSetupWizard::slotSkipFolderConfiguration()
emit ownCloudWizardDone(QDialog::Accepted);
}

void OwncloudSetupWizard::termsOfServiceChecked()
{
if (_termsOfServiceChecker && _termsOfServiceChecker->needToSign()) {

Check warning on line 750 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudsetupwizard.cpp:750:9 [readability-implicit-bool-conversion]

implicit conversion 'OCC::TermsOfServiceChecker *' -> bool
QDesktopServices::openUrl(_ocWizard->account()->url());
} else {
_ocWizard->successfulStep();
delete _termsOfServiceChecker;
_termsOfServiceChecker = nullptr;
}
}

AccountState *OwncloudSetupWizard::applyAccountChanges()

Check warning on line 759 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudsetupwizard.cpp:759:36 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 759 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudsetupwizard.cpp:759:36 [readability-convert-member-functions-to-static]

method 'applyAccountChanges' can be made static
{
AccountPtr newAccount = _ocWizard->account();
Expand Down
7 changes: 6 additions & 1 deletion src/gui/owncloudsetupwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
namespace OCC {

class AccountState;
class TermsOfServiceChecker;

class OwncloudWizard;

Expand Down Expand Up @@ -69,6 +70,8 @@ private slots:
void slotAssistantFinished(int);
void slotSkipFolderConfiguration();

void termsOfServiceChecked();

private:
explicit OwncloudSetupWizard(QObject *parent = nullptr);
~OwncloudSetupWizard() override;
Expand All @@ -79,8 +82,10 @@ private slots:
bool ensureStartFromScratch(const QString &localFolder);
AccountState *applyAccountChanges();
bool checkDowngradeAdvised(QNetworkReply *reply);
void testTermsOfService();

OwncloudWizard *_ocWizard;
TermsOfServiceChecker *_termsOfServiceChecker = nullptr;
OwncloudWizard *_ocWizard = nullptr;
QString _initLocalFolder;
QString _remoteFolder;
};
Expand Down
12 changes: 12 additions & 0 deletions src/gui/wizard/owncloudadvancedsetuppage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ void OwncloudAdvancedSetupPage::initializePage()
quotaJob->setProperties(QList<QByteArray>() << "http://owncloud.org/ns:size");

connect(quotaJob, &PropfindJob::result, this, &OwncloudAdvancedSetupPage::slotQuotaRetrieved);
connect(quotaJob, &PropfindJob::finishedWithError, this, &OwncloudAdvancedSetupPage::slotQuotaRetrievedWithError);
quotaJob->start();


Expand Down Expand Up @@ -547,6 +548,17 @@ void OwncloudAdvancedSetupPage::slotQuotaRetrieved(const QVariantMap &result)
updateStatus();
}

void OwncloudAdvancedSetupPage::slotQuotaRetrievedWithError(QNetworkReply *reply)
{
if (reply && reply->error() == QNetworkReply::ContentAccessDenied) {

}
_rSize = -1;
_ui.lSyncEverythingSizeLabel->setText({});

updateStatus();
}

qint64 OwncloudAdvancedSetupPage::availableLocalSpace() const
{
QString localDir = localFolder();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/wizard/owncloudadvancedsetuppage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "elidedlabel.h"

class QProgressIndicator;
class QNetworkReply;

Check warning on line 26 in src/gui/wizard/owncloudadvancedsetuppage.h

View workflow job for this annotation

GitHub Actions / build

src/gui/wizard/owncloudadvancedsetuppage.h:26:7 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'QNetworkReply' is non-const and globally accessible, consider making it const

namespace OCC {

Expand Down Expand Up @@ -63,6 +64,7 @@ private slots:
void slotSelectiveSyncClicked();
void slotVirtualFileSyncClicked();
void slotQuotaRetrieved(const QVariantMap &result);
void slotQuotaRetrievedWithError(QNetworkReply *reply);

private:
void setRadioChecked(QRadioButton *radio);
Expand Down

0 comments on commit 20af49e

Please sign in to comment.