Skip to content

Commit eddad3b

Browse files
committed
allow usage of public link to shared folders as an account URL
currently sync does not work you can login automatically unles a password is needed in that case, you get a prompt Signed-off-by: Matthieu Gallien <[email protected]>
1 parent 907b07c commit eddad3b

12 files changed

+169
-45
lines changed

src/gui/accountmanager.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ void AccountManager::saveAccountHelper(Account *account, QSettings &settings, bo
332332
{
333333
qCDebug(lcAccountManager) << "Saving settings to" << settings.fileName();
334334
settings.setValue(QLatin1String(versionC), maxAccountVersion);
335-
settings.setValue(QLatin1String(urlC), account->_url.toString());
335+
if (account->isPublicShareLink()) {
336+
settings.setValue(QLatin1String(urlC), account->publicShareLinkUrl().toString());
337+
} else {
338+
settings.setValue(QLatin1String(urlC), account->_url.toString());
339+
}
336340
settings.setValue(QLatin1String(davUserC), account->_davUser);
337341
settings.setValue(QLatin1String(displayNameC), account->davDisplayName());
338342
settings.setValue(QLatin1String(serverVersionC), account->_serverVersion);

src/gui/connectionvalidator.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ void ConnectionValidator::slotCapabilitiesRecieved(const QJsonDocument &json)
271271
_account->fetchDirectEditors(directEditingURL, directEditingETag);
272272

273273
checkServerTermsOfService();
274+
275+
if (_account->isPublicShareLink()) {
276+
slotUserFetched(nullptr);
277+
return;
278+
}
279+
280+
fetchUser();
274281
}
275282

276283
void ConnectionValidator::fetchUser()

src/gui/owncloudsetupwizard.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "sslerrordialog.h"
3535
#include "wizard/owncloudwizard.h"
3636
#include "wizard/owncloudwizardcommon.h"
37+
#include "account.h"
3738

3839
#include "creds/credentialsfactory.h"
3940
#include "creds/abstractcredentials.h"
@@ -290,7 +291,11 @@ void OwncloudSetupWizard::slotFoundServer(const QUrl &url, const QJsonObject &in
290291
qCInfo(lcWizard) << " was redirected to" << url.toString();
291292
}
292293

293-
slotDetermineAuthType();
294+
if (_ocWizard->account()->isPublicShareLink()) {
295+
_ocWizard->setAuthType(DetermineAuthTypeJob::Basic);
296+
} else {
297+
slotDetermineAuthType();
298+
}
294299
}
295300

296301
void OwncloudSetupWizard::slotNoServerFound(QNetworkReply *reply)
@@ -341,6 +346,19 @@ void OwncloudSetupWizard::slotConnectToOCUrl(const QString &url)
341346
_ocWizard->account()->setCredentials(creds);
342347
}
343348

