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);
}
connect(FolderMan::instance()->socketApi(), SIGNAL(shareCommandReceived(QString, QString)),
_gui, SLOT(slotShowShareDialog(QString, QString)));
connect(FolderMan::instance()->socketApi(), SIGNAL(shareCommandReceived(QString, QString, bool)),
_gui, SLOT(slotShowShareDialog(QString, QString, bool)));
// startup procedure.
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();
if (!account) {
@ -651,7 +651,7 @@ void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &l
}
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->setAttribute( Qt::WA_DeleteOnClose, true );
raiseDialog(w);

View file

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

View file

@ -33,14 +33,15 @@ namespace {
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),
_ui(new Ui::ShareDialog),
_account(account),
_sharePath(sharePath),
_localPath(localPath),
_passwordJobRunning(false),
_public_share_id(0)
_public_share_id(0),
_resharingAllowed(resharingAllowed)
{
setAttribute(Qt::WA_DeleteOnClose);
_ui->setupUi(this);
@ -310,10 +311,16 @@ void ShareDialog::slotSharesFetched(const QString &reply)
if( _shares.count()>0 ) {
setShareCheckBoxTitle(true);
} else {
// check the checkbox to create a link.
// If there are no shares yet, check the checkbox to create a link automatically.
// If its clear that resharing is not allowed, display an error
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();
}
}
}
void ShareDialog::setShareLink( const QString& url )
@ -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->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 )
{
_ui->label_sharePath->setText(msg);
}
#if 0
/*
* 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

View file

@ -57,7 +57,8 @@ class ShareDialog : public QDialog
Q_OBJECT
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();
void getShares();
@ -77,7 +78,7 @@ private slots:
private:
void setShareCheckBoxTitle(bool haveShares);
void displayError(int code);
void displayInfo( const QString& msg );
void displayError(const QString& errMsg);
void setShareLink( const QString& url );
Ui::ShareDialog *_ui;
@ -102,6 +103,7 @@ private:
QProgressIndicator *_pi_password;
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.
sendMessage(socket, message);
} 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);
sendMessage(socket, message);
const QString folderForPath = shareFolder->path();
const QString remotePath = shareFolder->remotePath() + localFile.right(localFile.count()-folderForPath.count()+1);
emit shareCommandReceived(remotePath, localFile);
emit shareCommandReceived(remotePath, localFile, allowReshare);
}
}

View file

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