mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-11 23:05:17 +00:00
5c75c265af
* fix(permissions): fix hang when all channel perm check return Fixes #14234 The problem was that we updated **all** the models from **all** the channels of a community each time the channel requirement checks returned. The fix is to first of all, make sure we don't call that check too often. It sometimes got called twice in a row by accident. The other better fix is to check if anything actually changed before updating. This solves the issue almost entirely. Since the permissions almost never change, the updates now take only a second. * fix(permisisons): never run permission checks for privileged users Also fixes #14234 but for admins, TMs and Owners. Admins+ were still getting the hang, because the permission checks always returned something different than the models, because the models knew that admins have access to everything, but the permission check was running as if it were a normal user (I think, un-tested). Anyway, the solution is more simple, we never need to run the permission checks on admins+, because they always have access to everything! * fix(Communities): prevent channels model from emitting unnecessary signals Closes: #14274 * chore(Communities): improve channels metadata lookup performance ChannelsSelectionModel is removed, replaced with plain LeftJoinModel. Transformations of left-side model are done in a single place, not in every delegate making the join. * only call update functions when there is something to update + move permission model creation when needed --------- Co-authored-by: Michał Cieślak <michalcieslak@status.im>
154 lines
4.8 KiB
QML
154 lines
4.8 KiB
QML
import QtQuick 2.15
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import StatusQ 0.1
|
|
import StatusQ.Controls 0.1
|
|
import StatusQ.Core 0.1
|
|
|
|
import SortFilterProxyModel 0.2
|
|
import shared.status 1.0
|
|
import shared.popups 1.0
|
|
import utils 1.0
|
|
|
|
import AppLayouts.Communities.controls 1.0
|
|
import AppLayouts.Communities.panels 1.0
|
|
|
|
ColumnLayout {
|
|
id: root
|
|
width: root.viewWidth
|
|
property int topPadding: count ? 16 : 0
|
|
spacing: 24
|
|
|
|
QtObject {
|
|
id: d
|
|
|
|
property int permissionIndexToRemove
|
|
}
|
|
|
|
required property var permissionsModel
|
|
required property var assetsModel
|
|
required property var collectiblesModel
|
|
required property var channelsModel
|
|
|
|
// id, name, image, color, owner, admin properties expected
|
|
required property var communityDetails
|
|
|
|
property int viewWidth: 560 // by design
|
|
property bool viewOnlyCanAddReaction
|
|
property bool showChannelOptions: false
|
|
property bool allowIntroPanel: true
|
|
|
|
signal editPermissionRequested(int index)
|
|
signal duplicatePermissionRequested(int index)
|
|
signal removePermissionRequested(int index)
|
|
signal userRestrictionsToggled(bool checked)
|
|
|
|
readonly property alias count: repeater.count
|
|
ListModel {
|
|
id: communityItemModel
|
|
|
|
Component.onCompleted: {
|
|
append({
|
|
text: root.communityDetails.name,
|
|
imageSource: root.communityDetails.image,
|
|
color: root.communityDetails.color
|
|
})
|
|
}
|
|
}
|
|
|
|
IntroPanel {
|
|
Layout.fillWidth: true
|
|
|
|
visible: (root.count === 0 && root.allowIntroPanel)
|
|
|
|
image: Style.png("community/permissions2_3")
|
|
title: qsTr("Permissions")
|
|
subtitle: qsTr("You can manage your community by creating and issuing membership and access permissions")
|
|
checkersModel: [
|
|
qsTr("Give individual members access to private channels"),
|
|
qsTr("Monetise your community with subscriptions and fees"),
|
|
qsTr("Require holding a token or NFT to obtain exclusive membership rights")
|
|
]
|
|
}
|
|
|
|
|
|
Repeater {
|
|
id: repeater
|
|
|
|
model: root.permissionsModel
|
|
|
|
delegate: PermissionItem {
|
|
Layout.fillWidth: true
|
|
|
|
holdingsListModel: HoldingsSelectionModel {
|
|
sourceModel: model.holdingsListModel
|
|
assetsModel: root.assetsModel
|
|
collectiblesModel: root.collectiblesModel
|
|
}
|
|
|
|
permissionType: model.permissionType
|
|
permissionState: model.permissionState // TODO: Backend!
|
|
|
|
LeftJoinModel {
|
|
id: channelsSelectionModel
|
|
|
|
leftModel: model.channelsListModel ?? null
|
|
rightModel: root.channelsModel
|
|
joinRole: "key"
|
|
}
|
|
|
|
channelsListModel: model.channelsListModel.rowCount()
|
|
? channelsSelectionModel : communityItemModel
|
|
isPrivate: model.isPrivate
|
|
|
|
showButtons: (model.permissionType !== PermissionTypes.Type.TokenMaster &&
|
|
model.permissionType !== PermissionTypes.Type.Owner) &&
|
|
(!!root.communityDetails && (root.communityDetails.owner ||
|
|
((root.communityDetails.admin || root.communityDetails.tokenMaster) && model.permissionType !== PermissionTypes.Type.Admin)))
|
|
|
|
onEditClicked: root.editPermissionRequested(model.index)
|
|
onDuplicateClicked: root.duplicatePermissionRequested(model.index)
|
|
|
|
onRemoveClicked: {
|
|
d.permissionIndexToRemove = index
|
|
declineAllDialog.open()
|
|
}
|
|
}
|
|
}
|
|
|
|
StatusBaseText {
|
|
id: noPermissionsLabel
|
|
Layout.fillWidth: true
|
|
Layout.fillHeight: true
|
|
visible: (root.count === 0 && root.showChannelOptions)
|
|
horizontalAlignment: Text.AlignHCenter
|
|
verticalAlignment: Text.AlignVCenter
|
|
text: qsTr("No channel permissions")
|
|
color: Style.current.secondaryText
|
|
}
|
|
|
|
StatusIconSwitch {
|
|
Layout.fillWidth: true
|
|
padding: 0
|
|
|
|
visible: root.showChannelOptions
|
|
title: qsTr("Users with view only permissions can add reactions")
|
|
icon: "emojis"
|
|
checked: root.viewOnlyCanAddReaction
|
|
onToggled: {
|
|
root.userRestrictionsToggled(checked);
|
|
}
|
|
}
|
|
ConfirmationDialog {
|
|
id: declineAllDialog
|
|
|
|
headerSettings.title: qsTr("Sure you want to delete permission")
|
|
confirmationText: qsTr("If you delete this permission, any of your community members who rely on this permission will lose the access this permission gives them.")
|
|
|
|
onConfirmButtonClicked: {
|
|
root.removePermissionRequested(d.permissionIndexToRemove)
|
|
close()
|
|
}
|
|
}
|
|
}
|