Merge pull request #3713 from nextcloud/feature/share-server-permissions

Use default sharing permissions from server
This commit is contained in:
Matthieu Gallien 2021-09-27 12:52:31 +02:00 коммит произвёл GitHub
Родитель c521ca0949 1de38a13f3
Коммит 8af4d905f1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 62 добавлений и 48 удалений

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

@ -631,19 +631,7 @@ void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &l
}
}
// As a first approximation, set the set of permissions that can be granted
// either to everything (resharing allowed) or nothing (no resharing).
//
// The correct value will be found with a propfind from ShareDialog.
// (we want to show the dialog directly, not wait for the propfind first)
SharePermissions maxSharingPermissions =
SharePermissionRead
| SharePermissionUpdate | SharePermissionCreate | SharePermissionDelete
| SharePermissionShare;
if (!resharingAllowed) {
maxSharingPermissions = {};
}
auto maxSharingPermissions = resharingAllowed? SharePermissions(accountState->account()->capabilities().shareDefaultPermissions()) : SharePermissions({});
ShareDialog *w = nullptr;
if (_shareDialogs.contains(localPath) && _shareDialogs[localPath]) {

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

@ -371,43 +371,30 @@ void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex &index)
*/
_lastCreatedShareId = QString();
if (sharee->type() == Sharee::Federated
&& _account->serverVersionInt() < Account::makeServerVersion(9, 1, 0)) {
int permissions = SharePermissionRead | SharePermissionUpdate;
if (!_isFile) {
permissions |= SharePermissionCreate | SharePermissionDelete;
QString password;
if (sharee->type() == Sharee::Email && _account->capabilities().shareEmailPasswordEnforced()) {
_ui->shareeLineEdit->clear();
// always show a dialog for password-enforced email shares
bool ok = false;
do {
password = QInputDialog::getText(
this,
tr("Password for share required"),
tr("Please enter a password for your email share:"),
QLineEdit::Password,
QString(),
&ok);
} while (password.isEmpty() && ok);
if (!ok) {
return;
}
_manager->createShare(_sharePath, Share::ShareType(sharee->type()),
sharee->shareWith(), SharePermission(permissions));
} else {
QString password;
if (sharee->type() == Sharee::Email && _account->capabilities().shareEmailPasswordEnforced()) {
_ui->shareeLineEdit->clear();
// always show a dialog for password-enforced email shares
bool ok = false;
do {
password = QInputDialog::getText(
this,
tr("Password for share required"),
tr("Please enter a password for your email share:"),
QLineEdit::Password,
QString(),
&ok);
} while (password.isEmpty() && ok);
if (!ok) {
return;
}
}
// Default permissions on creation
int permissions = SharePermissionCreate | SharePermissionUpdate
| SharePermissionDelete | SharePermissionShare;
_manager->createShare(_sharePath, Share::ShareType(sharee->type()),
sharee->shareWith(), SharePermission(permissions), password);
}
_manager->createShare(_sharePath, Share::ShareType(sharee->type()),
sharee->shareWith(), _maxSharingPermissions, password);
_ui->shareeLineEdit->setEnabled(false);
_ui->shareeLineEdit->clear();

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

@ -100,6 +100,15 @@ bool Capabilities::shareResharing() const
return _capabilities["files_sharing"].toMap()["resharing"].toBool();
}
int Capabilities::shareDefaultPermissions() const
{
if(_capabilities["files_sharing"].toMap().contains("default_permissions")) {
return _capabilities["files_sharing"].toMap()["default_permissions"].toInt();
}
return {};
}
bool Capabilities::clientSideEncryptionAvailable() const
{
auto it = _capabilities.constFind(QStringLiteral("end-to-end-encryption"));

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

@ -57,6 +57,7 @@ public:
int sharePublicLinkExpireDateDays() const;
bool sharePublicLinkMultiple() const;
bool shareResharing() const;
int shareDefaultPermissions() const;
bool chunkingNg() const;
bool userStatusNotification() const;
bool userStatus() const;

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

@ -214,6 +214,35 @@ private slots:
QVERIFY(!capabilities.userStatusSupportsEmoji());
}
void testShareDefaultPermissions_defaultSharePermissionsNotInCapabilities_returnZero()
{
QVariantMap filesSharingMap;
filesSharingMap["api_enabled"] = false;
QVariantMap capabilitiesMap;
capabilitiesMap["files_sharing"] = filesSharingMap;
const OCC::Capabilities capabilities(capabilitiesMap);
const auto defaultSharePermissionsNotInCapabilities = capabilities.shareDefaultPermissions();
QCOMPARE(defaultSharePermissionsNotInCapabilities, {});
}
void testShareDefaultPermissions_defaultSharePermissionsAvailable_returnPermissions()
{
QVariantMap filesSharingMap;
filesSharingMap["api_enabled"] = true;
filesSharingMap["default_permissions"] = 31;
QVariantMap capabilitiesMap;
capabilitiesMap["files_sharing"] = filesSharingMap;
const OCC::Capabilities capabilities(capabilitiesMap);
const auto defaultSharePermissionsAvailable = capabilities.shareDefaultPermissions();
QCOMPARE(defaultSharePermissionsAvailable, 31);
}
};
QTEST_GUILESS_MAIN(TestCapabilities)