mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 13:35:58 +03:00
[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
This commit is contained in:
parent
3e4612a1f0
commit
20fd349e17
4 changed files with 38 additions and 4 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue