Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Allow resharing" option to share dialog #5965

Merged
merged 7 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/gui/filedetails/ShareDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ GridLayout {
property bool backgroundsVisible: true

property bool canCreateLinkShares: true
property bool serverAllowsResharing: true

readonly property bool isLinkShare: model.shareType === ShareModel.ShareTypeLink
readonly property bool isPlaceholderLinkShare: model.shareType === ShareModel.ShareTypePlaceholderLink
Expand Down Expand Up @@ -268,6 +269,7 @@ GridLayout {
shareModelData: model

canCreateLinkShares: root.canCreateLinkShares
serverAllowsResharing: root.serverAllowsResharing

onCloseShareDetails: root.rootStackView.pop(root.rootStackView.initialItem, StackView.PopTransition)

Expand Down
64 changes: 56 additions & 8 deletions src/gui/filedetails/ShareDetailsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Page {
property var shareModelData: ({})

property bool canCreateLinkShares: true
property bool serverAllowsResharing: true

readonly property var share: shareModelData.share ?? ({})

Expand All @@ -66,6 +67,7 @@ Page {

readonly property string linkShareLabel: shareModelData.linkShareLabel ?? ""

readonly property bool resharingAllowed: shareModelData.resharingAllowed
readonly property bool editingAllowed: shareModelData.editingAllowed
readonly property bool hideDownload: shareModelData.hideDownload
readonly property bool noteEnabled: shareModelData.noteEnabled
Expand Down Expand Up @@ -142,7 +144,6 @@ Page {
}

function resetMenu() {

resetNoteField();
resetPasswordField();
resetLinkShareLabelField();
Expand Down Expand Up @@ -394,13 +395,6 @@ Page {
spacing: scrollContentsColumn.indicatorSpacing
padding: scrollContentsColumn.itemPadding
onClicked: root.permissionModeChanged(permissionMode)

NCBusyIndicator {
anchors.fill: parent
visible: root.isSharePermissionChangeInProgress
running: visible
z: 1
}
}

NCRadioButton {
Expand All @@ -416,6 +410,60 @@ Page {
padding: scrollContentsColumn.itemPadding
onClicked: root.permissionModeChanged(permissionMode)
}

CheckBox {
id: allowResharingCheckBox

Layout.fillWidth: true

// TODO: Rather than setting all these palette colours manually,
// create a custom style and do it for all components globally.
//
// Additionally, we need to override the entire palette when we
// set one palette property, as otherwise we default back to the
// theme palette -- not the parent palette
palette {
text: Style.ncTextColor
windowText: Style.ncTextColor
buttonText: Style.ncTextColor
brightText: Style.ncTextBrightColor
highlight: Style.lightHover
highlightedText: Style.ncTextColor
light: Style.lightHover
midlight: Style.ncSecondaryTextColor
mid: Style.darkerHover
dark: Style.menuBorder
button: Style.buttonBackgroundColor
window: palette.dark // NOTE: Fusion theme uses darker window colour for the border of the checkbox
base: Style.backgroundColor
toolTipBase: Style.backgroundColor
toolTipText: Style.ncTextColor
}

spacing: scrollContentsColumn.indicatorSpacing
padding: scrollContentsColumn.itemPadding
indicator.width: scrollContentsColumn.indicatorItemWidth
indicator.height: scrollContentsColumn.indicatorItemWidth

checkable: true
checked: root.resharingAllowed
text: qsTr("Allow resharing")
enabled: !root.isSharePermissionChangeInProgress && root.serverAllowsResharing
visible: root.serverAllowsResharing
onClicked: root.toggleAllowResharing(checked);

Connections {
target: root
onResharingAllowedChanged: allowResharingCheckBox.checked = root.resharingAllowed
}
}
}

NCBusyIndicator {
anchors.fill: parent
visible: root.isSharePermissionChangeInProgress
running: visible
z: 1
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/filedetails/ShareView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ColumnLayout {
readonly property bool sharingPossible: shareModel && shareModel.canShare && shareModel.sharingEnabled
readonly property bool userGroupSharingPossible: sharingPossible && shareModel.userGroupSharingEnabled
readonly property bool publicLinkSharingPossible: sharingPossible && shareModel.publicLinkSharesEnabled
readonly property bool serverAllowsResharing: shareModel && shareModel.serverAllowsResharing

readonly property bool loading: sharingPossible && (!shareModel ||
shareModel.fetchOngoing ||
Expand Down Expand Up @@ -214,6 +215,7 @@ ColumnLayout {
rootStackView: root.rootStackView
backgroundsVisible: root.backgroundsVisible
canCreateLinkShares: root.publicLinkSharingPossible
serverAllowsResharing: root.serverAllowsResharing

onCreateNewLinkShare: {
root.waitingForSharesToChange = true;
Expand Down
11 changes: 11 additions & 0 deletions src/gui/filedetails/sharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "account.h"
#include "folderman.h"
#include "sharepermissions.h"
#include "theme.h"

namespace {
Expand Down Expand Up @@ -141,6 +142,7 @@ QHash<int, QByteArray> ShareModel::roleNames() const
roles[IsSharePermissionsChangeInProgress] = "isSharePermissionChangeInProgress";
roles[HideDownloadEnabledRole] = "hideDownload";
roles[IsHideDownloadEnabledChangeInProgress] = "isHideDownloadInProgress";
roles[ResharingAllowedRole] = "resharingAllowed";

return roles;
}
Expand Down Expand Up @@ -241,6 +243,8 @@ QVariant ShareModel::data(const QModelIndex &index, const int role) const
|| (share->getShareType() == Share::TypeLink && _accountState->account()->capabilities().sharePublicLinkEnforcePassword()));
case EditingAllowedRole:
return share->getPermissions().testFlag(SharePermissionUpdate);
case ResharingAllowedRole:
return share->getPermissions().testFlag(SharePermissionShare);

// Deal with roles that only return certain values for link or user/group share types
case NoteEnabledRole:
Expand Down Expand Up @@ -1247,6 +1251,7 @@ void ShareModel::setAccountState(AccountState *accountState)
Q_EMIT sharingEnabledChanged();
Q_EMIT publicLinkSharesEnabledChanged();
Q_EMIT userGroupSharingEnabledChanged();
Q_EMIT serverAllowsResharingChanged();
updateData();
}

Expand Down Expand Up @@ -1306,6 +1311,12 @@ bool ShareModel::canShare() const
return _maxSharingPermissions & SharePermissionShare;
}

bool ShareModel::serverAllowsResharing() const
{
return _accountState && _accountState->account() && _accountState->account()->capabilities().isValid()
&& _accountState->account()->capabilities().shareResharing();
}

QVariantList ShareModel::sharees() const
{
QVariantList returnSharees;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/filedetails/sharemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ShareModel : public QAbstractListModel
Q_PROPERTY(bool canShare READ canShare NOTIFY sharePermissionsChanged)
Q_PROPERTY(bool fetchOngoing READ fetchOngoing NOTIFY fetchOngoingChanged)
Q_PROPERTY(bool hasInitialShareFetchCompleted READ hasInitialShareFetchCompleted NOTIFY hasInitialShareFetchCompletedChanged)
Q_PROPERTY(bool serverAllowsResharing READ serverAllowsResharing NOTIFY serverAllowsResharingChanged)
Q_PROPERTY(QVariantList sharees READ sharees NOTIFY shareesChanged)

public:
Expand Down Expand Up @@ -62,6 +63,7 @@ class ShareModel : public QAbstractListModel
IsSharePermissionsChangeInProgress,
HideDownloadEnabledRole,
IsHideDownloadEnabledChangeInProgress,
ResharingAllowedRole,
};
Q_ENUM(Roles)

Expand Down Expand Up @@ -115,6 +117,7 @@ class ShareModel : public QAbstractListModel
[[nodiscard]] bool publicLinkSharesEnabled() const;
[[nodiscard]] bool userGroupSharingEnabled() const;
[[nodiscard]] bool canShare() const;
[[nodiscard]] bool serverAllowsResharing() const;

[[nodiscard]] bool fetchOngoing() const;
[[nodiscard]] bool hasInitialShareFetchCompleted() const;
Expand All @@ -134,6 +137,7 @@ class ShareModel : public QAbstractListModel
void hasInitialShareFetchCompletedChanged();
void shareesChanged();
void internalLinkReady();
void serverAllowsResharingChanged();

void serverError(const int code, const QString &message);
void passwordSetError(const QString &shareId, const int code, const QString &message);
Expand Down
6 changes: 3 additions & 3 deletions src/gui/sharemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ void ShareManager::createShare(const QString &path,
connect(job, &OcsShareJob::shareJobFinished, this,
[=](const QJsonDocument &reply) {
// Find existing share permissions (if this was shared with us)
Share::Permissions existingPermissions = SharePermissionDefault;
Share::Permissions existingPermissions = SharePermissionAll;
foreach (const QJsonValue &element, reply.object()["ocs"].toObject()["data"].toArray()) {
auto map = element.toObject();
if (map["file_target"] == path)
Expand All @@ -471,10 +471,10 @@ void ShareManager::createShare(const QString &path,
// Limit the permissions we request for a share to the ones the item
// was shared with initially.
auto validPermissions = desiredPermissions;
if (validPermissions == SharePermissionDefault) {
if (validPermissions == SharePermissionAll) {
validPermissions = existingPermissions;
}
if (existingPermissions != SharePermissionDefault) {
if (existingPermissions != SharePermissionAll) {
validPermissions &= existingPermissions;
}

Expand Down
16 changes: 8 additions & 8 deletions src/gui/sharemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ class Share : public QObject
* Constructor for shares
*/
explicit Share(AccountPtr account,
const QString &id,
const QString &owner,
const QString &ownerDisplayName,
const QString &path,
const ShareType shareType,
bool isPasswordSet = false,
const Permissions permissions = SharePermissionDefault,
const ShareePtr shareWith = ShareePtr(nullptr));
const QString &id,
const QString &owner,
const QString &ownerDisplayName,
const QString &path,
const ShareType shareType,
bool isPasswordSet = false,
const Permissions permissions = SharePermissionAll,
const ShareePtr shareWith = ShareePtr(nullptr));

/**
* The account the share is defined on.
Expand Down
12 changes: 6 additions & 6 deletions src/gui/sharepermissions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ namespace OCC {
* Possible permissions, must match the server permission constants
*/
enum SharePermission {
SharePermissionRead = 1 << 0,
SharePermissionUpdate = 1 << 1,
SharePermissionCreate = 1 << 2,
SharePermissionDelete = 1 << 3,
SharePermissionShare = 1 << 4,
SharePermissionDefault = 1 << 30
claucambra marked this conversation as resolved.
Show resolved Hide resolved
SharePermissionRead = 1,
SharePermissionUpdate = 1 << 1,
SharePermissionCreate = 1 << 2,
SharePermissionDelete = 1 << 3,
SharePermissionShare = 1 << 4,
SharePermissionAll = 31,
};
Q_DECLARE_FLAGS(SharePermissions, SharePermission)
Q_DECLARE_OPERATORS_FOR_FLAGS(SharePermissions)
Expand Down
Loading