Skip to content

Commit

Permalink
Only make SecureFileDrop link creation available if server version is…
Browse files Browse the repository at this point in the history
… 26+.

Signed-off-by: alex-z <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Jan 26, 2023
1 parent 34c0b4e commit ca563db
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
4 changes: 4 additions & 0 deletions VERSION.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ set(NEXTCLOUD_SERVER_VERSION_MIN_SUPPORTED_MAJOR 16)
set(NEXTCLOUD_SERVER_VERSION_MIN_SUPPORTED_MINOR 0)
set(NEXTCLOUD_SERVER_VERSION_MIN_SUPPORTED_PATCH 0)

set(NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_MAJOR 26)
set(NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_MINOR 0)
set(NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_PATCH 0)

if ( NOT DEFINED MIRALL_VERSION_SUFFIX )
set( MIRALL_VERSION_SUFFIX "git") #e.g. beta1, beta2, rc1
endif( NOT DEFINED MIRALL_VERSION_SUFFIX )
Expand Down
12 changes: 6 additions & 6 deletions src/gui/filedetails/sharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ QVariant ShareModel::data(const QModelIndex &index, const int role) const
case EnforcedMaximumExpireDateRole:
return enforcedMaxExpireDateForShare(share);
case IsSecureFileDropLinkRole:
return _isEncryptedRootFolder && share->getPermissions().testFlag(OCC::SharePermission::SharePermissionCreate);
return _isSecureFileDropSupportedFolder && share->getPermissions().testFlag(OCC::SharePermission::SharePermissionCreate);
case PasswordProtectEnabledRole:
return share->isPasswordSet();
case PasswordRole:
Expand Down Expand Up @@ -258,7 +258,7 @@ void ShareModel::updateData()
_numericFileId = fileRecord.numericFileId();

_isEncryptedItem = fileRecord._isE2eEncrypted;
_isEncryptedRootFolder = fileRecord._isE2eEncrypted && fileRecord.e2eMangledName().isEmpty();
_isSecureFileDropSupportedFolder = fileRecord._isE2eEncrypted && fileRecord.e2eMangledName().isEmpty() && _accountState->account()->secureFileDropSupported();

