ShareDialog: Consider if resharing is not allowed on a share.
authorKlaas Freitag <freitag@owncloud.com>
Wed, 11 Mar 2015 13:09:31 +0000 (14:09 +0100)
committerKlaas Freitag <freitag@owncloud.com>
Wed, 11 Mar 2015 13:12:08 +0000 (14:12 +0100)
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

src/gui/application.cpp
src/gui/owncloudgui.cpp
src/gui/owncloudgui.h
src/gui/sharedialog.cpp
src/gui/sharedialog.h
src/gui/socketapi.cpp
src/gui/socketapi.h

index 26b15c49f27e46b3f47032bb3f4a7fe92084ffcc..734f7f18b89210cdc4a7c315335478c7de1aeaf4 100644 (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()));
index bf777f8803a6eb32899e24bf03413f19904da19a..48ec2b526a91d28339013ceac0e3b18391ea4872 100644 (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);
index 18dccae8711d511fa0d315d3e2c625c0acc1e6af..9dedcc66f3e7ff248074bb4d73c4cd0ceb78fe11 100644 (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();
index 4fce730aeeded543b1d44db7d8261b2ff0685c31..ae4506cc377e2b2bb8d49a39b04f406bd8c043f8 100644 (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,9 +311,15 @@ void ShareDialog::slotSharesFetched(const QString &reply)
     if( _shares.count()>0 ) {
         setShareCheckBoxTitle(true);
     } else {
-        // check the checkbox to create a link.
-        _ui->checkBox_shareLink->setChecked(true);
-        slotCheckBoxShareLinkClicked();
+        // 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();
+        }
     }
 }
 
@@ -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
index 997e17e0d1a12387657a24fe2a72d18023460ce1..2d86fd0888686ee518bb6ac726af4d0ba76eb614 100644 (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;
 };
 
 }
index e9b62d95c039b2e96636026fa5025c2627aa2f43..fa8244f850163000f9d0ae14f3a97daa33932493 100644 (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);
     }
 }
 
index 45fdb8a0040ffa90c159660b99c7514435fab2d7..b6c82d925645a5a31a3d91089290d31184c17542 100644 (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();