mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
Add expire date to user and group share
Fixes #3100 Signed-off-by: Felix Weilbach <felix.weilbach@nextcloud.com>
This commit is contained in:
parent
946a51e4c1
commit
22a3b19e08
5 changed files with 148 additions and 5 deletions
|
@ -285,8 +285,10 @@ UserGroupShare::UserGroupShare(AccountPtr account,
|
|||
const QString &path,
|
||||
const ShareType shareType,
|
||||
const Permissions permissions,
|
||||
const QSharedPointer<Sharee> shareWith)
|
||||
const QSharedPointer<Sharee> shareWith,
|
||||
const QDate &expireDate)
|
||||
: Share(account, id, owner, ownerDisplayName, path, shareType, permissions, shareWith)
|
||||
, _expireDate(expireDate)
|
||||
{
|
||||
Q_ASSERT(shareType == TypeUser || shareType == TypeGroup);
|
||||
Q_ASSERT(shareWith);
|
||||
|
@ -306,6 +308,35 @@ void UserGroupShare::slotNoteSet(const QJsonDocument &, const QVariant ¬e)
|
|||
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)
|
||||
|
@ -437,6 +468,11 @@ QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObje
|
|||
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");
|
||||
}
|
||||
|
||||
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(),
|
||||
|
@ -444,7 +480,8 @@ QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObje
|
|||
data.value("path").toString(),
|
||||
static_cast<Share::ShareType>(data.value("share_type").toInt()),
|
||||
static_cast<Share::Permissions>(data.value("permissions").toInt()),
|
||||
sharee));
|
||||
sharee,
|
||||
expireDate));
|
||||
}
|
||||
|
||||
QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QJsonObject &data)
|
||||
|
|
|
@ -270,17 +270,26 @@ public:
|
|||
const QString &path,
|
||||
const ShareType shareType,
|
||||
const Permissions permissions,
|
||||
const QSharedPointer<Sharee> shareWith);
|
||||
const QSharedPointer<Sharee> shareWith,
|
||||
const QDate &expireDate);
|
||||
|
||||
void setNote(const QString ¬e);
|
||||
|
||||
void slotNoteSet(const QJsonDocument &, const QVariant ¬e);
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -445,6 +445,8 @@ ShareUserLine::ShareUserLine(QSharedPointer<UserGroupShare> share,
|
|||
_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);
|
||||
|
||||
// create menu with checkable permissions
|
||||
auto *menu = new QMenu(this);
|
||||
|
@ -454,11 +456,24 @@ ShareUserLine::ShareUserLine(QSharedPointer<UserGroupShare> share,
|
|||
menu->addAction(_permissionReshare);
|
||||
connect(_permissionReshare, &QAction::triggered, this, &ShareUserLine::slotPermissionsChanged);
|
||||
|
||||
toggleNoteOptions(false);
|
||||
_noteLinkAction = new QAction(tr("Note to recipient"));
|
||||
_noteLinkAction->setCheckable(true);
|
||||
menu->addAction(_noteLinkAction);
|
||||
connect(_noteLinkAction, &QAction::triggered, this, &ShareUserLine::toggleNoteOptions);
|
||||
|
||||
toggleExpireDateOptions(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.data()->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
|
||||
|
@ -516,7 +531,6 @@ ShareUserLine::ShareUserLine(QSharedPointer<UserGroupShare> share,
|
|||
}
|
||||
|
||||
loadAvatar();
|
||||
toggleNoteOptions(false);
|
||||
|
||||
customizeStyle();
|
||||
}
|
||||
|
@ -727,6 +741,7 @@ void ShareUserLine::customizeStyle()
|
|||
_deleteShareButton->setIcon(deleteicon);
|
||||
|
||||
_ui->noteConfirmButton->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg"));
|
||||
_ui->confirmExpirationDate->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg"));
|
||||
}
|
||||
|
||||
void ShareUserLine::showNoteOptions(bool show)
|
||||
|
@ -764,4 +779,37 @@ void ShareUserLine::setNote(const QString ¬e)
|
|||
_share->setNote(note);
|
||||
}
|
||||
}
|
||||
|
||||
void ShareUserLine::toggleExpireDateOptions(bool enable)
|
||||
{
|
||||
showExpireDateOptions(enable);
|
||||
|
||||
if (enable) {
|
||||
const QDate date = QDate::currentDate().addDays(1);
|
||||
_ui->calendar->setDate(date);
|
||||
_ui->calendar->setMinimumDate(date);
|
||||
_ui->calendar->setFocus();
|
||||
} else {
|
||||
// 'deletes' expire date
|
||||
if (_share)
|
||||
_share->setExpireDate(QDate());
|
||||
}
|
||||
}
|
||||
|
||||
void ShareUserLine::showExpireDateOptions(bool show)
|
||||
{
|
||||
_ui->expirationLabel->setVisible(show);
|
||||
_ui->calendar->setVisible(show);
|
||||
_ui->confirmExpirationDate->setVisible(show);
|
||||
emit resizeRequested();
|
||||
}
|
||||
|
||||
void ShareUserLine::setExpireDate()
|
||||
{
|
||||
if (!_share) {
|
||||
return;
|
||||
}
|
||||
|
||||
_share->setExpireDate(_ui->calendar->date());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,6 +156,10 @@ private:
|
|||
void onNoteConfirmButtonClicked();
|
||||
void setNote(const QString ¬e);
|
||||
|
||||
void toggleExpireDateOptions(bool enable);
|
||||
void showExpireDateOptions(bool show);
|
||||
void setExpireDate();
|
||||
|
||||
Ui::ShareUserLine *_ui;
|
||||
QSharedPointer<UserGroupShare> _share;
|
||||
bool _isFile;
|
||||
|
@ -167,6 +171,7 @@ private:
|
|||
QAction *_permissionChange;
|
||||
QAction *_permissionDelete;
|
||||
QAction *_noteLinkAction;
|
||||
QAction *_expirationDateLinkAction;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>523</width>
|
||||
<width>486</width>
|
||||
<height>208</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -163,6 +163,50 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<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>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in a new issue