// Will get added when shares are fetched if no link shares are fetched
_placeholderLinkShare.reset(new Share(_accountState->account(),
Expand Down Expand Up @@ -368,7 +368,7 @@ void ShareModel::handlePlaceholderLinkShare()

void ShareModel::handleSecureFileDropLinkShare()
{
if (!_isEncryptedRootFolder) {
if (!_isSecureFileDropSupportedFolder) {
return;
}
// We want to add the placeholder if there are no link shares and
Expand Down Expand Up @@ -581,7 +581,7 @@ QString ShareModel::displayStringForShare(const SharePtr &share) const
{
if (const auto linkShare = share.objectCast<LinkShare>()) {

const auto isSecureFileDropShare = _isEncryptedRootFolder && linkShare->getPermissions().testFlag(OCC::SharePermission::SharePermissionCreate);
const auto isSecureFileDropShare = _isSecureFileDropSupportedFolder && linkShare->getPermissions().testFlag(OCC::SharePermission::SharePermissionCreate);

const auto displayString = isSecureFileDropShare ? tr("Secure filedrop link") : tr("Share link");

Expand Down Expand Up @@ -943,15 +943,15 @@ void ShareModel::setShareNoteFromQml(const QVariant &share, const QString &note)

void ShareModel::createNewLinkShare() const
{
if (_isEncryptedItem && !_isEncryptedRootFolder) {
if (_isEncryptedItem && !_isSecureFileDropSupportedFolder) {
qCWarning(lcShareModel) << "Attempt to create a link share for non-root encrypted folder or a file.";
return;
}

if (_manager) {
const auto askOptionalPassword = _accountState->account()->capabilities().sharePublicLinkAskOptionalPassword();
const auto password = askOptionalPassword ? createRandomPassword() : QString();
if (_isEncryptedRootFolder) {
if (_isSecureFileDropSupportedFolder) {
_manager->createSecureFileDropShare(_sharePath, {}, password);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/filedetails/sharemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private slots:
SharePermissions _maxSharingPermissions;
QByteArray _numericFileId;
bool _isEncryptedItem = false;
bool _isEncryptedRootFolder = false;
bool _isSecureFileDropSupportedFolder = false;
SyncJournalFileLockInfo _filelockState;
QString _privateLinkUrl;

Expand Down
15 changes: 8 additions & 7 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,13 +736,13 @@ class GetOrCreatePublicLinkShare : public QObject
{
Q_OBJECT
public:
GetOrCreatePublicLinkShare(const AccountPtr &account, const QString &localFile, const bool isE2eEncryptedFolder,
GetOrCreatePublicLinkShare(const AccountPtr &account, const QString &localFile, const bool isSecureFileDropOnlyFolder,
QObject *parent)
: QObject(parent)
, _account(account)
, _shareManager(account)
, _localFile(localFile)
, _isE2eEncryptedFolder(isE2eEncryptedFolder)
, _isSecureFileDropOnlyFolder(isSecureFileDropOnlyFolder)
{
connect(&_shareManager, &ShareManager::sharesFetched,
this, &GetOrCreatePublicLinkShare::sharesFetched);
Expand Down Expand Up @@ -779,7 +779,7 @@ private slots:

// otherwise create a new one
qCDebug(lcPublicLink) << "Creating new share";
if (_isE2eEncryptedFolder) {
if (_isSecureFileDropOnlyFolder) {
_shareManager.createSecureFileDropShare(_localFile, shareName, QString());
} else {
_shareManager.createLinkShare(_localFile, shareName, QString());
Expand Down Expand Up @@ -844,7 +844,7 @@ private slots:
AccountPtr _account;
ShareManager _shareManager;
QString _localFile;
bool _isE2eEncryptedFolder = false;
bool _isSecureFileDropOnlyFolder = false;
};

#else
Expand Down Expand Up @@ -1150,7 +1150,8 @@ void SocketApi::sendSharingContextMenuOptions(const FileData &fileData, SocketLi
{
const auto record = fileData.journalRecord();
const auto isOnTheServer = record.isValid();
const auto flagString = isOnTheServer && (!isForE2eeItem || isForRootE2eeFolder) ? QLatin1String("::") : QLatin1String(":d:");
const auto isSecureFileDropSupported = isForRootE2eeFolder && fileData.folder->accountState()->account()->secureFileDropSupported();
const auto flagString = isOnTheServer && (!isForE2eeItem || isSecureFileDropSupported) ? QLatin1String("::") : QLatin1String(":d:");

auto capabilities = fileData.folder->accountState()->account()->capabilities();
auto theme = Theme::instance();
Expand Down Expand Up @@ -1178,13 +1179,13 @@ void SocketApi::sendSharingContextMenuOptions(const FileData &fileData, SocketLi
&& !capabilities.sharePublicLinkEnforcePassword();

if (canCreateDefaultPublicLink) {
if (isForRootE2eeFolder) {
if (isSecureFileDropSupported) {
listener->sendMessage(QLatin1String("MENU_ITEM:COPY_SECUREFILEDROP_LINK") + QLatin1String("::") + tr("Copy secure filedrop link"));
} else {
listener->sendMessage(QLatin1String("MENU_ITEM:COPY_PUBLIC_LINK") + flagString + tr("Copy public link"));
}
} else if (publicLinksEnabled) {
if (isForRootE2eeFolder) {
if (isSecureFileDropSupported) {
listener->sendMessage(QLatin1String("MENU_ITEM:MANAGE_PUBLIC_LINKS") + QLatin1String("::") + tr("Copy secure filedrop link"));
} else {
listener->sendMessage(QLatin1String("MENU_ITEM:MANAGE_PUBLIC_LINKS") + flagString + tr("Copy public link"));
Expand Down
11 changes: 11 additions & 0 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,17 @@ bool Account::serverVersionUnsupported() const
NEXTCLOUD_SERVER_VERSION_MIN_SUPPORTED_MINOR, NEXTCLOUD_SERVER_VERSION_MIN_SUPPORTED_PATCH);
}

bool Account::secureFileDropSupported() const
{
if (serverVersionInt() == 0) {
// not detected yet, assume it is fine.
return true;
}
return serverVersionInt() >= makeServerVersion(NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_MAJOR,
NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_MINOR,
NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_PATCH);
}

bool Account::isUsernamePrefillSupported() const
{
return serverVersionInt() >= makeServerVersion(usernamePrefillServerVersionMinSupportedMajor, 0, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject
*/
[[nodiscard]] bool serverVersionUnsupported() const;

[[nodiscard]] bool secureFileDropSupported() const;

[[nodiscard]] bool isUsernamePrefillSupported() const;

[[nodiscard]] bool isChecksumRecalculateRequestSupported() const;
Expand Down
4 changes: 4 additions & 0 deletions version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ constexpr int NEXTCLOUD_SERVER_VERSION_MIN_SUPPORTED_MAJOR = @NEXTCLOUD_SERVER_V
constexpr int NEXTCLOUD_SERVER_VERSION_MIN_SUPPORTED_MINOR = @NEXTCLOUD_SERVER_VERSION_MIN_SUPPORTED_MINOR@;
constexpr int NEXTCLOUD_SERVER_VERSION_MIN_SUPPORTED_PATCH = @NEXTCLOUD_SERVER_VERSION_MIN_SUPPORTED_PATCH@;

constexpr int NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_MAJOR = @NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_MAJOR@;
constexpr int NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_MINOR = @NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_MINOR@;
constexpr int NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_PATCH = @NEXTCLOUD_SERVER_VERSION_SECURE_FILEDROP_MIN_SUPPORTED_PATCH@;

#endif // VERSION_H

0 comments on commit ca563db

Please sign in to comment.