349+
if (_ocWizard->account()->isPublicShareLink()) {
350+
_ocWizard->account()->setDavUser(creds->user());
351+
_ocWizard->account()->setDavDisplayName(creds->user());
352+
353+
_ocWizard->setField(QLatin1String("OCUrl"), url);
354+
_ocWizard->appendToConfigurationLog(tr("Trying to connect to %1 at %2 …")
355+
.arg(Theme::instance()->appNameGUI())
356+
.arg(url));
357+
358+
testOwnCloudConnect();
359+
return;
360+
}
361+
344362
const auto fetchUserNameJob = new JsonApiJob(_ocWizard->account()->sharedFromThis(), QStringLiteral("/ocs/v1.php/cloud/user"));
345363
connect(fetchUserNameJob, &JsonApiJob::jsonReceived, this, [this, url](const QJsonDocument &json, int statusCode) {
346364
if (statusCode != 100) {
@@ -731,6 +749,11 @@ AccountState *OwncloudSetupWizard::applyAccountChanges()
731749
auto manager = AccountManager::instance();
732750

733751
auto newState = manager->addAccount(newAccount);
752+
753+
if (newAccount->isPublicShareLink()) {
754+
qCInfo(lcWizard()) << "seeting up public share link account";
755+
}
756+
734757
manager->saveAccount(newAccount.data());
735758
return newState;
736759
}

src/gui/tray/UserLine.qml

+4-1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ AbstractButton {
152152
}
153153

154154
MenuItem {
155+
visible: model.canLogout
156+
height: visible ? implicitHeight : 0
157+
width: parent.width
155158
text: model.isConnected ? qsTr("Log out") : qsTr("Log in")
156159
font.pixelSize: Style.topLinePixelSize
157160
hoverEnabled: true
@@ -175,7 +178,7 @@ AbstractButton {
175178

176179
MenuItem {
177180
id: removeAccountButton
178-
text: qsTr("Remove account")
181+
text: model.removeAccountText
179182
font.pixelSize: Style.topLinePixelSize
180183
hoverEnabled: true
181184
onClicked: {

src/gui/tray/usermodel.cpp

+71-32
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,16 @@ const QVariantList &User::groupFolders() const
884884
return _trayFolderInfos;
885885
}
886886

887+
bool User::canLogout() const
888+
{
889+
return !isPublicShareLink();
890+
}
891+
892+
bool User::isPublicShareLink() const
893+
{
894+
return _account->account()->isPublicShareLink();
895+
}
896+
887897
void User::slotItemCompleted(const QString &folder, const SyncFileItemPtr &item)
888898
{
889899
auto folderInstance = FolderMan::instance()->folder(folder);
@@ -988,17 +998,27 @@ void User::logout() const
988998

989999
QString User::name() const
9901000
{
1001+
if (isPublicShareLink()) {
1002+
return tr("Public Share Link");
1003+
}
1004+
9911005
return _account->account()->prettyName();
9921006
}
9931007

9941008
QString User::server(bool shortened) const
9951009
{
996-
QString serverUrl = _account->account()->url().toString();
1010+
auto serverUrl = _account->account()->url();
1011+
1012+
if (isPublicShareLink()) {
1013+
serverUrl.setUserName({});
1014+
}
1015+
QString stringServerUrl = serverUrl.toString();
9971016
if (shortened) {
998-
serverUrl.replace(QLatin1String("https://"), QLatin1String(""));
999-
serverUrl.replace(QLatin1String("http://"), QLatin1String(""));
1017+
stringServerUrl.replace(QLatin1String("https://"), QLatin1String(""));
1018+
stringServerUrl.replace(QLatin1String("http://"), QLatin1String(""));
1019+
10001020
}
1001-
return serverUrl;
1021+
return stringServerUrl;
10021022
}
10031023

10041024
UserStatus::OnlineStatus User::status() const
@@ -1509,34 +1529,51 @@ int UserModel::rowCount(const QModelIndex &parent) const
15091529

15101530
QVariant UserModel::data(const QModelIndex &index, int role) const
15111531
{
1512-
if (index.row() < 0 || index.row() >= _users.count()) {
1513-
return QVariant();
1514-
}
1515-
1516-
if (role == NameRole) {
1517-
return _users[index.row()]->name();
1518-
} else if (role == ServerRole) {
1519-
return _users[index.row()]->server();
1520-
} else if (role == ServerHasUserStatusRole) {
1521-
return _users[index.row()]->serverHasUserStatus();
1522-
} else if (role == StatusIconRole) {
1523-
return _users[index.row()]->statusIcon();
1524-
} else if (role == StatusEmojiRole) {
1525-
return _users[index.row()]->statusEmoji();
1526-
} else if (role == StatusMessageRole) {
1527-
return _users[index.row()]->statusMessage();
1528-
} else if (role == DesktopNotificationsAllowedRole) {
1529-
return _users[index.row()]->isDesktopNotificationsAllowed();
1530-
} else if (role == AvatarRole) {
1531-
return _users[index.row()]->avatarUrl();
1532-
} else if (role == IsCurrentUserRole) {
1533-
return _users[index.row()]->isCurrentUser();
1534-
} else if (role == IsConnectedRole) {
1535-
return _users[index.row()]->isConnected();
1536-
} else if (role == IdRole) {
1537-
return index.row();
1538-
}
1539-
return QVariant();
1532+
auto result = QVariant{};
1533+
switch (role)
1534+
{
1535+
case NameRole:
1536+
result = _users[index.row()]->name();
1537+
break;
1538+
case ServerRole:
1539+
result = _users[index.row()]->server();
1540+
break;
1541+
case ServerHasUserStatusRole:
1542+
result = _users[index.row()]->serverHasUserStatus();
1543+
break;
1544+
case StatusIconRole:
1545+
result = _users[index.row()]->statusIcon();
1546+
break;
1547+
case StatusEmojiRole:
1548+
result = _users[index.row()]->statusEmoji();
1549+
break;
1550+
case StatusMessageRole:
1551+
result = _users[index.row()]->statusMessage();
1552+
break;
1553+
case DesktopNotificationsAllowedRole:
1554+
result = _users[index.row()]->isDesktopNotificationsAllowed();
1555+
break;
1556+
case AvatarRole:
1557+
result = _users[index.row()]->avatarUrl();
1558+
break;
1559+
case IsCurrentUserRole:
1560+
result = _users[index.row()]->isCurrentUser();
1561+
break;
1562+
case IsConnectedRole:
1563+
result = _users[index.row()]->isConnected();
1564+
break;
1565+
case IdRole:
1566+
result = index.row();
1567+
break;
1568+
case CanLogoutRole:
1569+
result = _users[index.row()]->canLogout();
1570+
break;
1571+
case RemoveAccountTextRole:
1572+
result = _users[index.row()]->isPublicShareLink() ? tr("Leave share") : tr("Remove account");
1573+
break;
1574+
}
1575+
1576+
return result;
15401577
}
15411578

15421579
QHash<int, QByteArray> UserModel::roleNames() const
@@ -1545,6 +1582,8 @@ QHash<int, QByteArray> UserModel::roleNames() const
15451582
roles[NameRole] = "name";
15461583
roles[ServerRole] = "server";
15471584
roles[ServerHasUserStatusRole] = "serverHasUserStatus";
1585+
roles[CanLogoutRole] = "canLogout";
1586+
roles[RemoveAccountTextRole] = "removeAccountText";
15481587
roles[StatusIconRole] = "statusIcon";
15491588
roles[StatusEmojiRole] = "statusEmoji";
15501589
roles[StatusMessageRole] = "statusMessage";

src/gui/tray/usermodel.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class User : public QObject
6363
Q_PROPERTY(bool isConnected READ isConnected NOTIFY accountStateChanged)
6464
Q_PROPERTY(UnifiedSearchResultsListModel* unifiedSearchResultsListModel READ getUnifiedSearchResultsListModel CONSTANT)
6565
Q_PROPERTY(QVariantList groupFolders READ groupFolders NOTIFY groupFoldersChanged)
66+
Q_PROPERTY(bool canLogout READ canLogout CONSTANT)
6667

6768
public:
6869
User(AccountStatePtr &account, const bool &isCurrent = false, QObject *parent = nullptr);
@@ -104,6 +105,8 @@ class User : public QObject
104105
[[nodiscard]] QString statusEmoji() const;
105106
void processCompletedSyncItem(const Folder *folder, const SyncFileItemPtr &item);
106107
[[nodiscard]] const QVariantList &groupFolders() const;
108+
[[nodiscard]] bool canLogout() const;
109+
[[nodiscard]] bool isPublicShareLink() const;
107110

108111
signals:
109112
void nameChanged();
@@ -236,14 +239,16 @@ class UserModel : public QAbstractListModel
236239
NameRole = Qt::UserRole + 1,
237240
ServerRole,
238241
ServerHasUserStatusRole,
242+
CanLogoutRole,
243+
RemoveAccountTextRole,
239244
StatusIconRole,
240245
StatusEmojiRole,
241246
StatusMessageRole,
242247
DesktopNotificationsAllowedRole,
243248
AvatarRole,
244249
IsCurrentUserRole,
245250
IsConnectedRole,
246-
IdRole
251+
IdRole,
247252
};
248253

249254
[[nodiscard]] AccountAppList appList() const;

src/gui/userinfo.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void UserInfo::slotRequestFailed()
7676

7777
bool UserInfo::canGetInfo() const
7878
{
79-
if (!_accountState || !_active) {
79+
if (!_accountState || !_active || !_accountState->account() || _accountState->account()->isPublicShareLink()) {
8080
return false;
8181
}
8282
AccountPtr account = _accountState->account();
@@ -140,7 +140,7 @@ void UserInfo::slotUpdateLastInfo(const QJsonDocument &json)
140140
_jobRestartTimer.start(defaultIntervalT);
141141
_lastInfoReceived = QDateTime::currentDateTime();
142142

143-
if(_fetchAvatarImage) {
143+
if(_fetchAvatarImage && !account->isPublicShareLink()) {
144144
auto *job = new AvatarJob(account, account->davUser(), 128, this);
145145
job->setTimeout(20 * 1000);
146146
QObject::connect(job, &AvatarJob::avatarPixmap, this, &UserInfo::slotAvatarImage);

src/gui/wizard/owncloudadvancedsetuppage.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ void OwncloudAdvancedSetupPage::fetchUserAvatar()
226226
if (Theme::isHidpi()) {
227227
avatarSize *= 2;
228228
}
229+
230+
if (account->isPublicShareLink()) {
231+
return;
232+
}
233+
229234
const auto avatarJob = new AvatarJob(account, account->davUser(), avatarSize, this);
230235
avatarJob->setTimeout(20 * 1000);
231236
QObject::connect(avatarJob, &AvatarJob::avatarPixmap, this, [this](const QImage &avatarImage) {

src/gui/wizard/owncloudhttpcredspage.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,15 @@ void OwncloudHttpCredsPage::initializePage()
104104
const QString user = url.userName();
105105
const QString password = url.password();
106106

107+
_ui.leUsername->setText(user);
108+
_ui.lePassword->setText(password);
109+
107110
if (!user.isEmpty()) {
108-
_ui.leUsername->setText(user);
109-
}
110-
if (!password.isEmpty()) {
111-
_ui.lePassword->setText(password);
111+
_ui.errorLabel->setVisible(false);
112+
startSpinner();
113+
114+
emit completeChanged();
115+
emit connectToOCUrl(field("OCUrl").toString().simplified());
112116
}
113117
}
114118
_ui.tokenLabel->setText(HttpCredentialsGui::requestAppPasswordText(ocWizard->account().data()));
@@ -124,7 +128,7 @@ void OwncloudHttpCredsPage::cleanupPage()
124128

125129
bool OwncloudHttpCredsPage::validatePage()
126130
{
127-
if (_ui.leUsername->text().isEmpty() || _ui.lePassword->text().isEmpty()) {
131+
if (_ui.leUsername->text().isEmpty()) {
128132
return false;
129133
}
130134

src/libsync/account.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ QString Account::davPath() const
104104

105105
QString Account::davPathRoot() const
106106
{
107-
return davPathBase() + QLatin1Char('/') + davUser();
107+
if (_isPublicLink) {
108+
return QStringLiteral("/public.php/webdav");
109+
} else {
110+
return davPathBase() + QLatin1Char('/') + davUser();
111+
}
108112
}
109113

110114
void Account::setSharedThis(AccountPtr sharedThis)
@@ -526,10 +530,26 @@ void Account::setSslErrorHandler(AbstractSslErrorHandler *handler)
526530

527531
void Account::setUrl(const QUrl &url)
528532
{
529-
_url = url;
533+
const QRegularExpression discoverPublicLinks(R"((http.://[^/]*).*/s/([^/]*))");
534+
const auto isPublicLink = discoverPublicLinks.match(url.toString());
535+
if (isPublicLink.hasMatch()) {
536+
_url = QUrl::fromUserInput(isPublicLink.captured(1));
537+
_url.setUserName(isPublicLink.captured(2));
538+
setDavUser(isPublicLink.captured(2));
539+
_isPublicLink = true;
540+
_publicShareLinkUrl = url;
541+
} else {
542+
_url = url;
543+
}
544+
530545
_userVisibleUrl = url;
531546
}
532547

548+
QUrl Account::publicShareLinkUrl() const
549+
{
550+
return _publicShareLinkUrl;
551+
}
552+
533553
void Account::setUserVisibleHost(const QString &host)
534554
{
535555
_userVisibleUrl.setHost(host);

src/libsync/account.h

+8
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject
165165
/** Server url of the account */
166166
void setUrl(const QUrl &url);
167167
[[nodiscard]] QUrl url() const { return _url; }
168+
[[nodiscard]] QUrl publicShareLinkUrl() const;
169+
170+
[[nodiscard]] bool isPublicShareLink() const
171+
{
172+
return _isPublicLink;
173+
}
168174

169175
/// Adjusts _userVisibleUrl once the host to use is discovered.
170176
void setUserVisibleHost(const QString &host);
@@ -501,6 +507,8 @@ private slots:
501507
#endif
502508
QMap<QString, QVariant> _settingsMap;
503509
QUrl _url;
510+
QUrl _publicShareLinkUrl;
511+
bool _isPublicLink = false;
504512

505513
/** If url to use for any user-visible urls.
506514
*

0 commit comments

Comments
 (0)