mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
Merge pull request #3439 from rullzer/use_caps
Use server capabilities for share dialog
This commit is contained in:
commit
dccaba98af
6 changed files with 138 additions and 5 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "theme.h"
|
||||
#include "syncresult.h"
|
||||
#include "configfile.h"
|
||||
#include "capabilities.h"
|
||||
|
||||
#include "QProgressIndicator.h"
|
||||
#include <QBuffer>
|
||||
|
@ -141,6 +142,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()->publicLinkEnforcePassword()) {
|
||||
_ui->checkBox_password->setEnabled(false);
|
||||
}
|
||||
|
||||
// If expiredate is enforced do not allow disable and set max days
|
||||
if (_account->capabilities()->publicLinkEnforceExpireDate()) {
|
||||
_ui->checkBox_expire->setEnabled(false);
|
||||
_ui->calendar->setMaximumDate(QDate::currentDate().addDays(
|
||||
_account->capabilities()->publicLinkExpireDateDays()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void ShareDialog::done( int r ) {
|
||||
|
@ -247,6 +264,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;
|
||||
}
|
||||
|
@ -439,6 +461,23 @@ void ShareDialog::slotCheckBoxShareLinkClicked()
|
|||
QList<QPair<QString, QString> > 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()->publicLinkEnforcePassword()) {
|
||||
_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();
|
||||
|
||||
slotCheckBoxPasswordClicked();
|
||||
return;
|
||||
}
|
||||
|
||||
OcsShareJob *job = new OcsShareJob("POST", url, _account, this);
|
||||
job->setPostParams(postParams);
|
||||
job->addPassStatusCode(403); // "password required" is not an error
|
||||
|
|
|
@ -35,6 +35,7 @@ endif()
|
|||
set(libsync_SRCS
|
||||
account.cpp
|
||||
bandwidthmanager.cpp
|
||||
capabilities.cpp
|
||||
clientproxy.cpp
|
||||
connectionvalidator.cpp
|
||||
cookiejar.cpp
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "accessmanager.h"
|
||||
#include "creds/abstractcredentials.h"
|
||||
#include "../3rdparty/certificates/p12topem.h"
|
||||
#include "capabilities.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QMutex>
|
||||
|
@ -35,6 +36,7 @@ namespace OCC {
|
|||
|
||||
Account::Account(QObject *parent)
|
||||
: QObject(parent)
|
||||
, _capabilities(QVariantMap())
|
||||
, _am(0)
|
||||
, _credentials(0)
|
||||
, _treatSslErrorsAsFailure(false)
|
||||
|
@ -438,14 +440,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()
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <QSharedPointer>
|
||||
#include "utility.h"
|
||||
#include <memory>
|
||||
#include "capabilities.h"
|
||||
|
||||
class QSettings;
|
||||
class QNetworkReply;
|
||||
|
@ -138,7 +139,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();
|
||||
|
||||
|
@ -172,7 +173,7 @@ private:
|
|||
QUrl _url;
|
||||
QList<QSslCertificate> _approvedCerts;
|
||||
QSslConfiguration _sslConfiguration;
|
||||
QVariantMap _capabilities;
|
||||
Capabilities _capabilities;
|
||||
QString _serverVersion;
|
||||
QScopedPointer<AbstractSslErrorHandler> _sslErrorHandler;
|
||||
QuotaInfo *_quotaInfo;
|
||||
|
|
45
src/libsync/capabilities.cpp
Normal file
45
src/libsync/capabilities.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* 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 <QVariantMap>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
45
src/libsync/capabilities.h
Normal file
45
src/libsync/capabilities.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* 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 <QVariantMap>
|
||||
|
||||
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
|
Loading…
Reference in a new issue