mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-29 12:19:03 +03:00
Implement expiration date for federated shares
Signed-off-by: alex-z <blackslayer4@gmail.com>
This commit is contained in:
parent
f3af4ce098
commit
6c3c45dadd
6 changed files with 76 additions and 3 deletions
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -90,6 +90,26 @@ int Capabilities::sharePublicLinkExpireDateDays() const
|
|||
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date"].toMap()["days"].toInt();
|
||||
}
|
||||
|
||||
bool Capabilities::shareInternalEnforceExpireDate() const
|
||||
{
|
||||
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date_internal"].toMap()["enforced"].toBool();
|
||||
}
|
||||
|
||||
int Capabilities::shareInternalExpireDateDays() const
|
||||
{
|
||||
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date_internal"].toMap()["days"].toInt();
|
||||
}
|
||||
|
||||
bool Capabilities::shareRemoteEnforceExpireDate() const
|
||||
{
|
||||
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date_remote"].toMap()["enforced"].toBool();
|
||||
}
|
||||
|
||||
int Capabilities::shareRemoteExpireDateDays() const
|
||||
{
|
||||
return _capabilities["files_sharing"].toMap()["public"].toMap()["expire_date_remote"].toMap()["days"].toInt();
|
||||
}
|
||||
|
||||
bool Capabilities::sharePublicLinkMultiple() const
|
||||
{
|
||||
return _capabilities["files_sharing"].toMap()["public"].toMap()["multiple"].toBool();
|
||||
|
|
|
@ -55,6 +55,10 @@ public:
|
|||
bool sharePublicLinkEnforcePassword() const;
|
||||
bool sharePublicLinkEnforceExpireDate() const;
|
||||
int sharePublicLinkExpireDateDays() const;
|
||||
bool shareInternalEnforceExpireDate() const;
|
||||
int shareInternalExpireDateDays() const;
|
||||
bool shareRemoteEnforceExpireDate() const;
|
||||
int shareRemoteExpireDateDays() const;
|
||||
bool sharePublicLinkMultiple() const;
|
||||
bool shareResharing() const;
|
||||
int shareDefaultPermissions() const;
|
||||
|
|
Loading…
Reference in a new issue