Forbid to encrypt or decrypt a non-empty folder.

The specs forbid the encryption or decryption of a
non empty folder. so...
1 - check for the sync status, if it's not synced return

as there's no way that I can say that there's items on the
server right now without waiting for the sync to finish

2 - verify if the folder is empty locally

as the user could have send some files to the folder.
This commit is contained in:
Tomaz Canabrava 2018-05-11 23:22:33 +02:00 committed by Roeland Jago Douma
parent f96206705a
commit 9b74a596c6
No known key found for this signature in database
GPG key ID: F941078878347C0C
2 changed files with 46 additions and 9 deletions

View file

@ -34,6 +34,7 @@
#include "tooltipupdater.h"
#include "filesystem.h"
#include "clientsideencryptionjobs.h"
#include "syncresult.h"
#include <math.h>
@ -335,9 +336,36 @@ void AccountSettings::slotUnlockFolderSuccess(const QByteArray& fileId)
{
qCInfo(lcAccountSettings()) << "Unlocking success!";
}
void AccountSettings::slotMarkSubfolderEncrpted(const QByteArray& fileId)
bool AccountSettings::canEncryptOrDecrypt (const FolderStatusModel::SubFolderInfo* info) {
if (info->_folder->syncResult().status() != SyncResult::Status::Success) {
QMessageBox msgBox;
msgBox.setText("Please wait for the folder to sync before trying to encrypt it.");
msgBox.exec();
return false;
}
// for some reason the actual folder in disk is info->_folder->path + info->_path.
QDir folderPath(info->_folder->path() + info->_path);
folderPath.setFilter( QDir::AllEntries | QDir::NoDotAndDotDot );
if (folderPath.count() != 0) {
QMessageBox msgBox;
msgBox.setText("You cannot encyrpt a folder with contents, please remove the files \n"
"Wait for the new sync, then encrypt it.");
msgBox.exec();
return false;
}
return true;
}
void AccountSettings::slotMarkSubfolderEncrpted(const FolderStatusModel::SubFolderInfo* folderInfo)
{
auto job = new OCC::SetEncryptionFlagApiJob(accountsState()->account(), fileId);
if (!canEncryptOrDecrypt(folderInfo)) {
return;
}
auto job = new OCC::SetEncryptionFlagApiJob(accountsState()->account(), folderInfo->_fileId);
connect(job, &OCC::SetEncryptionFlagApiJob::success, this, &AccountSettings::slotEncryptionFlagSuccess);
connect(job, &OCC::SetEncryptionFlagApiJob::error, this, &AccountSettings::slotEncryptionFlagError);
job->start();
@ -349,11 +377,17 @@ void AccountSettings::slotMarkSubfolderEncrpted(const QByteArray& fileId)
// 2 - Delete Metadata,
// 3 - Unlock Folder,
// 4 - Mark as Decrypted.
void AccountSettings::slotMarkSubfolderDecrypted(const QByteArray& fileId)
void AccountSettings::slotMarkSubfolderDecrypted(const FolderStatusModel::SubFolderInfo* folderInfo)
{
if (!canEncryptOrDecrypt(folderInfo)) {
return;
}
qDebug() << "Starting to mark as decrypted";
qDebug() << "Locking the folder";
auto lockJob = new LockEncryptFolderApiJob(accountsState()->account(), fileId);
auto lockJob = new LockEncryptFolderApiJob(accountsState()->account(), folderInfo->_fileId);
connect(lockJob, &LockEncryptFolderApiJob::success,
this, &AccountSettings::slotLockForDecryptionSuccess);
connect(lockJob, &LockEncryptFolderApiJob::error,
@ -444,13 +478,15 @@ void AccountSettings::slotSubfolderContextMenuRequested(const QModelIndex& index
auto acc = _accountState->account();
if (acc->capabilities().clientSideEncryptionAvaliable()) {
// Verify if the folder is empty before attempting to encrypt.
bool isEncrypted = acc->e2e()->isFolderEncrypted(info->_path);
ac = menu.addAction( isEncrypted ? tr("Decrypt") : tr("Encrypt"));
if (not isEncrypted) {
connect(ac, &QAction::triggered, [this, &info] { slotMarkSubfolderEncrpted(info->_fileId); });
connect(ac, &QAction::triggered, [this, &info] { slotMarkSubfolderEncrpted(info); });
} else {
connect(ac, &QAction::triggered, [this, &info] { slotMarkSubfolderDecrypted(info->_fileId); });
connect(ac, &QAction::triggered, [this, &info] { slotMarkSubfolderDecrypted(info); });
}
}
menu.exec(QCursor::pos());

View file

@ -25,6 +25,7 @@
#include "quotainfo.h"
#include "progressdispatcher.h"
#include "owncloudgui.h"
#include "folderstatusmodel.h"
class QModelIndex;
class QNetworkReply;
@ -55,7 +56,7 @@ public:
explicit AccountSettings(AccountState *accountState, QWidget *parent = 0);
~AccountSettings();
QSize sizeHint() const Q_DECL_OVERRIDE { return ownCloudGui::settingsDialogSize(); }
bool canEncryptOrDecrypt(const FolderStatusModel::SubFolderInfo* folderInfo);
signals:
void folderChanged();
@ -85,8 +86,8 @@ protected slots:
void slotOpenAccountWizard();
void slotAccountAdded(AccountState *);
void refreshSelectiveSyncStatus();
void slotMarkSubfolderEncrpted(const QByteArray& fileId);
void slotMarkSubfolderDecrypted(const QByteArray& fileId);
void slotMarkSubfolderEncrpted(const FolderStatusModel::SubFolderInfo* folderInfo);
void slotMarkSubfolderDecrypted(const FolderStatusModel::SubFolderInfo* folderInfo);
void slotSubfolderContextMenuRequested(const QModelIndex& idx, const QPoint& point);
void slotCustomContextMenuRequested(const QPoint &);
void slotFolderListClicked(const QModelIndex &indx);