Repository: provectus/kafka-ui
Issue: Clear messages should not be present when in readonly mode
Labels: type/bug
scope/frontend

**Describe the bug**
I'm currently using the master branch image (Version:v0.0.11-SNAPSHOT(1377e02)) and I configured the readonly mode.
However, when I browse a topic, on "Overview" tab, I can see I can clear messages from a partition.

I'm not sure that should be allowed 

**Set up**
`docker run -p 8080:8080 -e KAFKA_CLUSTERS_0_NAME=whatever -e KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=servers:9092 -e KAFKA_CLUSTERS_0_READONLY=true -d provectuslabs/kafka-ui:master`


**Expected behavior**
When in readonly mode, I shouldn't be able to modify anything.

**Screenshots**
![image](https://user-images.githubusercontent.com/29728596/119101347-2c976480-ba19-11eb-8523-dfb432ae602c.png)



Issue comments:
I just notice that it also appears on "All topics" screen, as well as "Delete Topic". 
Let me know if leaving that in this issue is ok or if I may create another one.
![image](https://user-images.githubusercontent.com/29728596/119133884-b9074e80-ba3c-11eb-97a5-b3cfb3b0ef6b.png)


Pull request review comments:
pls use context instead
useContext
done
done

Patch that resolved the issue:
diff --git a/kafka-ui-react-app/src/components/Topics/List/ListItem.tsx b/kafka-ui-react-app/src/components/Topics/List/ListItem.tsx
index ca92c22f5a6..07074be71fa 100644
--- a/kafka-ui-react-app/src/components/Topics/List/ListItem.tsx
+++ b/kafka-ui-react-app/src/components/Topics/List/ListItem.tsx
@@ -9,6 +9,7 @@ import {
 import DropdownItem from 'components/common/Dropdown/DropdownItem';
 import Dropdown from 'components/common/Dropdown/Dropdown';
 import ConfirmationModal from 'components/common/ConfirmationModal/ConfirmationModal';
+import ClusterContext from 'components/contexts/ClusterContext';
 
 export interface ListItemProps {
   topic: TopicWithDetailedInfo;
@@ -23,6 +24,8 @@ const ListItem: React.FC<ListItemProps> = ({
   clusterName,
   clearTopicMessages,
 }) => {
+  const { isReadOnly } = React.useContext(ClusterContext);
+
   const [isDeleteTopicConfirmationVisible, setDeleteTopicConfirmationVisible] =
     React.useState(false);
 
@@ -65,7 +68,7 @@ const ListItem: React.FC<ListItemProps> = ({
         </div>
       </td>
       <td className="topic-action-block">
-        {!internal ? (
+        {!internal && !isReadOnly ? (
           <>
             <div className="has-text-right">
               <Dropdown
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Details/Overview/Overview.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Details/Overview/Overview.tsx
index 52811ac353e..d9deb345dce 100644
--- a/kafka-ui-react-app/src/components/Topics/Topic/Details/Overview/Overview.tsx
+++ b/kafka-ui-react-app/src/components/Topics/Topic/Details/Overview/Overview.tsx
@@ -5,6 +5,7 @@ import Dropdown from 'components/common/Dropdown/Dropdown';
 import DropdownItem from 'components/common/Dropdown/DropdownItem';
 import MetricsWrapper from 'components/common/Dashboard/MetricsWrapper';
 import Indicator from 'components/common/Dashboard/Indicator';
+import ClusterContext from 'components/contexts/ClusterContext';
 import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';
 
 interface Props extends Topic, TopicDetails {
@@ -30,76 +31,82 @@ const Overview: React.FC<Props> = ({
   clusterName,
   topicName,
   clearTopicMessages,
-}) => (
-  <>
-    <MetricsWrapper>
-      <Indicator label="Partitions">{partitionCount}</Indicator>
-      <Indicator label="Replication Factor">{replicationFactor}</Indicator>
-      <Indicator label="URP" title="Under replicated partitions">
-        {underReplicatedPartitions}
-      </Indicator>
-      <Indicator label="In sync replicas">
-        {inSyncReplicas}
-        <span className="subtitle has-text-weight-light">
-          {' '}
-          of
-          {replicas}
-        </span>
-      </Indicator>
-      <Indicator label="Type">
-        <span className={`tag ${internal ? 'is-light' : 'is-primary'}`}>
-          {internal ? 'Internal' : 'External'}
-        </span>
-      </Indicator>
-      <Indicator label="Segment Size" title="">
-        <BytesFormatted value={segmentSize} />
-      </Indicator>
-      <Indicator label="Segment count">{segmentCount}</Indicator>
-    </MetricsWrapper>
-    <div className="box">
-      <table className="table is-striped is-fullwidth">
-        <thead>
-          <tr>
-            <th>Partition ID</th>
-            <th>Broker leader</th>
-            <th>Min offset</th>
-            <th>Max offset</th>
-            <th> </th>
-          </tr>
-        </thead>
-        <tbody>
-          {partitions?.map(({ partition, leader, offsetMin, offsetMax }) => (
-            <tr key={`partition-list-item-key-${partition}`}>
-              <td>{partition}</td>
-              <td>{leader}</td>
-              <td>{offsetMin}</td>
-              <td>{offsetMax}</td>
-              <td className="has-text-right">
-                {!internal ? (
-                  <Dropdown
-                    label={
-                      <span className="icon">
-                        <i className="fas fa-cog" />
-                      </span>
-                    }
-                    right
-                  >
-                    <DropdownItem
-                      onClick={() =>
-                        clearTopicMessages(clusterName, topicName, [partition])
+}) => {
+  const { isReadOnly } = React.useContext(ClusterContext);
+
+  return (
+    <>
+      <MetricsWrapper>
+        <Indicator label="Partitions">{partitionCount}</Indicator>
+        <Indicator label="Replication Factor">{replicationFactor}</Indicator>
+        <Indicator label="URP" title="Under replicated partitions">
+          {underReplicatedPartitions}
+        </Indicator>
+        <Indicator label="In sync replicas">
+          {inSyncReplicas}
+          <span className="subtitle has-text-weight-light">
+            {' '}
+            of
+            {replicas}
+          </span>
+        </Indicator>
+        <Indicator label="Type">
+          <span className={`tag ${internal ? 'is-light' : 'is-primary'}`}>
+            {internal ? 'Internal' : 'External'}
+          </span>
+        </Indicator>
+        <Indicator label="Segment Size" title="">
+          <BytesFormatted value={segmentSize} />
+        </Indicator>
+        <Indicator label="Segment count">{segmentCount}</Indicator>
+      </MetricsWrapper>
+      <div className="box">
+        <table className="table is-striped is-fullwidth">
+          <thead>
+            <tr>
+              <th>Partition ID</th>
+              <th>Broker leader</th>
+              <th>Min offset</th>
+              <th>Max offset</th>
+              <th> </th>
+            </tr>
+          </thead>
+          <tbody>
+            {partitions?.map(({ partition, leader, offsetMin, offsetMax }) => (
+              <tr key={`partition-list-item-key-${partition}`}>
+                <td>{partition}</td>
+                <td>{leader}</td>
+                <td>{offsetMin}</td>
+                <td>{offsetMax}</td>
+                <td className="has-text-right">
+                  {!internal && !isReadOnly ? (
+                    <Dropdown
+                      label={
+                        <span className="icon">
+                          <i className="fas fa-cog" />
+                        </span>
                       }
+                      right
                     >
-                      <span className="has-text-danger">Clear Messages</span>
-                    </DropdownItem>
-                  </Dropdown>
-                ) : null}
-              </td>
-            </tr>
-          ))}
-        </tbody>
-      </table>
-    </div>
-  </>
-);
+                      <DropdownItem
+                        onClick={() =>
+                          clearTopicMessages(clusterName, topicName, [
+                            partition,
+                          ])
+                        }
+                      >
+                        <span className="has-text-danger">Clear Messages</span>
+                      </DropdownItem>
+                    </Dropdown>
+                  ) : null}
+                </td>
+              </tr>
+            ))}
+          </tbody>
+        </table>
+      </div>
+    </>
+  );
+};
 
 export default Overview;


Test patch: