Show user/group note on share if already set

Signed-off-by: Felix Weilbach <felix.weilbach@nextcloud.com>
This commit is contained in:
Felix Weilbach 2021-04-15 15:47:10 +02:00 committed by Felix Weilbach (Rebase PR Action)
parent 22a3b19e08
commit 2851528595
3 changed files with 30 additions and 7 deletions

View file

@ -286,9 +286,11 @@ UserGroupShare::UserGroupShare(AccountPtr account,
const ShareType shareType,
const Permissions permissions,
const QSharedPointer<Sharee> shareWith,
const QDate &expireDate)
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);
@ -302,6 +304,11 @@ void UserGroupShare::setNote(const QString &note)
job->setNote(getId(), note);
}
QString UserGroupShare::getNote() const
{
return _note;
}
void UserGroupShare::slotNoteSet(const QJsonDocument &, const QVariant &note)
{
_note = note.toString();
@ -473,6 +480,11 @@ QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObje
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(),
@ -481,7 +493,8 @@ QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObje
static_cast<Share::ShareType>(data.value("share_type").toInt()),
static_cast<Share::Permissions>(data.value("permissions").toInt()),
sharee,
expireDate));
expireDate,
note));
}
QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QJsonObject &data)

View file

@ -271,10 +271,13 @@ public:
const ShareType shareType,
const Permissions permissions,
const QSharedPointer<Sharee> shareWith,
const QDate &expireDate);
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);

View file

@ -461,13 +461,17 @@ ShareUserLine::ShareUserLine(QSharedPointer<UserGroupShare> share,
_noteLinkAction->setCheckable(true);
menu->addAction(_noteLinkAction);
connect(_noteLinkAction, &QAction::triggered, this, &ShareUserLine::toggleNoteOptions);
if (!_share->getNote().isEmpty()) {
_noteLinkAction->setChecked(true);
toggleNoteOptions(true);
}
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();
const auto expireDate = _share->getExpireDate().isValid() ? share.data()->getExpireDate() : QDate();
if (!expireDate.isNull()) {
_ui->calendar->setDate(expireDate);
_expirationDateLinkAction->setChecked(true);
@ -758,11 +762,16 @@ void ShareUserLine::toggleNoteOptions(bool enable)
showNoteOptions(enable);
if (enable) {
const auto note = _share->getNote();
if (!note.isEmpty()) {
_ui->noteTextEdit->setText(note);
}
_ui->noteTextEdit->setFocus();
} else {
// 'deletes' note
if (_share)
if (_share) {
_share->setNote(QString());
}
}
}
@ -774,8 +783,6 @@ void ShareUserLine::onNoteConfirmButtonClicked()
void ShareUserLine::setNote(const QString &note)
{
if (_share) {
// slotToggleAnimation(true);
// _ui->errorLabel->hide();
_share->setNote(note);
}
}