Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.14] content access denied error during discovery: verify server access #7392

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/accountstate.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/accountstate.cpp

File src/gui/accountstate.cpp does not conform to Custom style guidelines. (lines 68, 69, 70, 71, 72, 73, 76, 77, 78, 365)
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -48,6 +48,7 @@
, _state(AccountState::Disconnected)
, _connectionStatus(ConnectionValidator::Undefined)
, _waitingForNewCredentials(false)
, _termsOfServiceChecker(_account)
, _maintenanceToConnectedDelay(60000 + (QRandomGenerator::global()->generate() % (4 * 60000))) // 1-5min delay
, _remoteWipe(new RemoteWipe(_account))
, _isDesktopNotificationsAllowed(true)
Expand All @@ -64,10 +65,18 @@
this, &AccountState::slotPushNotificationsReady);
connect(account.data(), &Account::serverUserStatusChanged, this,
&AccountState::slotServerUserStatusChanged);
connect(&_termsOfServiceChecker, &TermsOfServiceChecker::done,
this, [this] ()
{
if (_termsOfServiceChecker.needToSign()) {
slotConnectionValidatorResult(ConnectionValidator::NeedToSignTermsOfService, {});
}
});
connect(account.data(), &Account::termsOfServiceNeedToBeChecked,
this, [this] () {
checkConnectivity();
});
this, [this] ()
{
_termsOfServiceChecker.start();
});

