ShareDialog: Consider if resharing is not allowed on a share.

If a file or directory is shared without resharing permission, the
share dialog displays an error. This is not the optimal solution, but
best for now, as we do not have the permissions available for the file
manager plugin.

This fixes #2923
This commit is contained in:
Klaas Freitag 2015-03-11 14:09:31 +01:00
parent 9086f09fe2
commit 8cc5ff0e70
7 changed files with 43 additions and 19 deletions

View file

@ -149,8 +149,8 @@ Application::Application(int &argc, char **argv) :
slotAccountStateAdded(ai); slotAccountStateAdded(ai);
} }
connect(FolderMan::instance()->socketApi(), SIGNAL(shareCommandReceived(QString, QString)), connect(FolderMan::instance()->socketApi(), SIGNAL(shareCommandReceived(QString, QString, bool)),
_gui, SLOT(slotShowShareDialog(QString, QString))); _gui, SLOT(slotShowShareDialog(QString, QString, bool)));
// startup procedure. // startup procedure.
connect(&_checkConnectionTimer, SIGNAL(timeout()), this, SLOT(slotCheckConnection())); connect(&_checkConnectionTimer, SIGNAL(timeout()), this, SLOT(slotCheckConnection()));

View file

@ -642,7 +642,7 @@ void ownCloudGui::raiseDialog( QWidget *raiseWidget )
} }
void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &localPath) void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed)
{ {
AccountPtr account = AccountManager::instance()->account(); AccountPtr account = AccountManager::instance()->account();
if (!account) { if (!account) {
@ -651,7 +651,7 @@ void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &l
} }
qDebug() << Q_FUNC_INFO << "Opening share dialog"; qDebug() << Q_FUNC_INFO << "Opening share dialog";
ShareDialog *w = new ShareDialog(account, sharePath, localPath); ShareDialog *w = new ShareDialog(account, sharePath, localPath, resharingAllowed);
w->getShares(); w->getShares();
w->setAttribute( Qt::WA_DeleteOnClose, true ); w->setAttribute( Qt::WA_DeleteOnClose, true );
raiseDialog(w); raiseDialog(w);

View file

@ -70,7 +70,7 @@ public slots:
void slotHelp(); void slotHelp();
void slotOpenPath(const QString& path); void slotOpenPath(const QString& path);
void slotAccountStateChanged(); void slotAccountStateChanged();
void slotShowShareDialog(const QString &sharePath, const QString &localPath); void slotShowShareDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed);
private slots: private slots:
void slotDisplayIdle(); void slotDisplayIdle();

View file

@ -33,14 +33,15 @@ namespace {
namespace OCC { namespace OCC {
ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath, QWidget *parent) : ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) :
QDialog(parent), QDialog(parent),
_ui(new Ui::ShareDialog), _ui(new Ui::ShareDialog),
_account(account), _account(account),
_sharePath(sharePath), _sharePath(sharePath),
_localPath(localPath), _localPath(localPath),
_passwordJobRunning(false), _passwordJobRunning(false),
_public_share_id(0) _public_share_id(0),
_resharingAllowed(resharingAllowed)
{ {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
_ui->setupUi(this); _ui->setupUi(this);
@ -310,9 +311,15 @@ void ShareDialog::slotSharesFetched(const QString &reply)
if( _shares.count()>0 ) { if( _shares.count()>0 ) {
setShareCheckBoxTitle(true); setShareCheckBoxTitle(true);
} else { } else {
// check the checkbox to create a link. // If there are no shares yet, check the checkbox to create a link automatically.
_ui->checkBox_shareLink->setChecked(true); // If its clear that resharing is not allowed, display an error
slotCheckBoxShareLinkClicked(); if( !_resharingAllowed ) {
displayError(tr("The file can not be shared because it was shared without sharing permission."));
_ui->checkBox_shareLink->setEnabled(false);
} else {
_ui->checkBox_shareLink->setChecked(true);
slotCheckBoxShareLinkClicked();
}
} }
} }
@ -482,19 +489,24 @@ void ShareDialog::setShareCheckBoxTitle(bool haveShares)
} }
void ShareDialog::displayError(int code) void ShareDialog::displayError(const QString& errMsg)
{ {
const QString errMsg = tr("OCS API error code: %1").arg(code);
_ui->errorLabel->setText( errMsg ); _ui->errorLabel->setText( errMsg );
_ui->errorLabel->show(); _ui->errorLabel->show();
} }
void ShareDialog::displayError(int code)
{
const QString errMsg = tr("OCS API error code: %1").arg(code);
displayError(errMsg);
}
#if 0
void ShareDialog::displayInfo( const QString& msg ) void ShareDialog::displayInfo( const QString& msg )
{ {
_ui->label_sharePath->setText(msg); _ui->label_sharePath->setText(msg);
} }
#if 0
/* /*
* This code is disabled for now as we do not have answers for all the questions involved * This code is disabled for now as we do not have answers for all the questions involved
* here, see https://github.com/owncloud/client/issues/2732 * here, see https://github.com/owncloud/client/issues/2732

View file

@ -57,7 +57,8 @@ class ShareDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath, QWidget *parent = 0); explicit ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath,
bool resharingAllowed, QWidget *parent = 0);
~ShareDialog(); ~ShareDialog();
void getShares(); void getShares();
@ -77,7 +78,7 @@ private slots:
private: private:
void setShareCheckBoxTitle(bool haveShares); void setShareCheckBoxTitle(bool haveShares);
void displayError(int code); void displayError(int code);
void displayInfo( const QString& msg ); void displayError(const QString& errMsg);
void setShareLink( const QString& url ); void setShareLink( const QString& url );
Ui::ShareDialog *_ui; Ui::ShareDialog *_ui;
@ -102,6 +103,7 @@ private:
QProgressIndicator *_pi_password; QProgressIndicator *_pi_password;
QProgressIndicator *_pi_date; QProgressIndicator *_pi_date;
bool _resharingAllowed;
}; };
} }

View file

@ -420,12 +420,22 @@ void SocketApi::command_SHARE(const QString& localFile, SocketType* socket)
// files that are not within a sync folder are not synced. // files that are not within a sync folder are not synced.
sendMessage(socket, message); sendMessage(socket, message);
} else { } else {
const QString folderForPath = shareFolder->path();
const QString remotePath = shareFolder->remotePath() + localFile.right(localFile.count()-folderForPath.count()+1);
SyncJournalFileRecord rec = dbFileRecord_capi(shareFolder, localFile);
bool allowReshare = true; // lets assume the good
if( rec.isValid() ) {
// check the permission: Is resharing allowed?
if( !rec._remotePerm.contains('R') ) {
allowReshare = false;
}
}
const QString message = QLatin1String("SHARE:OK:")+QDir::toNativeSeparators(localFile); const QString message = QLatin1String("SHARE:OK:")+QDir::toNativeSeparators(localFile);
sendMessage(socket, message); sendMessage(socket, message);
const QString folderForPath = shareFolder->path(); emit shareCommandReceived(remotePath, localFile, allowReshare);
const QString remotePath = shareFolder->remotePath() + localFile.right(localFile.count()-folderForPath.count()+1);
emit shareCommandReceived(remotePath, localFile);
} }
} }

View file

@ -58,7 +58,7 @@ public slots:
void slotClearExcludesList(); void slotClearExcludesList();
signals: signals:
void shareCommandReceived(const QString &sharePath, const QString &localPath); void shareCommandReceived(const QString &sharePath, const QString &localPath, bool resharingAllowed);
private slots: private slots:
void slotNewConnection(); void slotNewConnection();