This is an automated email from the ASF dual-hosted git repository.

andytaylor pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis-console.git

commit 30346405ac7f53839abf70b439d562e702baba2b
Author: GChuf <[email protected]>
AuthorDate: Tue Sep 2 09:15:44 2025 +0200

    ARTEMIS-5424 - get queuePermissions only once
---
 .../artemis-console-plugin/src/artemis-service.ts  |  35 ++++
 .../src/queues/QueuesTable.tsx                     | 178 ++++++++++++---------
 .../src/table/ArtemisTable.tsx                     |   6 +-
 3 files changed, 137 insertions(+), 82 deletions(-)

diff --git 
a/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/artemis-service.ts
 
b/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/artemis-service.ts
index c6f8d5b..b5e5d9f 100644
--- 
a/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/artemis-service.ts
+++ 
b/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/artemis-service.ts
@@ -111,6 +111,13 @@ export type BrokerTopology = {
 
 }
 
+export type queuePermissions = {
+  canSend: boolean;
+  canBrowse: boolean;
+  canPurge: boolean;
+  canDelete: boolean;
+}
+
 const LIST_NETWORK_TOPOLOGY_SIG = "listNetworkTopology";
 const SEND_MESSAGE_SIG = 
"sendMessage(java.util.Map,int,java.lang.String,boolean,java.lang.String,java.lang.String,boolean)";
 const DELETE_ADDRESS_SIG = "deleteAddress(java.lang.String)";
@@ -560,6 +567,7 @@ class ArtemisService {
     }
 
     private DEBUG_PRIVS = true;
+
     canCreateQueue = (broker: MBeanNode | undefined): boolean => {
         return (this.DEBUG_PRIVS && broker?.hasInvokeRights(CREATE_QUEUE_SIG)) 
?? false
     }
@@ -624,6 +632,33 @@ class ArtemisService {
         return false;
     }
 
+    getQueuePermissions = (broker: MBeanNode | undefined): Record<string, 
queuePermissions> => {
+        const queuePermissionsMap: Record<string, queuePermissions> = {};
+
+        if (broker?.parent) {
+
+            const collectQueues = (node: MBeanNode) => {
+                if (node.propertyList?.get("subcomponent") === "queues") {
+                queuePermissionsMap[node.name] = {
+                    canSend: node.hasInvokeRights(SEND_MESSAGE_SIG) ?? false,
+                    canPurge: node.hasInvokeRights(REMOVE_ALL_MESSAGES_SIG) ?? 
false,
+                    canBrowse: node.hasInvokeRights(BROWSE_SIG) ?? false,
+                    canDelete: node.hasInvokeRights(DELETE_ADDRESS_SIG) ?? 
false
+                };
+            }
+
+            // Recurse into children if they exist
+            if (node.children?.length) {
+                node.children.forEach(child => collectQueues(child));
+                }
+            };
+
+            collectQueues(broker.parent);
+            return queuePermissionsMap;
+        }
+        return queuePermissionsMap;
+    };
+
     checkCanBrowseQueue = (queueMBean: MBeanNode ): boolean => {
         return (this.DEBUG_PRIVS && queueMBean?.hasInvokeRights(BROWSE_SIG)) 
?? false;
     }
diff --git 
a/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/queues/QueuesTable.tsx
 
b/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/queues/QueuesTable.tsx
index c99c74e..2dcd445 100644
--- 
a/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/queues/QueuesTable.tsx
+++ 
b/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/queues/QueuesTable.tsx
@@ -27,6 +27,13 @@ import { createQueueObjectName } from '../util/jmx';
 import { useNavigate } from 'react-router-dom';
 import { columnStorage } from '../artemis-preferences-service';
 
