[Pkg-owncloud-commits] [owncloud-client] 262/484: [Sharing] Filter sharee list properly

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:50 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 20fd349e174abc530a261b5d6832c138ca7542c4
Author: Roeland Jago Douma <rullzer at owncloud.com>
Date:   Thu Nov 5 12:30:34 2015 +0100

    [Sharing] Filter sharee list properly
    
    You can't share with a user/group that you've already shared with
    You can't share with yourself
---
 src/gui/sharee.cpp               | 25 ++++++++++++++++++++++---
 src/gui/sharee.h                 |  2 ++
 src/gui/shareusergroupwidget.cpp | 11 +++++++++++
 src/gui/shareusergroupwidget.h   |  4 +++-
 4 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/src/gui/sharee.cpp b/src/gui/sharee.cpp
index 0fb98d0..7f29806 100644
--- a/src/gui/sharee.cpp
+++ b/src/gui/sharee.cpp
@@ -56,11 +56,13 @@ Sharee::Type Sharee::type() const
 ShareeModel::ShareeModel(AccountPtr account,
                          const QString search,
                          const QString type,
+                         const QVector<QSharedPointer<Sharee>> &shareeBlacklist,
                          QObject *parent)
 : QAbstractListModel(parent),
   _account(account),
   _search(search),
-  _type(type)
+  _type(type),
+  _shareeBlacklist(shareeBlacklist)
 {
 
 }
@@ -116,8 +118,25 @@ void ShareeModel::shareesFetched(const QVariantMap &reply)
         }
     }
 
-    beginInsertRows(QModelIndex(), _sharees.size(), newSharees.size());
-    _sharees += newSharees;
+    // Filter sharees that we have already shared with
+    QVector<QSharedPointer<Sharee>> filteredSharees;
+    foreach(const auto &sharee, newSharees) {
+        bool found = false;
+        foreach(const auto &blacklistSharee, _shareeBlacklist) {
+            if (sharee->type() == blacklistSharee->type() &&
+                sharee->shareWith() == blacklistSharee->shareWith()) {
+                found = true;
+                break;
+            }
+        }
+
+        if (found == false) {
+            filteredSharees.append(sharee);
+        }
+    }
+    
+    beginInsertRows(QModelIndex(), _sharees.size(), filteredSharees.size());
+    _sharees += filteredSharees;
     endInsertRows();
 
     shareesReady();
diff --git a/src/gui/sharee.h b/src/gui/sharee.h
index 33a308b..ec95544 100644
--- a/src/gui/sharee.h
+++ b/src/gui/sharee.h
@@ -57,6 +57,7 @@ public:
     explicit ShareeModel(AccountPtr account,
                          const QString search,
                          const QString type,
+                         const QVector<QSharedPointer<Sharee>> &shareeBlacklist,
                          QObject *parent = 0);
 
     void fetch();
@@ -79,6 +80,7 @@ private:
     QString _type;
 
     QVector<QSharedPointer<Sharee>> _sharees;
+    QVector<QSharedPointer<Sharee>> _shareeBlacklist;
 };
 
 }
diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp
index d359fe9..68f4950 100644
--- a/src/gui/shareusergroupwidget.cpp
+++ b/src/gui/shareusergroupwidget.cpp
@@ -83,6 +83,7 @@ void ShareUserGroupWidget::on_searchPushButton_clicked()
     _completerModel = new ShareeModel(_account,
                                       _ui->shareeLineEdit->text(),
                                       _isFile ? QLatin1String("file") : QLatin1String("folder"),
+                                      _sharees,
                                       _completer);
     connect(_completerModel, SIGNAL(shareesReady()), SLOT(slotUpdateCompletion()));
     _completerModel->fetch();
@@ -104,11 +105,14 @@ void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>>
     const QString versionString = _account->serverVersion();
     qDebug() << Q_FUNC_INFO << versionString << "Fetched" << shares.count() << "shares";
 
+    //FIXME
     QLayoutItem *child;
     while ((child = _ui->sharesLayout->takeAt(0)) != 0) {
         delete child;
     }
 
+    _sharees.clear();
+
     foreach(const auto &share, shares) {
 
         if (share->getShareType() == Share::TypeLink) {
@@ -117,7 +121,14 @@ void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>>
 
         ShareWidget *s = new ShareWidget(share, this);
         _ui->sharesLayout->addWidget(s);
+
+        _sharees.append(share->getShareWith());
     }
+    
+    // Add the current user to _sharees since we can't share with ourself
+    QSharedPointer<Sharee> currentUser(new Sharee(_account->credentials()->user(), "", Sharee::Type::User));
+    _sharees.append(currentUser);
+
     _ui->sharesLayout->invalidate();
 }
 
diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h
index b14896a..5da18bc 100644
--- a/src/gui/shareusergroupwidget.h
+++ b/src/gui/shareusergroupwidget.h
@@ -21,7 +21,7 @@
 #include <QVariantMap>
 #include <QSharedPointer>
 #include <QList>
-
+#include <QVector>
 
 class QCompleter;
 
@@ -36,6 +36,7 @@ class AbstractCredentials;
 class QuotaInfo;
 class SyncResult;
 class Share;
+class Sharee;
 class ShareManager;
 class ShareeModel;
 
@@ -104,6 +105,7 @@ private:
     bool _isFile;
 
     ShareManager *_manager;
+    QVector<QSharedPointer<Sharee>> _sharees;
 };
 
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list