]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
detect the terms of service app is requiring the user to sign them
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 21 Oct 2024 16:25:36 +0000 (18:25 +0200)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Tue, 22 Oct 2024 13:03:45 +0000 (15:03 +0200)
will query the sign state for the terms of service and automatically
pause or resume sync

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/gui/accountsettings.cpp
src/gui/accountstate.cpp
src/gui/accountstate.h
src/gui/application.cpp
src/gui/connectionvalidator.cpp
src/gui/connectionvalidator.h
src/gui/folder.cpp
src/gui/owncloudgui.cpp
src/gui/owncloudgui.h

index 6446876cd0f194461c1ffc6d7c21eb8cffe8de9b..b882c156200793853b1e3d0c6b50b830e3307746 100644 (file)
@@ -1320,6 +1320,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.
index d1a0957791936995cf9024f0c190984aecb8aea6..a69f5ef17356c70924c52244f2c7a10f008c5d70 100644 (file)
@@ -159,6 +159,8 @@ QString AccountState::stateString(State state)
         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");
 }
@@ -346,6 +348,12 @@ void AccountState::slotConnectionValidatorResult(ConnectionValidator::Status sta
 
     _lastConnectionValidatorStatus = status;
 
+    if ((_lastConnectionValidatorStatus == ConnectionValidator::NeedToSignTermsOfService && status == ConnectionValidator::Connected) ||
+        status == ConnectionValidator::NeedToSignTermsOfService) {
+
+        emit termsOfServiceChanged(_account);
+    }
+
     // Come online gradually from 503, captive portal(redirection) or maintenance mode
     if (status == ConnectionValidator::Connected
         && (_connectionStatus == ConnectionValidator::ServiceUnavailable
@@ -424,6 +432,9 @@ void AccountState::slotConnectionValidatorResult(ConnectionValidator::Status sta
         setState(NetworkError);
         updateRetryCount();
         break;
+    case ConnectionValidator::NeedToSignTermsOfService:
+        setState(NeedToSignTermsOfService);
+        break;
     }
 }
 
index 77caa1b4051cabb176ac52815d677f6890183d2d..019b96d70cfd3022d4d898b96dbf8b4d67e95dd1 100644 (file)
@@ -82,7 +82,10 @@ public:
         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.
@@ -192,6 +195,7 @@ signals:
     void hasFetchedNavigationApps();
     void statusChanged();
     void desktopNotificationsAllowedChanged();
+    void termsOfServiceChanged(OCC::AccountPtr account);
 
 protected Q_SLOTS:
     void slotConnectionValidatorResult(OCC::ConnectionValidator::Status status, const QStringList &errors);
index 171acc75cfa8a8b3b21a2e5beff6db47cf1ba2dc..9dff3dcbfd7a3ca26e2b84823eb40b137de789c5 100644 (file)
@@ -627,6 +627,8 @@ void Application::slotAccountStateAdded(AccountState *accountState)
         _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,
index 87473c2ed05b4c463a8c867f2b49266c312c5a51..3d7c974df0ae82854844d96e44479add21328d7e 100644 (file)
@@ -267,7 +267,20 @@ void ConnectionValidator::slotCapabilitiesRecieved(const QJsonDocument &json)
     QString directEditingETag = caps["files"].toObject()["directEditing"].toObject()["etag"].toString();
     _account->fetchDirectEditors(directEditingURL, directEditingETag);
 
-    fetchUser();
+    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()
@@ -319,6 +332,22 @@ void ConnectionValidator::slotUserFetched(UserInfo *userInfo)
 #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);
index ecff3b98b4544c2b7d4a676f5d0cea9506197568..788a30da2b816cdb1834255ce6a8fcf8f863d8cc 100644 (file)
@@ -95,7 +95,8 @@ public:
         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);
 
@@ -129,6 +130,7 @@ protected slots:
 
     void slotCapabilitiesRecieved(const QJsonDocument &);
     void slotUserFetched(OCC::UserInfo *userInfo);
+    void slotServerTermsOfServiceRecieved(const QJsonDocument &reply);
 
 private:
 #ifndef TOKEN_AUTH_ONLY
@@ -136,6 +138,7 @@ private:
 #endif
     void reportResult(Status status);
     void checkServerCapabilities();
+    void checkServerTermsOfService();
     void fetchUser();
 
     /** Sets the account's server version
index 066d655c4d56c02a6148ad95ab0e37dcb50994e9..e35be0168f82d68218f5caad628a45974af97fda 100644 (file)
@@ -93,6 +93,12 @@ Folder::Folder(const FolderDefinition &definition,
     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);
 
index 60138a494943be967711871409d4b844b736de4e..abd1b6ec9cacc6563201125959b8bf7b06a4481d 100644 (file)
@@ -285,6 +285,16 @@ void ownCloudGui::slotTrayMessageIfServerUnsupported(Account *account)
     }
 }
 
+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()
 {
     bool allSignedOut = true;
index 8315fe228caa6ca828d2951314ed513d246cb74a..1cfc44876d5255e5fa92d9f8a60c8e5f19a439f7 100644 (file)
@@ -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.