connect(this, &AccountState::isConnectedChanged, [=]{
// Get the Apps available on the server if we're now connected.
Expand Down Expand Up @@ -353,7 +362,7 @@
_lastConnectionValidatorStatus = status;

if ((_lastConnectionValidatorStatus == ConnectionValidator::NeedToSignTermsOfService && status == ConnectionValidator::Connected) ||
status == ConnectionValidator::NeedToSignTermsOfService) {
(status == ConnectionValidator::NeedToSignTermsOfService && _lastConnectionValidatorStatus != status)) {

emit termsOfServiceChanged(_account);
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/accountstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private Q_SLOTS:
bool _waitingForNewCredentials = false;
QDateTime _timeOfLastETagCheck;
QPointer<ConnectionValidator> _connectionValidator;
TermsOfServiceChecker _termsOfServiceChecker;
QByteArray _notificationsEtagResponseHeader;
QByteArray _navigationAppsEtagResponseHeader;

Expand Down
91 changes: 68 additions & 23 deletions src/gui/connectionvalidator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/connectionvalidator.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/connectionvalidator.cpp

File src/gui/connectionvalidator.cpp does not conform to Custom style guidelines. (lines 47, 407, 408, 409)
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -12,7 +12,7 @@
* for more details.
*/

#include <QJsonDocument>

Check failure on line 15 in src/gui/connectionvalidator.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:15:10 [clang-diagnostic-error]

'QJsonDocument' file not found
#include <QJsonObject>
#include <QJsonArray>
#include <QLoggingCategory>
Expand Down Expand Up @@ -42,7 +42,10 @@
, _previousErrors(previousErrors)
, _accountState(accountState)
, _account(accountState->account())
, _termsOfServiceChecker(_account)
{
connect(&_termsOfServiceChecker, &TermsOfServiceChecker::done,
this, &ConnectionValidator::termsOfServiceCheckDone);
}

void ConnectionValidator::checkServerAndAuth()
Expand Down Expand Up @@ -270,19 +273,6 @@
checkServerTermsOfService();
}

void ConnectionValidator::checkServerTermsOfService()
{
// The main flow now needs the capabilities
auto *job = new JsonApiJob(_account, QLatin1String("ocs/v2.php/apps/terms_of_service/terms"), this);
job->setTimeout(timeoutToUseMsec);
QObject::connect(job, &JsonApiJob::jsonReceived, this, &ConnectionValidator::slotServerTermsOfServiceRecieved);
QObject::connect(job, &JsonApiJob::networkError, this, [] (QNetworkReply *reply)
{
qCInfo(lcConnectionValidator()) << "network error" << reply->error();
});
job->start();
}

void ConnectionValidator::fetchUser()
{
auto *userInfo = new UserInfo(_accountState.data(), true, true, this);
Expand Down Expand Up @@ -317,7 +307,12 @@
return true;
}

void ConnectionValidator::checkServerTermsOfService()
{
_termsOfServiceChecker.start();
}

void ConnectionValidator::slotUserFetched(UserInfo *userInfo)

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:315:27 [readability-convert-member-functions-to-static]

method 'slotUserFetched' can be made static
{
if(userInfo) {
userInfo->setActive(false);
Expand All @@ -332,17 +327,11 @@
#endif
}

void ConnectionValidator::slotServerTermsOfServiceRecieved(const QJsonDocument &reply)
void ConnectionValidator::termsOfServiceCheckDone()
{
qCDebug(lcConnectionValidator) << "Terms of service status" << reply;

if (reply.object().contains("ocs")) {
const auto hasSigned = reply.object().value("ocs").toObject().value("data").toObject().value("hasSigned").toBool(false);

if (!hasSigned) {
reportResult(NeedToSignTermsOfService);
return;
}
if (_termsOfServiceChecker.needToSign()) {
reportResult(NeedToSignTermsOfService);
return;
}

fetchUser();
Expand All @@ -366,4 +355,60 @@
deleteLater();
}

TermsOfServiceChecker::TermsOfServiceChecker(AccountPtr account, QObject *parent)

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:358:1 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: , , , _account
: QObject(parent)
, _account(account)
{
}

TermsOfServiceChecker::TermsOfServiceChecker(QObject *parent)

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:364:1 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: , , , _account
: QObject(parent)
{
}

bool TermsOfServiceChecker::needToSign() const

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:369:29 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
return _needToSign;
}

void TermsOfServiceChecker::start()
{
checkServerTermsOfService();
}

void TermsOfServiceChecker::slotServerTermsOfServiceRecieved(const QJsonDocument &reply)
{
qCDebug(lcConnectionValidator) << "Terms of service status" << reply;

if (reply.object().contains("ocs")) {
const auto needToSign = !reply.object().value("ocs").toObject().value("data").toObject().value("hasSigned").toBool(false);
if (needToSign != _needToSign) {
_needToSign = needToSign;
emit needToSignChanged();

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

View workflow job for this annotation

GitHub Actions / build

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

use a trailing return type for this function
}
} else if (_needToSign) {
_needToSign = false;
emit needToSignChanged();

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:391:14 [modernize-use-trailing-return-type]

use a trailing return type for this function
}

emit done();

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:394:10 [modernize-use-trailing-return-type]

use a trailing return type for this function
}

void TermsOfServiceChecker::checkServerTermsOfService()

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:397:29 [readability-convert-member-functions-to-static]

method 'checkServerTermsOfService' can be made static
{
if (!_account) {
emit done();

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:400:14 [modernize-use-trailing-return-type]

use a trailing return type for this function
}

// The main flow now needs the capabilities
auto *job = new JsonApiJob(_account, QLatin1String("ocs/v2.php/apps/terms_of_service/terms"), this);

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

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.cpp:404:11 [cppcoreguidelines-init-variables]

variable 'job' is not initialized
job->setTimeout(timeoutToUseMsec);
QObject::connect(job, &JsonApiJob::jsonReceived, this, &TermsOfServiceChecker::slotServerTermsOfServiceRecieved);
QObject::connect(job, &JsonApiJob::networkError, this, [] (QNetworkReply *reply)
{
qCInfo(lcConnectionValidator()) << "network error" << reply->error();
});
job->start();
}

} // namespace OCC
38 changes: 36 additions & 2 deletions src/gui/connectionvalidator.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/connectionvalidator.h

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/connectionvalidator.h

File src/gui/connectionvalidator.h does not conform to Custom style guidelines. (lines 84)
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -15,7 +15,7 @@
#ifndef CONNECTIONVALIDATOR_H
#define CONNECTIONVALIDATOR_H

#include "owncloudlib.h"

Check failure on line 18 in src/gui/connectionvalidator.h

View workflow job for this annotation

GitHub Actions / build

src/gui/connectionvalidator.h:18:10 [clang-diagnostic-error]

'owncloudlib.h' file not found
#include <QObject>
#include <QStringList>
#include <QVariantMap>
Expand Down Expand Up @@ -75,6 +75,37 @@

class UserInfo;

class TermsOfServiceChecker : public QObject
{
Q_OBJECT

Q_PROPERTY(bool needToSign READ needToSign NOTIFY needToSignChanged FINAL)
public:
explicit TermsOfServiceChecker(AccountPtr account,
QObject *parent = nullptr);

explicit TermsOfServiceChecker(QObject *parent = nullptr);

[[nodiscard]] bool needToSign() const;

public slots:
void start();

signals:
void needToSignChanged();

void done();

private slots:
void slotServerTermsOfServiceRecieved(const QJsonDocument &reply);

private:
void checkServerTermsOfService();

AccountPtr _account;
bool _needToSign = false;
};

class ConnectionValidator : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -130,15 +161,15 @@

void slotCapabilitiesRecieved(const QJsonDocument &);
void slotUserFetched(OCC::UserInfo *userInfo);
void slotServerTermsOfServiceRecieved(const QJsonDocument &reply);

void termsOfServiceCheckDone();

private:
#ifndef TOKEN_AUTH_ONLY
void reportConnected();
#endif
void reportResult(Status status);
void checkServerCapabilities();
void checkServerTermsOfService();
void fetchUser();

/** Sets the account's server version
Expand All @@ -147,10 +178,13 @@
*/
bool setAndCheckServerVersion(const QString &version);

void checkServerTermsOfService();

const QStringList _previousErrors;
QStringList _errors;
AccountStatePtr _accountState;
AccountPtr _account;
TermsOfServiceChecker _termsOfServiceChecker;
bool _isCheckingServerAndAuth = false;
};
}
Expand Down
Loading