+export type queuePermissions = {
+  canSend: boolean;
+  canBrowse: boolean;
+  canPurge: boolean;
+  canDelete: boolean;
+}
+
 export const QueuesTable: React.FunctionComponent<QueueNavigate> = navigate => 
{
   const getAddressFilter = (row: any) => {
     var filter: Filter = {
@@ -160,99 +167,112 @@ export const QueuesTable: 
React.FunctionComponent<QueueNavigate> = navigate => {
       });
   };
 
-  const getRowActions = (row: any, rowIndex: number): IAction[] => {
-    var actions: IAction[] =  [
-      {
-        title: 'Show in Artemis JMX',
-        onClick: async () => {
-          setAddress(row.name);
-          const brokerObjectName = await artemisService.getBrokerObjectName();
-          const queueObjectName = 
createQueueObjectName(brokerObjectName,row.address, row.routingType,  row.name);
-          findAndSelectNode(queueObjectName, row.name);
-          routenavigate('/treeartemisJMX')
-        }
-      },
-      {
-        title: 'Attributes',
-        onClick: async () => {
-          setAddress(row.name);
-          const brokerObjectName = await artemisService.getBrokerObjectName();
-          const queueObjectName = 
createQueueObjectName(brokerObjectName,row.address, row.routingType,  row.name);
-          findAndSelectNode(queueObjectName, row.name);
-          setShowAttributesDialog(true);
-        }
-      },
-      {
-        title: 'Operations',
-        onClick: async () => {
-          setAddress(row.name);
-          const brokerObjectName = await artemisService.getBrokerObjectName();
-          const queueObjectName = 
createQueueObjectName(brokerObjectName,row.address, row.routingType,  row.name);
-          findAndSelectNode(queueObjectName, row.name);
-          setShowOperationsDialog(true);
-        }
-      }
-    ]
-
+  const showInJmxAction = (rowName: string, rowAddress: string, 
rowRoutingType: string): IAction => ({
+    title: "Show in Artemis JMX",
+    onClick: async () => {
+      setAddress(rowName);
+      const brokerObjectName = await artemisService.getBrokerObjectName();
+      const queueObjectName = createQueueObjectName(brokerObjectName, 
rowAddress, rowRoutingType, rowName);
+      findAndSelectNode(queueObjectName, rowName);
+      routenavigate("/treeartemisJMX");
+    }
+  });
 
-    if (canDeleteQueue) {
-      actions.push(
-        {
-          title: 'Delete',
-          onClick: () => {
-            setQueue(row.name);
-            setShowDeleteDialog(true);
-          }
-        }
+  const attributesAction = (rowName: string, rowAddress: string, 
rowRoutingType: string) => ({
+    title: "Attributes",
+    onClick: async () => {
+      setAddress(rowName);
+      const brokerObjectName = await artemisService.getBrokerObjectName();
+      const queueObjectName = createQueueObjectName(
+        brokerObjectName,
+        rowAddress,
+        rowRoutingType,
+        rowName
       );
+      findAndSelectNode(queueObjectName, rowName);
+      setShowAttributesDialog(true);
     }
+  });
 
-    var canSendMessage = artemisService.canSendMessageToQueue(brokerNode, 
row.name);
-    if (canSendMessage) {
-      actions.push(
-        {
-          title: 'Send Message',
-          onClick: () => {
-            setQueue(row.name);
-            setAddress(row.address);
-            setRoutingType(row.routingType)
-            setShowSendDialog(true);
-          }
-
-        }
+  const operationsAction = (rowName: string, rowAddress: string, 
rowRoutingType: string): IAction => ({
+    title: "Operations",
+    onClick: async () => {
+      setAddress(rowName);
+      const brokerObjectName = await artemisService.getBrokerObjectName();
+      const queueObjectName = createQueueObjectName(
+        brokerObjectName,
+        rowAddress,
+        rowRoutingType,
+        rowName
       );
+      findAndSelectNode(queueObjectName, rowName);
+      setShowOperationsDialog(true);
     }
+  });
 
-    var canPurgeQueue = artemisService.canPurgeQueue(brokerNode, row.name);
-    if (canPurgeQueue) {
-      actions.push(
-        {
-          title: 'Purge',
-          onClick: () => {
-            setQueue(row.name);
-            setQueueToPurgeAddress(row.address);
-            setQueueToPurgeRoutingType(row.routingType);
-            setShowPurgeDialog(true);
-          }
-        }
-      );
+  const deleteAction = (rowname: string): IAction => ({
+    title: "Delete",
+    onClick: () => {
+      setQueue(rowname);
+      setShowDeleteDialog(true);
     }
+  });
 
-    var canBrowseQueue = artemisService.canBrowseQueue(brokerNode, row.name);
-    if (canBrowseQueue) {
-      actions.push(
-        {
-          title: 'Browse Messages',
-          onClick: () => {
-            navigate.selectQueue(row.name, row.address, row.routingType);
-          }
+  const sendMessageAction = (rowName: string, rowAddress: string, 
rowRoutingType: string): IAction => ({
+    title: "Send Message",
+    onClick: () => {
+      setQueue(rowName);
+      setAddress(rowAddress);
+      setRoutingType(rowRoutingType);
+      setShowSendDialog(true);
+    }
+  });
 
-        }
-      );
+  const purgeAction = (rowName: string, rowAddress: string, rowRoutingType: 
string): IAction => ({
+    title: "Purge",
+    onClick: () => {
+      setQueue(rowName);
+      setQueueToPurgeAddress(rowAddress);
+      setQueueToPurgeRoutingType(rowRoutingType);
+      setShowPurgeDialog(true);
     }
+  });
 
+  const browseAction = (rowName: string, rowAddress: string, rowRoutingType: 
string): IAction => ({
+    title: "Browse Messages",
+    onClick: () => {
+      navigate.selectQueue(rowName, rowAddress, rowRoutingType);
+    }
+  });
+
+  const permissions = artemisService.getQueuePermissions(brokerNode);
+
+  const getRowActions = (row: any): IAction[] => {
+    const rowName = row.name;
+    const rowAddress = row.address;
+    const rowRoutingType = row.routingType;
+    const rowPerms = permissions[rowName];
+    const actions: IAction[] = [
+      showInJmxAction(rowName, rowAddress, rowRoutingType),
+      attributesAction(rowName, rowAddress, rowRoutingType),
+      operationsAction(rowName, rowAddress, rowRoutingType)
+    ];
+
+  if (rowPerms?.canSend) {
+    actions.push(sendMessageAction(rowName, rowAddress, rowRoutingType));
+  }
+  if (rowPerms?.canPurge) {
+    actions.push(purgeAction(rowName, rowAddress, rowRoutingType));
+  }
+  if (rowPerms?.canBrowse) {
+    actions.push(browseAction(rowName, rowAddress, rowRoutingType));
+  }
+  if (rowPerms?.canDelete) {
+    actions.push(deleteAction(rowName));
+  }
 
     return actions;
+
   };
 
   return (
diff --git 
a/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/table/ArtemisTable.tsx
 
b/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/table/ArtemisTable.tsx
index 050476c..11727d4 100644
--- 
a/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/table/ArtemisTable.tsx
+++ 
b/artemis-console-extension/artemis-extension/packages/artemis-console-plugin/src/table/ArtemisTable.tsx
@@ -201,9 +201,9 @@ const operationOptions = [
     sessionStorage.setItem(broker.storageColumnLocation + 
".activesort",JSON.stringify(updatedActiveSort));
   }
 
-  const getRowActions = (row: never, rowIndex: number): IAction[] => {
+  const getRowActions = (row: never): IAction[] => {
     if (broker.getRowActions) {
-      return broker.getRowActions(row, rowIndex);
+      return broker.getRowActions(row);
     }
     return [];
   };
@@ -433,7 +433,7 @@ const operationOptions = [
                 })}
                 <Td isActionCell>
                   <ActionsColumn
-                    items={getRowActions(row, rowIndex)}
+                    items={getRowActions(row)}
                     popperProps={{ position: 'right', appendTo: () => 
(document.getElementById('root') as HTMLElement) }}
                   />
                 </Td>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to