From 7f893aa676002cc0e21ed10225be52548ebb5d84 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 10 Jul 2015 15:26:26 +0200 Subject: [PATCH 1/4] Fore password request if required by capabilities --- src/gui/sharedialog.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 2bcb126aa..d33530e21 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace { int SHARETYPE_PUBLIC = 3; @@ -422,6 +423,28 @@ void ShareDialog::slotCheckBoxShareLinkClicked() QList > postParams; postParams.append(qMakePair(QString::fromLatin1("path"), _sharePath)); postParams.append(qMakePair(QString::fromLatin1("shareType"), QString::number(SHARETYPE_PUBLIC))); + + /* + * Check the capabilities if the server requires a password for a share + * Ask for it directly + */ + if (_account->capabilities()["files_sharing"].toMap()["public"].toMap()["password"].toMap()["enforced"].toBool()) { + bool ok; + const QString pass = QInputDialog::getText(this, + tr("Password for share by link"), + tr("Sharing by link requires a password:"), + QLineEdit::Password, + QString(), + &ok); + + if (!ok) { + _pi_link->stopAnimation(); + _ui->checkBox_shareLink->setChecked(false); + return; + } + postParams.append(qMakePair(QString::fromLatin1("password"), pass)); + } + OcsShareJob *job = new OcsShareJob("POST", url, _account, this); job->setPostParams(postParams); job->addPassStatusCode(403); // "password required" is not an error From c052f6d4c96da37d4744837f3b79157c5d6f03f8 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 10 Jul 2015 15:46:17 +0200 Subject: [PATCH 2/4] Use capabilities to not allow removing of expiredate and password If the server admin has enforced the expiration date and the password our UI should not give the user the option to remove those. --- src/gui/sharedialog.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index d33530e21..c19319a7d 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -138,6 +138,22 @@ ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QSt _ui->errorLabel->setFrameShape(QFrame::Box); _ui->errorLabel->setContentsMargins(QMargins(12,12,12,12)); _ui->errorLabel->hide(); + + + // Parse capabilities + + // If password is enforced make don't allow users to disable it + if (_account->capabilities()["files_sharing"].toMap()["public"].toMap()["password"].toMap()["enforced"].toBool()) { + _ui->checkBox_password->setEnabled(false); + } + + // If expiredate is enforced do not allow disable and set max days + if (_account->capabilities()["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["enforced"].toBool()) { + _ui->checkBox_expire->setEnabled(false); + _ui->calendar->setMaximumDate(QDate::currentDate().addDays( + _account->capabilities()["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["days"].toInt() + )); + } } void ShareDialog::done( int r ) { From 7e79a7890136b1a319d1f3bcd454329cfb71c91a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 16 Jul 2015 20:55:54 +0200 Subject: [PATCH 3/4] Use already available password field --- src/gui/sharedialog.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index c19319a7d..4d9869b73 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -28,7 +28,6 @@ #include #include #include -#include namespace { int SHARETYPE_PUBLIC = 3; @@ -260,6 +259,11 @@ void ShareDialog::setPassword(const QString &password) OcsShareJob *job = new OcsShareJob(verb, url, _account, this); job->setPostParams(requestParams); connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotPasswordSet(QVariantMap))); + + if (_public_share_id == 0) { + connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotCreateShareFetched(QVariantMap))); + } + job->start(); _passwordJobRunning = true; } @@ -445,20 +449,15 @@ void ShareDialog::slotCheckBoxShareLinkClicked() * Ask for it directly */ if (_account->capabilities()["files_sharing"].toMap()["public"].toMap()["password"].toMap()["enforced"].toBool()) { - bool ok; - const QString pass = QInputDialog::getText(this, - tr("Password for share by link"), - tr("Sharing by link requires a password:"), - QLineEdit::Password, - QString(), - &ok); + _ui->checkBox_password->setChecked(true); + _ui->checkBox_password->setEnabled(false); + _ui->checkBox_password->setText(tr("Public shå requires a password")); + _ui->lineEdit_password->setFocus(); + _ui->pushButton_copy->hide(); + _ui->widget_shareLink->show(); - if (!ok) { - _pi_link->stopAnimation(); - _ui->checkBox_shareLink->setChecked(false); - return; - } - postParams.append(qMakePair(QString::fromLatin1("password"), pass)); + slotCheckBoxPasswordClicked(); + return; } OcsShareJob *job = new OcsShareJob("POST", url, _account, this); From 6c8ff7c61a35d4498359d9e7e1f511e2e75cfb99 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 16 Jul 2015 21:49:12 +0200 Subject: [PATCH 4/4] Added capabilities class --- src/gui/sharedialog.cpp | 9 ++++---- src/libsync/CMakeLists.txt | 1 + src/libsync/account.cpp | 8 ++++--- src/libsync/account.h | 5 ++-- src/libsync/capabilities.cpp | 45 ++++++++++++++++++++++++++++++++++++ src/libsync/capabilities.h | 45 ++++++++++++++++++++++++++++++++++++ 6 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 src/libsync/capabilities.cpp create mode 100644 src/libsync/capabilities.h diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 4d9869b73..750e20465 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -23,6 +23,7 @@ #include "theme.h" #include "syncresult.h" #include "configfile.h" +#include "capabilities.h" #include "QProgressIndicator.h" #include @@ -142,15 +143,15 @@ ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QSt // Parse capabilities // If password is enforced make don't allow users to disable it - if (_account->capabilities()["files_sharing"].toMap()["public"].toMap()["password"].toMap()["enforced"].toBool()) { + if (_account->capabilities()->publicLinkEnforcePassword()) { _ui->checkBox_password->setEnabled(false); } // If expiredate is enforced do not allow disable and set max days - if (_account->capabilities()["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["enforced"].toBool()) { + if (_account->capabilities()->publicLinkEnforceExpireDate()) { _ui->checkBox_expire->setEnabled(false); _ui->calendar->setMaximumDate(QDate::currentDate().addDays( - _account->capabilities()["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["days"].toInt() + _account->capabilities()->publicLinkExpireDateDays() )); } } @@ -448,7 +449,7 @@ void ShareDialog::slotCheckBoxShareLinkClicked() * Check the capabilities if the server requires a password for a share * Ask for it directly */ - if (_account->capabilities()["files_sharing"].toMap()["public"].toMap()["password"].toMap()["enforced"].toBool()) { + if (_account->capabilities()->publicLinkEnforcePassword()) { _ui->checkBox_password->setChecked(true); _ui->checkBox_password->setEnabled(false); _ui->checkBox_password->setText(tr("Public shå requires a password")); diff --git a/src/libsync/CMakeLists.txt b/src/libsync/CMakeLists.txt index a596c26a6..509b4825e 100644 --- a/src/libsync/CMakeLists.txt +++ b/src/libsync/CMakeLists.txt @@ -35,6 +35,7 @@ endif() set(libsync_SRCS account.cpp bandwidthmanager.cpp + capabilities.cpp clientproxy.cpp connectionvalidator.cpp cookiejar.cpp diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 2b789e5df..90f08724e 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -18,6 +18,7 @@ #include "accessmanager.h" #include "creds/abstractcredentials.h" #include "../3rdparty/certificates/p12topem.h" +#include "capabilities.h" #include #include @@ -35,6 +36,7 @@ namespace OCC { Account::Account(QObject *parent) : QObject(parent) + , _capabilities(QVariantMap()) , _am(0) , _credentials(0) , _treatSslErrorsAsFailure(false) @@ -434,14 +436,14 @@ void Account::setMigrated(bool mig) _wasMigrated = mig; } -QVariantMap Account::capabilities() +const Capabilities * Account::capabilities() const { - return _capabilities; + return &_capabilities; } void Account::setCapabilities(const QVariantMap &caps) { - _capabilities = caps; + _capabilities = Capabilities(caps); } QString Account::serverVersion() diff --git a/src/libsync/account.h b/src/libsync/account.h index e19795bda..e31d1e0d4 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -26,6 +26,7 @@ #include #include "utility.h" #include +#include "capabilities.h" class QSettings; class QNetworkReply; @@ -139,7 +140,7 @@ public: void setCertificate(const QByteArray certficate = QByteArray(), const QString privateKey = QString()); void setCapabilities(const QVariantMap &caps); - QVariantMap capabilities(); + const Capabilities * capabilities() const; void setServerVersion(const QString &version); QString serverVersion(); @@ -170,7 +171,7 @@ private: QUrl _url; QList _approvedCerts; QSslConfiguration _sslConfiguration; - QVariantMap _capabilities; + Capabilities _capabilities; QString _serverVersion; QScopedPointer _sslErrorHandler; QuotaInfo *_quotaInfo; diff --git a/src/libsync/capabilities.cpp b/src/libsync/capabilities.cpp new file mode 100644 index 000000000..b1137b95e --- /dev/null +++ b/src/libsync/capabilities.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) by Roeland Jago Douma + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "capabilities.h" + +#include + +namespace OCC { + + +Capabilities::Capabilities(const Capabilities &capabilities) { + _capabilities = capabilities._capabilities; +} + +Capabilities::Capabilities(const QVariantMap capabilities) + : _capabilities(capabilities) +{ +} + +bool Capabilities::publicLinkEnforcePassword() const +{ + return _capabilities["files_sharing"].toMap()["public"].toMap()["password"].toMap()["enforced"].toBool(); +} + +bool Capabilities::publicLinkEnforceExpireDate() const +{ + return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["enforced"].toBool(); +} + +int Capabilities::publicLinkExpireDateDays() const +{ + return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["days"].toInt(); +} + +} diff --git a/src/libsync/capabilities.h b/src/libsync/capabilities.h new file mode 100644 index 000000000..548895d91 --- /dev/null +++ b/src/libsync/capabilities.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) by Roeland Jago Douma + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + + +#ifndef CAPABILITIES_H +#define CAPABILITIES_H + +#include "owncloudlib.h" + +#include + +namespace OCC { + +/** + * @brief The Capabilities class represent the capabilities of an ownCloud + * server + * @ingroup libsync + */ +class Capabilities { + +public: + Capabilities(const Capabilities& capabilities); + Capabilities(const QVariantMap capabilities); + + bool publicLinkEnforcePassword() const; + bool publicLinkEnforceExpireDate() const; + int publicLinkExpireDateDays() const; + +private: + QVariantMap _capabilities; +}; + +} + +#endif //CAPABILITIES_H