Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authoralex-z <blackslayer4@gmail.com>2021-11-01 18:37:23 +0300
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>2021-11-03 13:54:18 +0300
commit6c3c45dadd725f1a0488924dbc1db0ed20add5a9 (patch)
tree9680575214d042b8131e23d3ff1ce44e5248d42b /src/gui
parentf3af4ce09861a282789849223c6c7515f3bd0f50 (diff)
Implement expiration date for federated shares
Signed-off-by: alex-z <blackslayer4@gmail.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/sharemanager.cpp10
-rw-r--r--src/gui/sharemanager.h5
-rw-r--r--src/gui/shareusergroupwidget.cpp37
-rw-r--r--src/gui/shareusergroupwidget.h3
4 files changed, 52 insertions, 3 deletions
diff --git a/src/gui/sharemanager.cpp b/src/gui/sharemanager.cpp
index 4490ff067..afebb981f 100644
--- a/src/gui/sharemanager.cpp
+++ b/src/gui/sharemanager.cpp
@@ -146,6 +146,12 @@ void Share::deleteShare()
job->deleteShare(getId());
}
+bool Share::isUserGroupShare(const ShareType type)
+{
+ return (type == Share::TypeUser || type == Share::TypeGroup || type == Share::TypeEmail || type == Share::TypeRoom
+ || type == Share::TypeRemote);
+}
+
void Share::slotDeleted()
{
updateFolder(_account, _path);
@@ -317,7 +323,7 @@ UserGroupShare::UserGroupShare(AccountPtr account,
, _note(note)
, _expireDate(expireDate)
{
- Q_ASSERT(shareType == TypeUser || shareType == TypeGroup || shareType == TypeEmail || shareType == TypeRoom);
+ Q_ASSERT(Share::isUserGroupShare(shareType));
Q_ASSERT(shareWith);
}
@@ -487,7 +493,7 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply)
if (shareType == Share::TypeLink) {
newShare = parseLinkShare(data);
- } else if (shareType == Share::TypeGroup || shareType == Share::TypeUser || shareType == Share::TypeEmail || shareType == Share::TypeRoom) {
+ } else if (Share::isUserGroupShare(static_cast <Share::ShareType>(shareType))) {
newShare = parseUserGroupShare(data);
} else {
newShare = parseShare(data);
diff --git a/src/gui/sharemanager.h b/src/gui/sharemanager.h
index f30a26576..06e53c026 100644
--- a/src/gui/sharemanager.h
+++ b/src/gui/sharemanager.h
@@ -130,6 +130,11 @@ public:
*/
void deleteShare();
+ /*
+ * Is it a share with a user or group (local or remote)
+ */
+ static bool isUserGroupShare(const ShareType type);
+
signals:
void permissionsSet();
void shareDeleted();
diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp
index 45d2c9ec7..4b463ad70 100644
--- a/src/gui/shareusergroupwidget.cpp
+++ b/src/gui/shareusergroupwidget.cpp
@@ -249,7 +249,7 @@ void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>>
}
- Q_ASSERT(share->getShareType() == Share::TypeUser || share->getShareType() == Share::TypeGroup || share->getShareType() == Share::TypeEmail || share->getShareType() == Share::TypeRoom);
+ Q_ASSERT(Share::isUserGroupShare(share->getShareType()));
auto userGroupShare = qSharedPointerDynamicCast<UserGroupShare>(share);
auto *s = new ShareUserLine(_account, userGroupShare, _maxSharingPermissions, _isFile, _parentScrollArea);
connect(s, &ShareUserLine::resizeRequested, this, &ShareUserGroupWidget::slotAdjustScrollWidgetSize);
@@ -1031,6 +1031,12 @@ void ShareUserLine::showExpireDateOptions(bool show, const QDate &initialDate)
_ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
_ui->calendar->setDate(initialDate.isValid() ? initialDate : _ui->calendar->minimumDate());
_ui->calendar->setFocus();
+
+ if (enforceExpirationDateForShare(_share->getShareType())) {
+ _ui->calendar->setMaximumDate(maxExpirationDateForShare(_share->getShareType(), _ui->calendar->maximumDate()));
+ _expirationDateLinkAction->setChecked(true);
+ _expirationDateLinkAction->setEnabled(false);
+ }
}
emit resizeRequested();
@@ -1072,6 +1078,35 @@ void ShareUserLine::disableProgessIndicatorAnimation()
enableProgessIndicatorAnimation(false);
}
+QDate ShareUserLine::maxExpirationDateForShare(const Share::ShareType type, const QDate &fallbackDate) const
+{
+ auto daysToExpire = 0;
+ if (type == Share::ShareType::TypeRemote) {
+ daysToExpire = _account->capabilities().shareRemoteExpireDateDays();
+ } else if (type == Share::ShareType::TypeEmail) {
+ daysToExpire = _account->capabilities().sharePublicLinkExpireDateDays();
+ } else {
+ daysToExpire = _account->capabilities().shareInternalExpireDateDays();
+ }
+
+ if (daysToExpire > 0) {
+ return QDate::currentDate().addDays(daysToExpire);
+ }
+
+ return fallbackDate;
+}
+
+bool ShareUserLine::enforceExpirationDateForShare(const Share::ShareType type) const
+{
+ if (type == Share::ShareType::TypeRemote) {
+ return _account->capabilities().shareRemoteEnforceExpireDate();
+ } else if (type == Share::ShareType::TypeEmail) {
+ return _account->capabilities().sharePublicLinkEnforceExpireDate();
+ } else {
+ return _account->capabilities().shareInternalEnforceExpireDate();
+ }
+}
+
void ShareUserLine::setPasswordConfirmed()
{
if (_ui->lineEdit_password->text().isEmpty()) {
diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h
index 8715af22f..c63e56d74 100644
--- a/src/gui/shareusergroupwidget.h
+++ b/src/gui/shareusergroupwidget.h
@@ -189,6 +189,9 @@ private:
void enableProgessIndicatorAnimation(bool enable);
void disableProgessIndicatorAnimation();
+ QDate maxExpirationDateForShare(const Share::ShareType type, const QDate &fallbackDate) const;
+ bool enforceExpirationDateForShare(const Share::ShareType type) const;
+
Ui::ShareUserLine *_ui;
AccountPtr _account;
QSharedPointer<UserGroupShare> _share;