Merge pull request #3127 from nextcloud/feature/add-note-to-group-share

Add note to user and group share
This commit is contained in:
Felix Weilbach 2021-04-20 13:47:50 +02:00 коммит произвёл GitHub
Родитель 87f3073b87 275e46f0db
Коммит 596992c2ea
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 470 добавлений и 86 удалений

Просмотреть файл

@ -23,6 +23,8 @@
#include <QJsonObject>
#include <QJsonArray>
Q_LOGGING_CATEGORY(lcUserGroupShare, "nextcloud.gui.usergroupshare", QtInfoMsg)
namespace OCC {
/**
@ -278,6 +280,72 @@ void LinkShare::slotNameSet(const QJsonDocument &, const QVariant &value)
emit nameSet();
}
UserGroupShare::UserGroupShare(AccountPtr account,
const QString &id,
const QString &owner,
const QString &ownerDisplayName,
const QString &path,
const ShareType shareType,
const Permissions permissions,
const QSharedPointer<Sharee> shareWith,
const QDate &expireDate,
const QString &note)
: Share(account, id, owner, ownerDisplayName, path, shareType, permissions, shareWith)
, _expireDate(expireDate)
, _note(note)
{
Q_ASSERT(shareType == TypeUser || shareType == TypeGroup);
Q_ASSERT(shareWith);
}
void UserGroupShare::setNote(const QString &note)
{
auto *job = new OcsShareJob(_account);
connect(job, &OcsShareJob::shareJobFinished, this, &UserGroupShare::slotNoteSet);
connect(job, &OcsJob::ocsError, this, &UserGroupShare::slotOcsError);
job->setNote(getId(), note);
}
QString UserGroupShare::getNote() const
{
return _note;
}
void UserGroupShare::slotNoteSet(const QJsonDocument &, const QVariant &note)
{
_note = note.toString();
emit noteSet();
}
QDate UserGroupShare::getExpireDate() const
{
return _expireDate;
}
void UserGroupShare::setExpireDate(const QDate &date)
{
auto *job = new OcsShareJob(_account);
connect(job, &OcsShareJob::shareJobFinished, this, &UserGroupShare::slotExpireDateSet);
connect(job, &OcsJob::ocsError, this, &UserGroupShare::slotOcsError);
job->setExpireDate(getId(), date);
}
void UserGroupShare::slotExpireDateSet(const QJsonDocument &reply, const QVariant &value)
{
auto data = reply.object().value("ocs").toObject().value("data").toObject();
/*
* If the reply provides a data back (more REST style)
* they use this date.
*/
if (data.value("expiration").isString()) {
_expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
} else {
_expireDate = value.toDate();
}
emit expireDateSet();
}
ShareManager::ShareManager(AccountPtr account, QObject *parent)
: QObject(parent)
, _account(account)
@ -390,6 +458,8 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply)
if (shareType == Share::TypeLink) {
newShare = parseLinkShare(data);
} else if (shareType == Share::TypeGroup || shareType == Share::TypeUser) {
newShare = parseUserGroupShare(data);
} else {
newShare = parseShare(data);
}
@ -401,6 +471,34 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply)
emit sharesFetched(shares);
}
QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObject &data)
{
QSharedPointer<Sharee> sharee(new Sharee(data.value("share_with").toString(),
data.value("share_with_displayname").toString(),
static_cast<Sharee::Type>(data.value("share_type").toInt())));
QDate expireDate;
if (data.value("expiration").isString()) {
expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
}
QString note;
if (data.value("note").isString()) {
note = data.value("note").toString();
}
return QSharedPointer<UserGroupShare>(new UserGroupShare(_account,
data.value("id").toVariant().toString(), // "id" used to be an integer, support both
data.value("uid_owner").toVariant().toString(),
data.value("displayname_owner").toVariant().toString(),
data.value("path").toString(),
static_cast<Share::ShareType>(data.value("share_type").toInt()),
static_cast<Share::Permissions>(data.value("permissions").toInt()),
sharee,
expireDate,
note));
}
QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QJsonObject &data)
{
QUrl url;

Просмотреть файл

@ -259,6 +259,42 @@ private:
QUrl _url;
};
class UserGroupShare : public Share
{
Q_OBJECT
public:
UserGroupShare(AccountPtr account,
const QString &id,
const QString &owner,
const QString &ownerDisplayName,
const QString &path,
const ShareType shareType,
const Permissions permissions,
const QSharedPointer<Sharee> shareWith,
const QDate &expireDate,
const QString &note);
void setNote(const QString &note);
QString getNote() const;
void slotNoteSet(const QJsonDocument &, const QVariant &note);
void setExpireDate(const QDate &date);
QDate getExpireDate() const;
void slotExpireDateSet(const QJsonDocument &reply, const QVariant &value);
signals:
void noteSet();
void expireDateSet();
private:
QString _note;
QDate _expireDate;
};
/**
* The share manager allows for creating, retrieving and deletion
* of shares. It abstracts away from the OCS Share API, all the usages
@ -331,6 +367,7 @@ private slots:
void slotOcsError(int statusCode, const QString &message);
private:
QSharedPointer<LinkShare> parseLinkShare(const QJsonObject &data);
QSharedPointer<UserGroupShare> parseUserGroupShare(const QJsonObject &data);
QSharedPointer<Share> parseShare(const QJsonObject &data);
AccountPtr _account;

Просмотреть файл

@ -12,6 +12,7 @@
* for more details.
*/
#include "sharee.h"
#include "ui_shareusergroupwidget.h"
#include "ui_shareuserline.h"
#include "shareusergroupwidget.h"
@ -228,7 +229,10 @@ void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>>
_ui->mainOwnerLabel->setText(QString("Shared with you by ").append(share->getOwnerDisplayName()));
}
auto *s = new ShareUserLine(share, _maxSharingPermissions, _isFile, _parentScrollArea);
Q_ASSERT(share->getShareType() == Share::TypeUser || share->getShareType() == Share::TypeGroup);
auto userGroupShare = qSharedPointerDynamicCast<UserGroupShare>(share);
auto *s = new ShareUserLine(userGroupShare, _maxSharingPermissions, _isFile, _parentScrollArea);
connect(s, &ShareUserLine::resizeRequested, this, &ShareUserGroupWidget::slotAdjustScrollWidgetSize);
connect(s, &ShareUserLine::visualDeletionDone, this, &ShareUserGroupWidget::getShares);
s->setBackgroundRole(layout->count() % 2 == 0 ? QPalette::Base : QPalette::AlternateBase);
@ -267,12 +271,19 @@ void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>>
void ShareUserGroupWidget::slotAdjustScrollWidgetSize()
{
QScrollArea *scrollArea = _parentScrollArea;
int count = scrollArea->findChildren<ShareUserLine *>().count();
scrollArea->setVisible(count > 0);
if (count > 0 && count <= 3) {
const auto shareUserLineChilds = scrollArea->findChildren<ShareUserLine *>();
// Ask the child widgets to calculate their size
for (const auto shareUserLineChild : shareUserLineChilds) {
shareUserLineChild->adjustSize();
}
const auto shareUserLineChildsCount = shareUserLineChilds.count();
scrollArea->setVisible(shareUserLineChildsCount > 0);
if (shareUserLineChildsCount > 0 && shareUserLineChildsCount <= 3) {
scrollArea->setFixedHeight(scrollArea->widget()->sizeHint().height());
}
scrollArea->setFrameShape(count > 3 ? QFrame::StyledPanel : QFrame::NoFrame);
scrollArea->setFrameShape(shareUserLineChildsCount > 3 ? QFrame::StyledPanel : QFrame::NoFrame);
}
void ShareUserGroupWidget::slotPrivateLinkShare()
@ -413,7 +424,7 @@ void ShareUserGroupWidget::activateShareeLineEdit()
_ui->shareeLineEdit->setFocus();
}
ShareUserLine::ShareUserLine(QSharedPointer<Share> share,
ShareUserLine::ShareUserLine(QSharedPointer<UserGroupShare> share,
SharePermissions maxSharingPermissions,
bool isFile,
QWidget *parent)
@ -422,6 +433,7 @@ ShareUserLine::ShareUserLine(QSharedPointer<Share> share,
, _share(share)
, _isFile(isFile)
{
Q_ASSERT(_share);
_ui->setupUi(this);
_ui->sharedWith->setElideMode(Qt::ElideRight);
@ -434,6 +446,12 @@ ShareUserLine::ShareUserLine(QSharedPointer<Share> share,
maxSharingPermissions & SharePermissionDelete);
_ui->permissionsEdit->setEnabled(enabled);
connect(_ui->permissionsEdit, &QAbstractButton::clicked, this, &ShareUserLine::slotEditPermissionsChanged);
connect(_ui->noteConfirmButton, &QAbstractButton::clicked, this, &ShareUserLine::onNoteConfirmButtonClicked);
connect(_ui->confirmExpirationDate, &QAbstractButton::clicked, this, &ShareUserLine::setExpireDate);
connect(_ui->calendar, &QDateTimeEdit::dateChanged, this, &ShareUserLine::setExpireDate);
connect(_share.data(), &UserGroupShare::noteSet, this, &ShareUserLine::disableProgessIndicatorAnimation);
connect(_share.data(), &UserGroupShare::expireDateSet, this, &ShareUserLine::disableProgessIndicatorAnimation);
// create menu with checkable permissions
auto *menu = new QMenu(this);
@ -443,6 +461,28 @@ ShareUserLine::ShareUserLine(QSharedPointer<Share> share,
menu->addAction(_permissionReshare);
connect(_permissionReshare, &QAction::triggered, this, &ShareUserLine::slotPermissionsChanged);
showNoteOptions(false);
_noteLinkAction = new QAction(tr("Note to recipient"));
_noteLinkAction->setCheckable(true);
menu->addAction(_noteLinkAction);
connect(_noteLinkAction, &QAction::triggered, this, &ShareUserLine::toggleNoteOptions);
if (!_share->getNote().isEmpty()) {
_noteLinkAction->setChecked(true);
showNoteOptions(true);
}
showExpireDateOptions(false);
_expirationDateLinkAction = new QAction(tr("Set expiration date"));
_expirationDateLinkAction->setCheckable(true);
menu->addAction(_expirationDateLinkAction);
connect(_expirationDateLinkAction, &QAction::triggered, this, &ShareUserLine::toggleExpireDateOptions);
const auto expireDate = _share->getExpireDate().isValid() ? share.data()->getExpireDate() : QDate();
if (!expireDate.isNull()) {
_ui->calendar->setDate(expireDate);
_expirationDateLinkAction->setChecked(true);
showExpireDateOptions(true);
}
menu->addSeparator();
// Adds action to delete share widget
@ -708,6 +748,93 @@ void ShareUserLine::customizeStyle()
QIcon deleteicon = QIcon::fromTheme(QLatin1String("user-trash"),Theme::createColorAwareIcon(QLatin1String(":/client/theme/delete.svg")));
_deleteShareButton->setIcon(deleteicon);
_ui->noteConfirmButton->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg"));
_ui->confirmExpirationDate->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg"));
_ui->progressIndicator->setColor(QGuiApplication::palette().color(QPalette::WindowText));
}
void ShareUserLine::showNoteOptions(bool show)
{
_ui->noteLabel->setVisible(show);
_ui->noteTextEdit->setVisible(show);
_ui->noteConfirmButton->setVisible(show);
if (show) {
const auto note = _share->getNote();
_ui->noteTextEdit->setText(note);
_ui->noteTextEdit->setFocus();
}
emit resizeRequested();
}
void ShareUserLine::toggleNoteOptions(bool enable)
{
showNoteOptions(enable);
if (!enable) {
// Delete note
_share->setNote(QString());
}
}
void ShareUserLine::onNoteConfirmButtonClicked()
{
setNote(_ui->noteTextEdit->toPlainText());
}
void ShareUserLine::setNote(const QString &note)
{
enableProgessIndicatorAnimation(true);
_share->setNote(note);
}
void ShareUserLine::toggleExpireDateOptions(bool enable)
{
showExpireDateOptions(enable);
if (!enable) {
_share->setExpireDate(QDate());
}
}
void ShareUserLine::showExpireDateOptions(bool show)
{
_ui->expirationLabel->setVisible(show);
_ui->calendar->setVisible(show);
_ui->confirmExpirationDate->setVisible(show);
if (show) {
const QDate date = QDate::currentDate().addDays(1);
_ui->calendar->setDate(date);
_ui->calendar->setMinimumDate(date);
_ui->calendar->setFocus();
}
emit resizeRequested();
}
void ShareUserLine::setExpireDate()
{
enableProgessIndicatorAnimation(true);
_share->setExpireDate(_ui->calendar->date());
}
void ShareUserLine::enableProgessIndicatorAnimation(bool enable)
{
if (enable) {
if (!_ui->progressIndicator->isAnimated()) {
_ui->progressIndicator->startAnimation();
}
} else {
_ui->progressIndicator->stopAnimation();
}
}
void ShareUserLine::disableProgessIndicatorAnimation()
{
enableProgessIndicatorAnimation(false);
}
}

Просмотреть файл

@ -16,6 +16,7 @@
#define SHAREUSERGROUPWIDGET_H
#include "accountfwd.h"
#include "sharemanager.h"
#include "sharepermissions.h"
#include "sharee.h"
#include "QProgressIndicator.h"
@ -119,7 +120,7 @@ class ShareUserLine : public QWidget
Q_OBJECT
public:
explicit ShareUserLine(QSharedPointer<Share> Share,
explicit ShareUserLine(QSharedPointer<UserGroupShare> share,
SharePermissions maxSharingPermissions,
bool isFile,
QWidget *parent = nullptr);
@ -150,16 +151,30 @@ private:
void loadAvatar();
void customizeStyle();
Ui::ShareUserLine *_ui;
QSharedPointer<Share> _share;
bool _isFile;
void showNoteOptions(bool show);
void toggleNoteOptions(bool enable);
void onNoteConfirmButtonClicked();
void setNote(const QString &note);
// _permissionEdit is a checkbox
QAction *_permissionReshare;
QAction *_deleteShareButton;
QAction *_permissionCreate;
QAction *_permissionChange;
QAction *_permissionDelete;
void toggleExpireDateOptions(bool enable);
void showExpireDateOptions(bool show);
void setExpireDate();
void enableProgessIndicatorAnimation(bool enable);
void disableProgessIndicatorAnimation();
Ui::ShareUserLine *_ui;
QSharedPointer<UserGroupShare> _share;
bool _isFile;
// _permissionEdit is a checkbox
QAction *_permissionReshare;
QAction *_deleteShareButton;
QAction *_permissionCreate;
QAction *_permissionChange;
QAction *_permissionDelete;
QAction *_noteLinkAction;
QAction *_expirationDateLinkAction;
};
}

Просмотреть файл

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>58</height>
<width>980</width>
<height>210</height>
</rect>
</property>
<property name="sizePolicy">
@ -25,81 +25,182 @@
<property name="autoFillBackground">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="avatar">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="rightMargin">
<number>0</number>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<item>
<widget class="QLabel" name="avatar">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="OCC::ElidedLabel" name="sharedWith">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Username</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<widget class="QProgressIndicator" name="progressIndicator" native="true"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="permissionsEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>can edit</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="permissionToolButton">
<property name="icon">
<iconset resource="../../theme.qrc">
<normaloff>:/client/theme/more.svg</normaloff>:/client/theme/more.svg</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="OCC::ElidedLabel" name="sharedWith">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="text">
<string>Username</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
<item>
<widget class="QLabel" name="noteLabel">
<property name="text">
<string>Note:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="noteTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="noteConfirmButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../theme.qrc">
<normaloff>:/client/theme/confirm.svg</normaloff>:/client/theme/confirm.svg</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="permissionsEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>can edit</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="permissionToolButton">
<property name="icon">
<iconset resource="../../theme.qrc">
<normaloff>:/client/theme/more.svg</normaloff>:/client/theme/more.svg</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="expirationLabel">
<property name="minimumSize">
<size>
<width>78</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Expires:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDateEdit" name="calendar">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="confirmExpirationDate">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../theme.qrc">
<normaloff>:/client/theme/confirm.svg</normaloff>:/client/theme/confirm.svg</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
@ -109,6 +210,12 @@
<extends>QLabel</extends>
<header>elidedlabel.h</header>
</customwidget>
<customwidget>
<class>QProgressIndicator</class>
<extends>QWidget</extends>
<header>QProgressIndicator.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../theme.qrc"/>