[cse] Use server capabilities to query for cse

This commit is contained in:
Tomaz Canabrava 2017-09-03 13:33:50 +02:00 committed by Roeland Jago Douma
parent 920047fa70
commit 1c85f94b00
No known key found for this signature in database
GPG key ID: F941078878347C0C
7 changed files with 12 additions and 41 deletions

View file

@ -277,7 +277,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
}
auto fileId = _model->data(index, FolderStatusModel::FileIdRole).toByteArray();
if (accountsState()->account()->hasClientSideEncryption()) {
if (accountsState()->account()->capabilities().clientSideEncryptionAvaliable()) {
ac = menu->addAction(tr("Encrypt"));
connect(ac, &QAction::triggered, [this, &fileId](bool triggered) {
Q_UNUSED(triggered);
@ -285,6 +285,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
"ocs/v2.php/apps/client_side_encryption/api/v1/encrypted/" + QString(fileId));
connect(job, &OCC::JsonApiJob::jsonReceived, [this](const QJsonDocument& json, int httpResponse) {
Q_UNUSED(json);
qCInfo(lcAccountSettings) << "Encrypt Http Response" << httpResponse;
});
job->start();
@ -735,7 +736,7 @@ void AccountSettings::slotAccountStateChanged()
* if it has, do not offer to create one.
*/
qCInfo(lcAccountSettings) << "Accout" << accountsState()->account()->displayName()
<< "Client Side Encryption" << accountsState()->account()->hasClientSideEncryption();
<< "Client Side Encryption" << accountsState()->account()->capabilities().clientSideEncryptionAvaliable();
}
}

View file

@ -482,14 +482,4 @@ void Account::setNonShib(bool nonShib)
}
}
bool Account::hasClientSideEncryption() const
{
return _hasClientSideEncryption;
}
void Account::setHasClientSideEncryption(bool cse)
{
_hasClientSideEncryption = cse;
}
} // namespace OCC

View file

@ -225,9 +225,6 @@ public:
/// Called by network jobs on credential errors, emits invalidCredentials()
void handleInvalidCredentials();
bool hasClientSideEncryption() const;
void setHasClientSideEncryption(bool cse);
public slots:
/// Used when forgetting credentials
void clearQNAMCache();
@ -278,7 +275,6 @@ private:
QSharedPointer<QNetworkAccessManager> _am;
QScopedPointer<AbstractCredentials> _credentials;
bool _http2Supported = false;
bool _hasClientSideEncryption;
/// Certificates that were explicitly rejected by the user
QList<QSslCertificate> _rejectedCertificates;

View file

@ -81,6 +81,12 @@ bool Capabilities::shareResharing() const
return _capabilities["files_sharing"].toMap()["resharing"].toBool();
}
bool Capabilities::clientSideEncryptionAvaliable() const
{
return _capabilities.keys().indexOf("client-side-encryption") != 1
? _capabilities["client-side-encryption"].toMap()["enabled"].toBool() : false;
}
bool Capabilities::notificationsAvailable() const
{
// We require the OCS style API in 9.x, can't deal with the REST one only found in 8.2

View file

@ -53,6 +53,9 @@ public:
/// returns true if the capabilities report notifications
bool notificationsAvailable() const;
/// returns true if the server supports client side encryption
bool clientSideEncryptionAvaliable() const;
/// returns true if the capabilities are loaded already.
bool isValid() const;

View file

@ -246,36 +246,12 @@ void ConnectionValidator::slotAuthSuccess()
checkServerCapabilities();
}
void ConnectionValidator::checkClientSideEncryption()
{
JsonApiJob *job = new JsonApiJob(_account, QLatin1String("ocs/v2.php/cloud/apps"), this);
job->setTimeout(timeoutToUseMsec);
connect(job, &JsonApiJob::jsonReceived, [this](const QJsonDocument& json, int httpResponse) {
Q_UNUSED(httpResponse);
auto apps = json.object().value("ocs").toObject().value("data").toObject().value("apps").toArray().toVariantList();
bool hasClientSideEncryption = false;
for(const auto& app : qAsConst(apps)) {
if (app.toString() == "client_side_encryption") {
hasClientSideEncryption = true;
qCInfo(lcConnectionValidator()) << "Found Client Side Encryption";
break;
}
}
_account->setHasClientSideEncryption(hasClientSideEncryption);
});
job->start();
}
void ConnectionValidator::checkServerCapabilities()
{
JsonApiJob *job = new JsonApiJob(_account, QLatin1String("ocs/v1.php/cloud/capabilities"), this);
job->setTimeout(timeoutToUseMsec);
QObject::connect(job, &JsonApiJob::jsonReceived, this, &ConnectionValidator::slotCapabilitiesRecieved);
job->start();
checkClientSideEncryption();
}
void ConnectionValidator::slotCapabilitiesRecieved(const QJsonDocument &json)

View file

@ -128,7 +128,6 @@ protected slots:
private:
void reportResult(Status status);
void checkServerCapabilities();
void checkClientSideEncryption();
void fetchUser();
/** Sets the account's server version