// 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.
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");
}
_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
setState(NetworkError);
updateRetryCount();
break;
+ case ConnectionValidator::NeedToSignTermsOfService:
+ setState(NeedToSignTermsOfService);
+ break;
}
}
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.
void hasFetchedNavigationApps();
void statusChanged();
void desktopNotificationsAllowedChanged();
+ void termsOfServiceChanged(OCC::AccountPtr account);
protected Q_SLOTS:
void slotConnectionValidatorResult(OCC::ConnectionValidator::Status status, const QStringList &errors);
_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,
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()
#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);
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);
void slotCapabilitiesRecieved(const QJsonDocument &);
void slotUserFetched(OCC::UserInfo *userInfo);
+ void slotServerTermsOfServiceRecieved(const QJsonDocument &reply);
private:
#ifndef TOKEN_AUTH_ONLY
#endif
void reportResult(Status status);
void checkServerCapabilities();
+ void checkServerTermsOfService();
void fetchUser();
/** Sets the account's server version
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);
}
}
+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;
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.