From 83834301fa8404bc93a380a8b3c7cff58203f019 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 17 Jun 2022 10:00:43 -0400
Subject: [PATCH] swarmdetailspanel: make profile in readonly if not enough
 authorization

Change-Id: Ia7d17f72d4de82482187d9f0f945af9024d2c242
GitLab: #737
---
 src/app/commoncomponents/EditableLineEdit.qml     | 11 ++++++-----
 src/app/commoncomponents/PhotoboothView.qml       |  6 +++---
 src/app/mainview/components/SwarmDetailsPanel.qml |  5 ++++-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/app/commoncomponents/EditableLineEdit.qml b/src/app/commoncomponents/EditableLineEdit.qml
index ff262cfb9..2d2fa6c0b 100644
--- a/src/app/commoncomponents/EditableLineEdit.qml
+++ b/src/app/commoncomponents/EditableLineEdit.qml
@@ -41,6 +41,7 @@ Item {
     property var editIconColor:  UtilsAdapter.luma(root.color) ? JamiTheme.editLineColor : "white"
     property var cancelIconColor: UtilsAdapter.luma(root.color) ? JamiTheme.buttonTintedBlue : "white"
 
+    property bool readOnly: false
     property bool editable: false
     property bool hovered: false
     property string tooltipText: ""
@@ -71,7 +72,7 @@ Item {
 
         Image {
             id: editImg
-            opacity: editable
+            opacity: editable && !root.readOnly
 
             Layout.alignment: Qt.AlignVCenter
 
@@ -95,7 +96,7 @@ Item {
         MaterialLineEdit {
             id: lineEdit
 
-            readOnly: !editable
+            readOnly: !editable || root.readOnly
             underlined: true
 
             borderColor: root.editIconColor
@@ -127,9 +128,9 @@ Item {
 
             Layout.alignment: Qt.AlignVCenter
 
-            enabled: editable
+            enabled: editable && !root.readOnly
             preferredSize: lineEdit.height * 2 / 3
-            opacity: editable ? 0.8 : 0
+            opacity: enabled ? 0.8 : 0
             imageColor: root.cancelIconColor
             normalColor: "transparent"
             hoveredColor: JamiTheme.hoveredButtonColor
@@ -155,7 +156,7 @@ Item {
         anchors.fill: row
         radius: JamiTheme.primaryRadius
 
-        visible: root.editable || root.hovered
+        visible: (root.editable || root.hovered)  && !root.readOnly
         color: root.editIconColor
 
         Rectangle {
diff --git a/src/app/commoncomponents/PhotoboothView.qml b/src/app/commoncomponents/PhotoboothView.qml
index f31b84a2c..8a7061ed0 100644
--- a/src/app/commoncomponents/PhotoboothView.qml
+++ b/src/app/commoncomponents/PhotoboothView.qml
@@ -32,7 +32,7 @@ Item {
 
     property alias imageId: avatar.imageId
     property bool newConversation: false
-    property bool editable: true
+    property bool readOnly: false
     property real avatarSize
     property real buttonSize: avatarSize
     property bool darkTheme: false
@@ -140,7 +140,7 @@ Item {
 
             HoverHandler {
                 target: parent
-                enabled: parent.visible && editable
+                enabled: parent.visible && !root.readOnly
                 onHoveredChanged: {
                     overlayHighlighted.visible = hovered
                 }
@@ -148,7 +148,7 @@ Item {
 
             TapHandler {
                 target: parent
-                enabled: parent.visible && editable
+                enabled: parent.visible && !root.readOnly
                 onTapped: {
                     imageLayer.visible = false
                     buttonsRowLayout.visible = true
diff --git a/src/app/mainview/components/SwarmDetailsPanel.qml b/src/app/mainview/components/SwarmDetailsPanel.qml
index ddb109884..f8035af9a 100644
--- a/src/app/mainview/components/SwarmDetailsPanel.qml
+++ b/src/app/mainview/components/SwarmDetailsPanel.qml
@@ -32,6 +32,7 @@ Rectangle {
     id: root
 
     color: CurrentConversation.color
+    property var isAdmin: UtilsAdapter.getParticipantRole(CurrentAccount.id, CurrentConversation.id, CurrentAccount.uri) === Member.Role.ADMIN
 
     ColumnLayout {
         id: swarmProfileDetails
@@ -48,7 +49,7 @@ Rectangle {
             PhotoboothView {
                 id: currentAccountAvatar
                 darkTheme: UtilsAdapter.luma(root.color)
-                editable: UtilsAdapter.getParticipantRole(CurrentAccount.id, CurrentConversation.id, CurrentAccount.uri) === Member.Role.ADMIN
+                readOnly: !root.isAdmin
 
                 Layout.alignment: Qt.AlignHCenter
 
@@ -68,6 +69,7 @@ Rectangle {
                 verticalAlignment: Text.AlignVCenter
 
                 text: CurrentConversation.title
+                readOnly: !root.isAdmin
                 placeholderText: JamiStrings.swarmName
                 placeholderTextColor: {
                     if (editable) {
@@ -106,6 +108,7 @@ Rectangle {
                 verticalAlignment: Text.AlignVCenter
 
                 text: CurrentConversation.description
+                readOnly: !root.isAdmin
                 placeholderText: JamiStrings.addADescription
                 placeholderTextColor: {
                     if (editable) {
-- 
GitLab