If askForOptionalPassword is enabled preset a random password
authorKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 6 Oct 2020 12:01:53 +0000 (14:01 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Wed, 7 Oct 2020 09:43:47 +0000 (09:43 +0000)
This is the same approach used on the server side. Turns out I quite
like it, this avoids popping up a dialog to the user and since she won't
know the password she'll have to set a new one anyway or disable it.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/gui/sharedialog.cpp

index 709766a808a6bc802db0bc98855e9179ad281e3b..ca30aa4ff3130b015e39276c1fa93344e8d1b1d9 100644 (file)
@@ -25,6 +25,7 @@
 #include "configfile.h"
 #include "theme.h"
 #include "thumbnailjob.h"
+#include "wordlist.h"
 
 #include <QFileInfo>
 #include <QFileIconProvider>
 #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);
     }
 }