Merge pull request #2520 from nextcloud/handle_askForOptionalPassword_capability

Handle ask for optional password capability
This commit is contained in:
Michael Schuster 2020-10-07 15:30:17 +02:00 committed by GitHub
commit f90ae66d94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 1 deletions

View file

@ -25,6 +25,7 @@
#include "configfile.h"
#include "theme.h"
#include "thumbnailjob.h"
#include "wordlist.h"
#include <QFileInfo>
#include <QFileIconProvider>
@ -33,6 +34,20 @@
#include <QPushButton>
#include <QFrame>
namespace {
QString createRandomPassword()
{
const auto words = OCC::WordList::getRandomWords(10);
const auto addFirstLetter = [](const QString &current, const QString &next) {
return current + next.at(0);
};
return std::accumulate(std::cbegin(words), std::cend(words), QString(), addFirstLetter);
}
}
namespace OCC {
static const int thumbnailSize = 40;
@ -303,7 +318,9 @@ void ShareDialog::showSharingUi()
void ShareDialog::slotCreateLinkShare()
{
if(_manager) {
_manager->createLinkShare(_sharePath, QString(), QString());
const auto askOptionalPassword = _accountState->account()->capabilities().sharePublicLinkAskOptionalPassword();
const auto password = askOptionalPassword ? createRandomPassword() : QString();
_manager->createLinkShare(_sharePath, QString(), password);
}
}

View file

@ -744,6 +744,7 @@ void SocketApi::sendSharingContextMenuOptions(const FileData &fileData, SocketLi
// Is is possible to create a public link without user choices?
bool canCreateDefaultPublicLink = publicLinksEnabled
&& !capabilities.sharePublicLinkEnforceExpireDate()
&& !capabilities.sharePublicLinkAskOptionalPassword()
&& !capabilities.sharePublicLinkEnforcePassword();
if (canCreateDefaultPublicLink) {

View file

@ -59,6 +59,11 @@ bool Capabilities::sharePublicLinkSupportsUploadOnly() const
return _capabilities["files_sharing"].toMap()["public"].toMap()["supports_upload_only"].toBool();
}
bool Capabilities::sharePublicLinkAskOptionalPassword() const
{
return _capabilities["files_sharing"].toMap()["public"].toMap()["password"].toMap()["askForOptionalPassword"].toBool();
}
bool Capabilities::sharePublicLinkEnforcePassword() const
{
return _capabilities["files_sharing"].toMap()["public"].toMap()["password"].toMap()["enforced"].toBool();

View file

@ -40,6 +40,7 @@ public:
bool sharePublicLink() const;
bool sharePublicLinkAllowUpload() const;
bool sharePublicLinkSupportsUploadOnly() const;
bool sharePublicLinkAskOptionalPassword() const;
bool sharePublicLinkEnforcePassword() const;
bool sharePublicLinkEnforceExpireDate() const;
int sharePublicLinkExpireDateDays() const;