fix(permissions): fix hang when all channel perm check return (#14259)
* 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>
2024-04-04 15:26:44 +00:00
import QtQuick 2.15
import QtQuick . Layouts 1.15
2022-11-25 17:35:30 +00:00
fix(permissions): fix hang when all channel perm check return (#14259)
* 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>
2024-04-04 15:26:44 +00:00
import StatusQ 0.1
2024-02-06 09:31:36 +00:00
import StatusQ . Controls 0.1
fix(permissions): fix hang when all channel perm check return (#14259)
* 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>
2024-04-04 15:26:44 +00:00
import StatusQ . Core 0.1
2022-11-25 17:35:30 +00:00
import SortFilterProxyModel 0.2
2024-02-06 09:31:36 +00:00
import shared . status 1.0
2022-11-24 16:23:54 +00:00
import shared . popups 1.0
2023-06-29 11:54:04 +00:00
import utils 1.0
2022-11-25 17:35:30 +00:00
2023-06-23 06:17:04 +00:00
import AppLayouts . Communities . controls 1.0
2023-06-29 11:54:04 +00:00
import AppLayouts . Communities . panels 1.0
2022-11-25 17:35:30 +00:00
2024-02-06 09:31:36 +00:00
ColumnLayout {
2022-11-25 17:35:30 +00:00
id: root
2024-02-06 09:31:36 +00:00
width: root . viewWidth
property int topPadding: count ? 16 : 0
spacing: 24
QtObject {
id: d
property int permissionIndexToRemove
}
2022-11-25 17:35:30 +00:00
2023-03-07 08:47:04 +00:00
required property var permissionsModel
required property var assetsModel
required property var collectiblesModel
required property var channelsModel
2023-06-29 07:37:49 +00:00
// id, name, image, color, owner, admin properties expected
2024-05-30 13:52:28 +00:00
required property QtObject communityDetails
2023-02-22 17:51:49 +00:00
2022-11-25 17:35:30 +00:00
property int viewWidth: 560 // by design
2024-02-06 09:31:36 +00:00
property bool viewOnlyCanAddReaction
property bool showChannelOptions: false
property bool allowIntroPanel: true
2022-11-25 17:35:30 +00:00
2023-02-10 22:40:07 +00:00
signal editPermissionRequested ( int index )
signal duplicatePermissionRequested ( int index )
signal removePermissionRequested ( int index )
2024-02-06 09:31:36 +00:00
signal userRestrictionsToggled ( bool checked )
2022-11-24 16:23:54 +00:00
2024-09-27 17:28:27 +00:00
readonly property alias count: listView . count
2024-02-06 09:31:36 +00:00
2024-05-30 13:52:28 +00:00
Connections {
target: root . communityDetails
function onNameChanged ( ) {
resetCommunityItemModel ( )
}
function onImageChanged ( ) {
resetCommunityItemModel ( )
2024-02-06 09:31:36 +00:00
}
2024-05-30 13:52:28 +00:00
function onColorChanged ( ) {
resetCommunityItemModel ( )
}
}
2024-09-27 17:28:27 +00:00
function resetCommunityItemModel ( ) {
2024-05-30 13:52:28 +00:00
communityItemModel . clear ( )
communityItemModel . append ( {
text: root . communityDetails . name ,
imageSource: root . communityDetails . image ,
color: root . communityDetails . color
} )
}
ListModel {
id: communityItemModel
Component.onCompleted: resetCommunityItemModel ( )
2024-02-06 09:31:36 +00:00
}
2023-06-29 11:54:04 +00:00
2024-02-06 09:31:36 +00:00
IntroPanel {
Layout.fillWidth: true
2023-06-29 22:05:46 +00:00
2024-02-06 09:31:36 +00:00
visible: ( root . count === 0 && root . allowIntroPanel )
2023-01-18 19:54:14 +00:00
2024-02-06 09:31:36 +00:00
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" )
]
2022-11-24 16:23:54 +00:00
}
2024-09-27 17:28:27 +00:00
StatusListView {
id: listView
reuseItems: true
2024-02-06 09:31:36 +00:00
model: root . permissionsModel
2024-09-27 17:28:27 +00:00
spacing: 24
Layout.fillWidth: true
Layout.fillHeight: true
Layout.preferredHeight: contentHeight
Layout.topMargin: root . topPadding
2023-01-27 09:22:04 +00:00
2024-02-06 09:31:36 +00:00
delegate: PermissionItem {
2024-09-27 17:28:27 +00:00
width: root . viewWidth
2023-06-29 22:05:46 +00:00
2024-02-06 09:31:36 +00:00
holdingsListModel: HoldingsSelectionModel {
sourceModel: model . holdingsListModel
assetsModel: root . assetsModel
collectiblesModel: root . collectiblesModel
}
2023-02-11 19:03:57 +00:00
2024-02-06 09:31:36 +00:00
permissionType: model . permissionType
permissionState: model . permissionState // TODO: Backend!
2023-01-27 09:22:04 +00:00
fix(permissions): fix hang when all channel perm check return (#14259)
* 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>
2024-04-04 15:26:44 +00:00
LeftJoinModel {
2024-02-06 09:31:36 +00:00
id: channelsSelectionModel
2023-01-27 09:22:04 +00:00
fix(permissions): fix hang when all channel perm check return (#14259)
* 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>
2024-04-04 15:26:44 +00:00
leftModel: model . channelsListModel ? ? null
rightModel: root . channelsModel
joinRole: "key"
2024-02-06 09:31:36 +00:00
}
2023-01-27 09:22:04 +00:00
fix(permissions): fix hang when all channel perm check return (#14259)
* 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>
2024-04-04 15:26:44 +00:00
channelsListModel: model . channelsListModel . rowCount ( )
2024-02-06 09:31:36 +00:00
? channelsSelectionModel : communityItemModel
isPrivate: model . isPrivate
2022-11-25 17:35:30 +00:00
2024-02-06 09:31:36 +00:00
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 ) ) )
2023-06-14 16:00:41 +00:00
2024-02-06 09:31:36 +00:00
onEditClicked: root . editPermissionRequested ( model . index )
onDuplicateClicked: root . duplicatePermissionRequested ( model . index )
2023-01-27 09:22:04 +00:00
2024-02-06 09:31:36 +00:00
onRemoveClicked: {
d . permissionIndexToRemove = index
declineAllDialog . open ( )
2022-11-25 17:35:30 +00:00
}
}
}
2022-11-24 16:23:54 +00:00
2024-02-06 09:31:36 +00:00
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
2024-03-13 19:13:41 +00:00
visible: root . showChannelOptions
2024-02-06 09:31:36 +00:00
title: qsTr ( "Users with view only permissions can add reactions" )
icon: "emojis"
checked: root . viewOnlyCanAddReaction
onToggled: {
root . userRestrictionsToggled ( checked ) ;
}
}
2024-09-27 17:28:27 +00:00
2023-02-10 22:40:07 +00:00
ConfirmationDialog {
id: declineAllDialog
2023-05-23 12:46:16 +00:00
headerSettings.title: qsTr ( "Sure you want to delete permission" )
2023-02-15 23:04:24 +00:00
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." )
2023-02-10 22:40:07 +00:00
onConfirmButtonClicked: {
root . removePermissionRequested ( d . permissionIndexToRemove )
close ( )
2022-11-24 16:23:54 +00:00
}
}
2022-11-25 17:35:30 +00:00
}