Skip to content

Commit 4ac2a06

Browse files
authored
Merge pull request #4175 from nextcloud/feature/publicLinks
Feature/public links
2 parents 5f369e7 + 6c14f29 commit 4ac2a06

File tree

12 files changed

+197
-69
lines changed

12 files changed

+197
-69
lines changed

src/gui/accountmanager.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,11 @@ void AccountManager::saveAccountHelper(const AccountPtr &account, QSettings &set
368368
{
369369
qCDebug(lcAccountManager) << "Saving settings to" << settings.fileName();
370370
settings.setValue(QLatin1String(versionC), maxAccountVersion);
371-
settings.setValue(QLatin1String(urlC), account->_url.toString());
371+
if (account->isPublicShareLink()) {
372+
settings.setValue(QLatin1String(urlC), account->publicShareLinkUrl().toString());
373+
} else {
374+
settings.setValue(QLatin1String(urlC), account->_url.toString());
375+
}
372376
settings.setValue(QLatin1String(davUserC), account->_davUser);
373377
settings.setValue(QLatin1String(displayNameC), account->davDisplayName());
374378
settings.setValue(QLatin1String(serverVersionC), account->_serverVersion);

src/gui/connectionvalidator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@ void ConnectionValidator::slotCapabilitiesRecieved(const QJsonDocument &json)
272272
_account->fetchDirectEditors(directEditingURL, directEditingETag);
273273

274274
checkServerTermsOfService();
275+
276+
if (_account->isPublicShareLink()) {
277+
slotUserFetched(nullptr);
278+
return;
279+
}
280+
281+
fetchUser();
275282
}
276283

277284
void ConnectionValidator::fetchUser()

src/gui/owncloudsetupwizard.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "sslerrordialog.h"
2020
#include "wizard/owncloudwizard.h"
2121
#include "wizard/owncloudwizardcommon.h"
22+
#include "account.h"
2223

2324
#include "creds/credentialsfactory.h"
2425
#include "creds/abstractcredentials.h"
@@ -300,7 +301,11 @@ void OwncloudSetupWizard::slotFoundServer(const QUrl &url, const QJsonObject &in
300301
qCInfo(lcWizard) << " was redirected to" << url.toString();
301302
}
302303

303-
slotDetermineAuthType();
304+
if (_ocWizard->account()->isPublicShareLink()) {
305+
_ocWizard->setAuthType(DetermineAuthTypeJob::Basic);
306+
} else {
307+
slotDetermineAuthType();
308+
}
304309
}
305310

306311
void OwncloudSetupWizard::slotNoServerFound(QNetworkReply *reply)
@@ -352,6 +357,19 @@ void OwncloudSetupWizard::slotConnectToOCUrl(const QString &url)
352357
creds->persist();
353358
}
354359

360+
if (_ocWizard->account()->isPublicShareLink()) {
361+
_ocWizard->account()->setDavUser(creds->user());
362+
_ocWizard->account()->setDavDisplayName(creds->user());
363+
364+
_ocWizard->setField(QLatin1String("OCUrl"), url);
365+
_ocWizard->appendToConfigurationLog(tr("Trying to connect to %1 at %2 …")
366+
.arg(Theme::instance()->appNameGUI())
367+
.arg(url));
368+
369+
testOwnCloudConnect();
370+
return;
371+
}
372+
355373
const auto fetchUserNameJob = new JsonApiJob(_ocWizard->account()->sharedFromThis(), QStringLiteral("/ocs/v1.php/cloud/user"));
356374
connect(fetchUserNameJob, &JsonApiJob::jsonReceived, this, [this, url](const QJsonDocument &json, int statusCode) {
357375
if (statusCode != 100) {
@@ -786,7 +804,13 @@ AccountState *OwncloudSetupWizard::applyAccountChanges()
786804
auto manager = AccountManager::instance();
787805

788806
auto newState = manager->addAccount(newAccount);
807+
808+
if (newAccount->isPublicShareLink()) {
809+
qCInfo(lcWizard()) << "seeting up public share link account";
810+
}
811+
789812
manager->saveAccount(newAccount);
813+
790814
return newState;
791815
}
792816

src/gui/tray/UserLine.qml

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import com.nextcloud.desktopclient
1515
AbstractButton {
1616
id: userLine
1717

18-
signal showUserStatusSelector(int id)
19-
signal showUserStatusMessageSelector(int id)
18+
signal showUserStatusSelector(int id)
19+
signal showUserStatusMessageSelector(int id)
2020

2121

2222
Accessible.role: Accessible.MenuItem
@@ -133,26 +133,31 @@ AbstractButton {
133133
id: userMoreButtonMenu
134134
closePolicy: Menu.CloseOnPressOutsideParent | Menu.CloseOnEscape
135135

136-
MenuItem {
137-
visible: model.isConnected && model.serverHasUserStatus
138-
height: visible ? implicitHeight : 0
139-
text: qsTr("Set status")
140-
font.pixelSize: Style.topLinePixelSize
141-
hoverEnabled: true
142-
onClicked: showUserStatusSelector(index)
143-
}
144-
145-
MenuItem {
146-
visible: model.isConnected && model.serverHasUserStatus
147-
height: visible ? implicitHeight : 0
148-
text: qsTr("Status message")
149-
font.pixelSize: Style.topLinePixelSize
150-
hoverEnabled: true
151-
onClicked: showUserStatusMessageSelector(index)
152-
}
153-
154-
MenuItem {
155-
text: model.isConnected ? qsTr("Log out") : qsTr("Log in")
136+
<<<<<<< HEAD
137+
MenuItem {
138+
visible: model.isConnected && model.serverHasUserStatus
139+
height: visible ? implicitHeight : 0
140+
text: qsTr("Set status")
141+
font.pixelSize: Style.topLinePixelSize
142+
hoverEnabled: true
143+
onClicked: showUserStatusSelector(index)
144+
}
145+
146+
MenuItem {
147+
visible: model.isConnected && model.serverHasUserStatus
148+
height: visible ? implicitHeight : 0
149+
text: qsTr("Status message")
150+
font.pixelSize: Style.topLinePixelSize
151+
hoverEnabled: true
152+
onClicked: showUserStatusMessageSelector(index)
153+
}
154+
155+
MenuItem {
156+
text: model.isConnected ? qsTr("Log out") : qsTr("Log in")
157+
visible: model.canLogout
158+
height: visible ? implicitHeight : 0
159+
width: parent.width
160+
text: model.isConnected ? qsTr("Log out") : qsTr("Log in")
156161
font.pixelSize: Style.topLinePixelSize
157162
hoverEnabled: true
158163
onClicked: {
@@ -175,7 +180,7 @@ AbstractButton {
175180

176181
MenuItem {
177182
id: removeAccountButton
178-
text: qsTr("Remove account")
183+
text: model.removeAccountText
179184
font.pixelSize: Style.topLinePixelSize
180185
hoverEnabled: true
181186
onClicked: {

src/gui/tray/usermodel.cpp

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,16 @@ const QVariantList &User::groupFolders() const
900900
return _trayFolderInfos;
901901
}
902902

903+
bool User::canLogout() const
904+
{
905+
return !isPublicShareLink();
906+
}
907+
908+
bool User::isPublicShareLink() const
909+
{
910+
return _account->account()->isPublicShareLink();
911+
}
912+
903913
void User::slotItemCompleted(const QString &folder, const SyncFileItemPtr &item)
904914
{
905915
auto folderInstance = FolderMan::instance()->folder(folder);
@@ -1004,17 +1014,27 @@ void User::logout() const
10041014

10051015
QString User::name() const
10061016
{
1017+
if (isPublicShareLink()) {
1018+
return tr("Public Share Link");
1019+
}
1020+
10071021
return _account->account()->prettyName();
10081022
}
10091023

10101024
QString User::server(bool shortened) const
10111025
{
1012-
QString serverUrl = _account->account()->url().toString();
1026+
auto serverUrl = _account->account()->url();
1027+
1028+
if (isPublicShareLink()) {
1029+
serverUrl.setUserName({});
1030+
}
1031+
QString stringServerUrl = serverUrl.toString();
10131032
if (shortened) {
1014-
serverUrl.replace(QLatin1String("https://"), QLatin1String(""));
1015-
serverUrl.replace(QLatin1String("http://"), QLatin1String(""));
1033+
stringServerUrl.replace(QLatin1String("https://"), QLatin1String(""));
1034+
stringServerUrl.replace(QLatin1String("http://"), QLatin1String(""));
1035+
10161036
}
1017-
return serverUrl;
1037+
return stringServerUrl;
10181038
}
10191039

10201040
UserStatus::OnlineStatus User::status() const
@@ -1579,36 +1599,54 @@ int UserModel::rowCount(const QModelIndex &parent) const
15791599

15801600
QVariant UserModel::data(const QModelIndex &index, int role) const
15811601
{
1582-
if (index.row() < 0 || index.row() >= _users.count()) {
1583-
return QVariant();
1584-
}
1585-
1586-
if (role == NameRole) {
1587-
return _users[index.row()]->name();
1588-
} else if (role == ServerRole) {
1589-
return _users[index.row()]->server();
1590-
} else if (role == ServerHasUserStatusRole) {
1591-
return _users[index.row()]->serverHasUserStatus();
1592-
} else if (role == StatusRole) {
1593-
return QVariant::fromValue(_users[index.row()]->status());
1594-
} else if (role == StatusIconRole) {
1595-
return _users[index.row()]->statusIcon();
1596-
} else if (role == StatusEmojiRole) {
1597-
return _users[index.row()]->statusEmoji();
1598-
} else if (role == StatusMessageRole) {
1599-
return _users[index.row()]->statusMessage();
1600-
} else if (role == DesktopNotificationsAllowedRole) {
1601-
return _users[index.row()]->isDesktopNotificationsAllowed();
1602-
} else if (role == AvatarRole) {
1603-
return _users[index.row()]->avatarUrl();
1604-
} else if (role == IsCurrentUserRole) {
1605-
return _users[index.row()]->isCurrentUser();
1606-
} else if (role == IsConnectedRole) {
1607-
return _users[index.row()]->isConnected();
1608-
} else if (role == IdRole) {
1609-
return index.row();
1610-
}
1611-
return QVariant();
1602+
auto result = QVariant{};
1603+
switch (static_cast<UserRoles>(role))
1604+
{
1605+
case NameRole:
1606+
result = _users[index.row()]->name();
1607+
break;
1608+
case ServerRole:
1609+
result = _users[index.row()]->server();
1610+
break;
1611+
case ServerHasUserStatusRole:
1612+
result = _users[index.row()]->serverHasUserStatus();
1613+
break;
1614+
case StatusRole:
1615+
result = QVariant::fromValue(_users[index.row()]->status());
1616+
break;
1617+
case StatusIconRole:
1618+
result = _users[index.row()]->statusIcon();
1619+
break;
1620+
case StatusEmojiRole:
1621+
result = _users[index.row()]->statusEmoji();
1622+
break;
1623+
case StatusMessageRole:
1624+
result = _users[index.row()]->statusMessage();
1625+
break;
1626+
case DesktopNotificationsAllowedRole:
1627+
result = _users[index.row()]->isDesktopNotificationsAllowed();
1628+
break;
1629+
case AvatarRole:
1630+
result = _users[index.row()]->avatarUrl();
1631+
break;
1632+
case IsCurrentUserRole:
1633+
result = _users[index.row()]->isCurrentUser();
1634+
break;
1635+
case IsConnectedRole:
1636+
result = _users[index.row()]->isConnected();
1637+
break;
1638+
case IdRole:
1639+
result = index.row();
1640+
break;
1641+
case CanLogoutRole:
1642+
result = _users[index.row()]->canLogout();
1643+
break;
1644+
case RemoveAccountTextRole:
1645+
result = _users[index.row()]->isPublicShareLink() ? tr("Leave share") : tr("Remove account");
1646+
break;
1647+
}
1648+
1649+
return result;
16121650
}
16131651

16141652
QHash<int, QByteArray> UserModel::roleNames() const
@@ -1626,6 +1664,8 @@ QHash<int, QByteArray> UserModel::roleNames() const
16261664
roles[IsCurrentUserRole] = "isCurrentUser";
16271665
roles[IsConnectedRole] = "isConnected";
16281666
roles[IdRole] = "id";
1667+
roles[CanLogoutRole] = "canLogout";
1668+
roles[RemoveAccountTextRole] = "removeAccountText";
16291669
return roles;
16301670
}
16311671

src/gui/tray/usermodel.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class User : public QObject
7171
Q_PROPERTY(bool needsToSignTermsOfService READ needsToSignTermsOfService NOTIFY accountStateChanged)
7272
Q_PROPERTY(UnifiedSearchResultsListModel* unifiedSearchResultsListModel READ getUnifiedSearchResultsListModel CONSTANT)
7373
Q_PROPERTY(QVariantList groupFolders READ groupFolders NOTIFY groupFoldersChanged)
74+
Q_PROPERTY(bool canLogout READ canLogout CONSTANT)
7475

7576
public:
7677
User(AccountStatePtr &account, const bool &isCurrent = false, QObject *parent = nullptr);
@@ -113,6 +114,8 @@ class User : public QObject
113114
[[nodiscard]] QString statusEmoji() const;
114115
void processCompletedSyncItem(const Folder *folder, const SyncFileItemPtr &item);
115116
[[nodiscard]] const QVariantList &groupFolders() const;
117+
[[nodiscard]] bool canLogout() const;
118+
[[nodiscard]] bool isPublicShareLink() const;
116119

117120
signals:
118121
void nameChanged();
@@ -256,7 +259,9 @@ class UserModel : public QAbstractListModel
256259
AvatarRole,
257260
IsCurrentUserRole,
258261
IsConnectedRole,
259-
IdRole
262+
IdRole,
263+
CanLogoutRole,
264+
RemoveAccountTextRole,
260265
};
261266

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

src/gui/userinfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void UserInfo::slotRequestFailed()
6666

6767
bool UserInfo::canGetInfo() const
6868
{
69-
if (!_accountState || !_active) {
69+
if (!_accountState || !_active || !_accountState->account() || _accountState->account()->isPublicShareLink()) {
7070
return false;
7171
}
7272
AccountPtr account = _accountState->account();
@@ -130,7 +130,7 @@ void UserInfo::slotUpdateLastInfo(const QJsonDocument &json)
130130
_jobRestartTimer.start(defaultIntervalT);
131131
_lastInfoReceived = QDateTime::currentDateTime();
132132

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

src/gui/wizard/owncloudadvancedsetuppage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ void OwncloudAdvancedSetupPage::fetchUserAvatar()
240240
if (Theme::isHidpi()) {
241241
avatarSize *= 2;
242242
}
243+
244+
if (account->isPublicShareLink()) {
245+
return;
246+
}
247+
243248
const auto avatarJob = new AvatarJob(account, account->davUser(), avatarSize, this);
244249
avatarJob->setTimeout(20 * 1000);
245250
QObject::connect(avatarJob, &AvatarJob::avatarPixmap, this, [this](const QImage &avatarImage) {

src/gui/wizard/owncloudhttpcredspage.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ void OwncloudHttpCredsPage::initializePage()
9595
const QString user = url.userName();
9696
const QString password = url.password();
9797

98+
_ui.leUsername->setText(user);
99+
_ui.lePassword->setText(password);
100+
98101
if (!user.isEmpty()) {
99-
_ui.leUsername->setText(user);
100-
}
101-
if (!password.isEmpty()) {
102-
_ui.lePassword->setText(password);
102+
_ui.errorLabel->setVisible(false);
103+
startSpinner();
104+
105+
emit completeChanged();
106+
emit connectToOCUrl(field("OCUrl").toString().simplified());
103107
}
104108
}
105109
_ui.tokenLabel->setText(HttpCredentialsGui::requestAppPasswordText(ocWizard->account().data()));
@@ -115,7 +119,7 @@ void OwncloudHttpCredsPage::cleanupPage()
115119

116120
bool OwncloudHttpCredsPage::validatePage()
117121
{
118-
if (_ui.leUsername->text().isEmpty() || _ui.lePassword->text().isEmpty()) {
122+
if (_ui.leUsername->text().isEmpty()) {
119123
return false;
120124
}
121125

0 commit comments

Comments
 (0)