소스 검색

limit infrastructure views on frontend

Alexander Belanger 4 년 전
부모
커밋
09b2ddd085

+ 1 - 0
api/types/project.go

@@ -6,6 +6,7 @@ type Project struct {
 	Roles               []*Role `json:"roles"`
 	PreviewEnvsEnabled  bool    `json:"preview_envs_enabled"`
 	RDSDatabasesEnabled bool    `json:"enable_rds_databases"`
+	ManagedInfraEnabled bool    `json:"managed_infra_enabled"`
 }
 
 type CreateProjectRequest struct {

+ 12 - 1
dashboard/src/main/home/infrastructure/InfrastructureRouter.tsx

@@ -1,12 +1,23 @@
-import React from "react";
+import React, { useContext, useLayoutEffect } from "react";
 import { Route, Switch } from "react-router-dom";
 import { withRouter } from "react-router";
 import { useParams } from "react-router-dom";
 import InfrastructureList from "./InfrastructureList";
 import ExpandedInfra from "./ExpandedInfra";
 import ProvisionInfra from "./components/ProvisionInfra";
+import { Context } from "shared/Context";
+import { useRouting } from "shared/routing";
 
 const InfrastructureRouter = () => {
+  const { currentCluster, currentProject } = useContext(Context);
+  const { pushFiltered } = useRouting();
+
+  useLayoutEffect(() => {
+    if (!currentProject || !currentProject.managed_infra_enabled) {
+      pushFiltered("/dashboard", []);
+    }
+  }, [currentProject]);
+
   return (
     <Switch>
       <Route path="/infrastructure/provision/:name">

+ 12 - 11
dashboard/src/main/home/sidebar/Sidebar.tsx

@@ -244,17 +244,18 @@ class Sidebar extends Component<PropsType, StateType> {
             <Img src={rocket} />
             Launch
           </NavButton>
-          <NavButton
-            onClick={() =>
-              currentView !== "infrastructure" &&
-              pushFiltered(this.props, "/infrastructure", ["project_id"])
-            }
-            selected={currentView === "infrastructure"}
-          >
-            <i className="material-icons">build_circle</i>
-            Infrastructure
-          </NavButton>
-
+          {currentProject && currentProject.managed_infra_enabled && (
+            <NavButton
+              onClick={() =>
+                currentView !== "infrastructure" &&
+                pushFiltered(this.props, "/infrastructure", ["project_id"])
+              }
+              selected={currentView === "infrastructure"}
+            >
+              <i className="material-icons">build_circle</i>
+              Infrastructure
+            </NavButton>
+          )}
           {this.props.isAuthorized("integrations", "", [
             "get",
             "create",

+ 1 - 0
dashboard/src/shared/types.tsx

@@ -229,6 +229,7 @@ export interface ProjectType {
   name: string;
   preview_envs_enabled: boolean;
   enable_rds_databases: boolean;
+  managed_infra_enabled: boolean;
   roles: {
     id: number;
     kind: string;

+ 2 - 0
internal/models/project.go

@@ -58,6 +58,7 @@ type Project struct {
 
 	PreviewEnvsEnabled  bool
 	RDSDatabasesEnabled bool
+	ManagedInfraEnabled bool
 }
 
 // ToProjectType generates an external types.Project to be shared over REST
@@ -74,5 +75,6 @@ func (p *Project) ToProjectType() *types.Project {
 		Roles:               roles,
 		PreviewEnvsEnabled:  p.PreviewEnvsEnabled,
 		RDSDatabasesEnabled: p.RDSDatabasesEnabled,
+		ManagedInfraEnabled: p.ManagedInfraEnabled,
 	}
 }