Просмотр исходного кода

Implemented authorization module on Application Expanded chart

jnfrati 4 лет назад
Родитель
Сommit
4c7f13c694

+ 19 - 5
dashboard/src/main/home/cluster-dashboard/expanded-chart/ExpandedChart.tsx

@@ -26,8 +26,9 @@ import ListSection from "./ListSection";
 import StatusSection from "./status/StatusSection";
 import StatusSection from "./status/StatusSection";
 import SettingsSection from "./SettingsSection";
 import SettingsSection from "./SettingsSection";
 import ChartList from "../chart/ChartList";
 import ChartList from "../chart/ChartList";
+import { withAuth, WithAuthProps } from "shared/auth/AuthorizationHoc";
 
 
-type PropsType = {
+type PropsType = WithAuthProps & {
   namespace: string;
   namespace: string;
   currentChart: ChartType;
   currentChart: ChartType;
   currentCluster: ClusterType;
   currentCluster: ClusterType;
@@ -58,7 +59,7 @@ type StateType = {
   newestImage: string;
   newestImage: string;
 };
 };
 
 
-export default class ExpandedChart extends Component<PropsType, StateType> {
+class ExpandedChart extends Component<PropsType, StateType> {
   state = {
   state = {
     currentChart: this.props.currentChart,
     currentChart: this.props.currentChart,
     loading: true,
     loading: true,
@@ -444,7 +445,13 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
         );
         );
       case "values":
       case "values":
         return (
         return (
-          <ValuesYaml currentChart={chart} refreshChart={this.refreshChart} />
+          <ValuesYaml
+            currentChart={chart}
+            refreshChart={this.refreshChart}
+            disabled={
+              !this.props.isAuthorized("application", "", ["get", "update"])
+            }
+          />
         );
         );
       default:
       default:
     }
     }
@@ -474,7 +481,9 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
     }
     }
 
 
     // Settings tab is always last
     // Settings tab is always last
-    tabOptions.push({ label: "Settings", value: "settings" });
+    if (this.props.isAuthorized("application", "", ["get", "delete"])) {
+      tabOptions.push({ label: "Settings", value: "settings" });
+    }
 
 
     // Filter tabs if previewing an old revision or updating the chart version
     // Filter tabs if previewing an old revision or updating the chart version
     if (this.state.isPreview || this.state.isUpdatingChart) {
     if (this.state.isPreview || this.state.isUpdatingChart) {
@@ -787,7 +796,10 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
           </HeaderWrapper>
           </HeaderWrapper>
           <BodyWrapper>
           <BodyWrapper>
             <FormWrapper
             <FormWrapper
-              isReadOnly={this.state.imageIsPlaceholder}
+              isReadOnly={
+                this.state.imageIsPlaceholder ||
+                !this.props.isAuthorized("application", "", ["get", "update"])
+              }
               formData={this.state.formData}
               formData={this.state.formData}
               tabOptions={this.state.tabOptions}
               tabOptions={this.state.tabOptions}
               isInModal={true}
               isInModal={true}
@@ -817,6 +829,8 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
 
 
 ExpandedChart.contextType = Context;
 ExpandedChart.contextType = Context;
 
 
+export default withAuth(ExpandedChart);
+
 const TextWrap = styled.div``;
 const TextWrap = styled.div``;
 
 
 const Header = styled.div`
 const Header = styled.div`

+ 9 - 3
dashboard/src/main/home/cluster-dashboard/expanded-chart/RevisionSection.tsx

@@ -7,8 +7,9 @@ import { Context } from "shared/Context";
 import { ChartType, StorageType } from "shared/types";
 import { ChartType, StorageType } from "shared/types";
 
 
 import ConfirmOverlay from "components/ConfirmOverlay";
 import ConfirmOverlay from "components/ConfirmOverlay";
+import { withAuth, WithAuthProps } from "shared/auth/AuthorizationHoc";
 
 
-type PropsType = {
+type PropsType = WithAuthProps & {
   showRevisions: boolean;
   showRevisions: boolean;
   toggleShowRevisions: () => void;
   toggleShowRevisions: () => void;
   chart: ChartType;
   chart: ChartType;
@@ -31,7 +32,7 @@ type StateType = {
 };
 };
 
 
 // TODO: handle refresh when new revision is generated from an old revision
 // TODO: handle refresh when new revision is generated from an old revision
-export default class RevisionSection extends Component<PropsType, StateType> {
+class RevisionSection extends Component<PropsType, StateType> {
   state = {
   state = {
     revisions: [] as ChartType[],
     revisions: [] as ChartType[],
     rollbackRevision: null as number | null,
     rollbackRevision: null as number | null,
@@ -227,7 +228,10 @@ export default class RevisionSection extends Component<PropsType, StateType> {
           <Td>v{revision.chart.metadata.version}</Td>
           <Td>v{revision.chart.metadata.version}</Td>
           <Td>
           <Td>
             <RollbackButton
             <RollbackButton
-              disabled={isCurrent}
+              disabled={
+                isCurrent ||
+                !this.props.isAuthorized("application", "", ["get", "update"])
+              }
               onClick={() =>
               onClick={() =>
                 this.setState({ rollbackRevision: revision.version })
                 this.setState({ rollbackRevision: revision.version })
               }
               }
@@ -341,6 +345,8 @@ export default class RevisionSection extends Component<PropsType, StateType> {
 
 
 RevisionSection.contextType = Context;
 RevisionSection.contextType = Context;
 
 
+export default withAuth(RevisionSection);
+
 const TableWrapper = styled.div`
 const TableWrapper = styled.div`
   padding-bottom: 20px;
   padding-bottom: 20px;
 `;
 `;

+ 10 - 6
dashboard/src/main/home/cluster-dashboard/expanded-chart/ValuesYaml.tsx

@@ -12,6 +12,7 @@ import SaveButton from "components/SaveButton";
 type PropsType = {
 type PropsType = {
   currentChart: ChartType;
   currentChart: ChartType;
   refreshChart: () => void;
   refreshChart: () => void;
+  disabled?: boolean;
 };
 };
 
 
 type StateType = {
 type StateType = {
@@ -89,14 +90,17 @@ export default class ValuesYaml extends Component<PropsType, StateType> {
           <YamlEditor
           <YamlEditor
             value={this.state.values}
             value={this.state.values}
             onChange={(e: any) => this.setState({ values: e })}
             onChange={(e: any) => this.setState({ values: e })}
+            readOnly={this.props.disabled}
           />
           />
         </Wrapper>
         </Wrapper>
-        <SaveButton
-          text="Update Values"
-          onClick={this.handleSaveValues}
-          status={this.state.saveValuesStatus}
-          makeFlush={true}
-        />
+        {!this.props.disabled && (
+          <SaveButton
+            text="Update Values"
+            onClick={this.handleSaveValues}
+            status={this.state.saveValuesStatus}
+            makeFlush={true}
+          />
+        )}
       </StyledValuesYaml>
       </StyledValuesYaml>
     );
     );
   }
   }