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.13] detect the terms of service app is requiring the user to sign them #7388

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,9 @@ void AccountSettings::slotAccountStateChanged()
// we can't end up here as the whole block is ifdeffed
Q_UNREACHABLE();
break;
case AccountState::NeedToSignTermsOfService:
showConnectionLabel(tr("You need to accept the terms of service"));
break;
}
} else {
// ownCloud is not yet configured.
Expand Down
15 changes: 15 additions & 0 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 63, 64, 351, 352)
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -60,6 +60,10 @@
this, &AccountState::slotPushNotificationsReady);
connect(account.data(), &Account::serverUserStatusChanged, this,
&AccountState::slotServerUserStatusChanged);
connect(account.data(), &Account::termsOfServiceNeedToBeChecked,
this, [this] () {
checkConnectivity();
});

connect(this, &AccountState::isConnectedChanged, [=]{
// Get the Apps available on the server if we're now connected.
Expand Down Expand Up @@ -155,6 +159,8 @@
return tr("Configuration error");
case AskingCredentials:
return tr("Asking Credentials");
case NeedToSignTermsOfService:
return tr("Need the user to accept the terms of service");
}
return tr("Unknown account state");
}
Expand Down Expand Up @@ -342,6 +348,12 @@

_lastConnectionValidatorStatus = status;

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

emit termsOfServiceChanged(_account);

Check warning on line 354 in src/gui/accountstate.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/accountstate.cpp:354:14 [cppcoreguidelines-init-variables]

variable 'termsOfServiceChanged' is not initialized
}

// Come online gradually from 503, captive portal(redirection) or maintenance mode
if (status == ConnectionValidator::Connected
&& (_connectionStatus == ConnectionValidator::ServiceUnavailable
Expand Down Expand Up @@ -420,6 +432,9 @@
setState(NetworkError);
updateRetryCount();
break;
case ConnectionValidator::NeedToSignTermsOfService:
setState(NeedToSignTermsOfService);
break;
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/gui/accountstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ class AccountState : public QObject, public QSharedData
ConfigurationError,

/// We are currently asking the user for credentials
AskingCredentials
AskingCredentials,

/// Need to sign terms of service by going to web UI
NeedToSignTermsOfService,
};

/// The actual current connectivity status.
Expand Down Expand Up @@ -192,6 +195,7 @@ public slots:
void hasFetchedNavigationApps();
void statusChanged();
void desktopNotificationsAllowedChanged();
void termsOfServiceChanged(OCC::AccountPtr account);

protected Q_SLOTS:
void slotConnectionValidatorResult(OCC::ConnectionValidator::Status status, const QStringList &errors);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

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

View workflow job for this annotation

GitHub Actions / build

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

File src/gui/application.cpp does not conform to Custom style guidelines. (lines 591)
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
Expand Down Expand Up @@ -588,6 +588,8 @@
_gui.data(), &ownCloudGui::slotAccountStateChanged);
connect(accountState->account().data(), &Account::serverVersionChanged,
_gui.data(), &ownCloudGui::slotTrayMessageIfServerUnsupported);
connect(accountState, &AccountState::termsOfServiceChanged,
_gui.data(), &ownCloudGui::slotNeedToAcceptTermsOfService);
connect(accountState, &AccountState::stateChanged,
_folderManager.data(), &FolderMan::slotAccountStateChanged);
connect(accountState->account().data(), &Account::serverVersionChanged,
Expand Down
31 changes: 30 additions & 1 deletion 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 279, 280, 281)
* 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 @@ -267,7 +267,20 @@
QString directEditingETag = caps["files"].toObject()["directEditing"].toObject()["etag"].toString();
_account->fetchDirectEditors(directEditingURL, directEditingETag);

fetchUser();
checkServerTermsOfService();
}

void ConnectionValidator::checkServerTermsOfService()

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

View workflow job for this annotation

GitHub Actions / build

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

method 'checkServerTermsOfService' can be made static
{
// 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 276 in src/gui/connectionvalidator.cpp

View workflow job for this annotation

GitHub Actions / build

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

variable 'job' is not initialized
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()
Expand Down Expand Up @@ -321,6 +334,22 @@
#endif
}

void ConnectionValidator::slotServerTermsOfServiceRecieved(const QJsonDocument &reply)
{
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;
}
}

fetchUser();
}

#ifndef TOKEN_AUTH_ONLY
void ConnectionValidator::reportConnected() {
reportResult(Connected);
Expand Down
5 changes: 4 additions & 1 deletion src/gui/connectionvalidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -95,7 +95,8 @@
StatusRedirect, // 204 URL received one of redirect HTTP codes (301-307), possibly a captive portal
ServiceUnavailable, // 503 on authed request
MaintenanceMode, // maintenance enabled in status.php
Timeout // actually also used for other errors on the authed request
Timeout, // actually also used for other errors on the authed request
NeedToSignTermsOfService,
};
Q_ENUM(Status);

Expand Down Expand Up @@ -129,13 +130,15 @@

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

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 Down
6 changes: 6 additions & 0 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

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

View workflow job for this annotation

GitHub Actions / build

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

File src/gui/folder.cpp does not conform to Custom style guidelines. (lines 95, 96, 97, 98)
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
Expand All @@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "common/syncjournaldb.h"

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

View workflow job for this annotation

GitHub Actions / build

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

'common/syncjournaldb.h' file not found
#include "config.h"

#include "account.h"
Expand Down Expand Up @@ -92,6 +92,12 @@
if (!reloadExcludes())
qCWarning(lcFolder, "Could not read system exclude file");

connect(_accountState.data(), &AccountState::termsOfServiceChanged,
this, [this] ()
{
setSyncPaused(_accountState->state() == AccountState::NeedToSignTermsOfService);
});

connect(_accountState.data(), &AccountState::isConnectedChanged, this, &Folder::canSyncChanged);
connect(_engine.data(), &SyncEngine::rootEtag, this, &Folder::etagRetrievedFromSyncEngine);

Expand Down
10 changes: 10 additions & 0 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

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

View workflow job for this annotation

GitHub Actions / build

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

File src/gui/owncloudgui.cpp does not conform to Custom style guidelines. (lines 280, 281, 282, 283)
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -275,7 +275,17 @@
}
}

void ownCloudGui::slotNeedToAcceptTermsOfService(OCC::AccountPtr account)
{
slotShowTrayMessage(
tr("Terms of service"),
tr("Your account %1 requires you to accept the terms of service of your server. "
"You will be redirected to %2 to acknowledge that you have read it and agrees with it.")
.arg(account->displayName(), account->url().toString()));
QDesktopServices::openUrl(account->url());
}

void ownCloudGui::slotComputeOverallSyncStatus()

Check warning on line 288 in src/gui/owncloudgui.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudgui.cpp:288:19 [readability-convert-member-functions-to-static]

method 'slotComputeOverallSyncStatus' can be made static
{
bool allSignedOut = true;
bool allPaused = true;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/owncloudgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public slots:
void slotOpenPath(const QString &path);
void slotAccountStateChanged();
void slotTrayMessageIfServerUnsupported(OCC::Account *account);

void slotNeedToAcceptTermsOfService(OCC::AccountPtr account);

/**
* Open a share dialog for a file or folder.
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef SERVERCONNECTION_H
#define SERVERCONNECTION_H

#include <QByteArray>

Check failure on line 19 in src/libsync/account.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/account.h:19:10 [clang-diagnostic-error]

'QByteArray' file not found
#include <QUrl>
#include <QNetworkCookie>
#include <QNetworkRequest>
Expand Down Expand Up @@ -377,6 +377,8 @@
void lockFileSuccess();
void lockFileError(const QString&);

void termsOfServiceNeedToBeChecked();

protected Q_SLOTS:
void slotCredentialsFetched();
void slotCredentialsAsked();
Expand Down
4 changes: 4 additions & 0 deletions src/libsync/discoveryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,11 @@
msg = tr("Server error: PROPFIND reply is not XML formatted!");
}

if (r->error() == QNetworkReply::ContentAccessDenied) {
emit _account->termsOfServiceNeedToBeChecked();

Check warning on line 655 in src/libsync/discoveryphase.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/discoveryphase.cpp:655:14 [cppcoreguidelines-init-variables]

variable '_account' is not initialized
}

emit finished(HttpError{ httpCode, msg });

Check warning on line 658 in src/libsync/discoveryphase.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/discoveryphase.cpp:658:10 [cppcoreguidelines-init-variables]

variable 'finished' is not initialized
deleteLater();
}

Expand Down
Loading