From 94741cfac89d6e28a8a835d404d5515c29d34038 Mon Sep 17 00:00:00 2001
From: "Captain.B" <bin@fit2cloud.com>
Date: Fri, 28 May 2021 10:25:33 +0800
Subject: [PATCH] =?UTF-8?q?fix(=E6=9D=83=E9=99=90=E8=AE=BE=E7=BD=AE):=20?=
 =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89=EF=BC=8C?=
 =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8=E5=8C=96=EF=BC=8C=E6=B5=8B?=
 =?UTF-8?q?=E8=AF=95=E8=B7=9F=E8=B8=AA=E5=8F=AA=E8=AF=BB=E7=94=A8=E6=88=B7?=
 =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=82=B9=E5=87=BB=E5=88=9B=E5=BB=BA=E7=9A=84?=
 =?UTF-8?q?=E6=9D=83=E9=99=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../api/automation/ApiAutomation.vue          | 331 +++++++++---------
 .../api/definition/ApiDefinition.vue          |   5 +-
 .../components/track/case/TestCase.vue        |   7 +-
 3 files changed, 173 insertions(+), 170 deletions(-)

diff --git a/frontend/src/business/components/api/automation/ApiAutomation.vue b/frontend/src/business/components/api/automation/ApiAutomation.vue
index a3a99ce88e..c2c8b2a291 100644
--- a/frontend/src/business/components/api/automation/ApiAutomation.vue
+++ b/frontend/src/business/components/api/automation/ApiAutomation.vue
@@ -48,7 +48,7 @@
           </div>
         </el-tab-pane>
 
-        <el-tab-pane name="add">
+        <el-tab-pane name="add" v-if="hasPermission('PROJECT_API_SCENARIO:READ+CREATE')">
           <template v-slot:label>
             <el-dropdown @command="handleCommand">
               <el-button type="primary" plain icon="el-icon-plus" size="mini"/>
@@ -74,164 +74,165 @@ import MsContainer from "@/business/components/common/components/MsContainer";
 import MsAsideContainer from "@/business/components/common/components/MsAsideContainer";
 import MsMainContainer from "@/business/components/common/components/MsMainContainer";
 import MsApiScenarioList from "@/business/components/api/automation/scenario/ApiScenarioList";
-import {getCurrentUser, getUUID} from "@/common/js/utils";
+import {getCurrentUser, getUUID, hasPermission} from "@/common/js/utils";
 import MsApiScenarioModule from "@/business/components/api/automation/scenario/ApiScenarioModule";
 import MsEditApiScenario from "./scenario/EditApiScenario";
 
-  export default {
-    name: "ApiAutomation",
-    components: {
-      MsApiScenarioModule,
-      MsApiScenarioList,
-      MsMainContainer,
-      MsAsideContainer,
-      MsContainer,
-      MsEditApiScenario
+export default {
+  name: "ApiAutomation",
+  components: {
+    MsApiScenarioModule,
+    MsApiScenarioList,
+    MsMainContainer,
+    MsAsideContainer,
+    MsContainer,
+    MsEditApiScenario
+  },
+  comments: {},
+  computed: {
+    checkRedirectID: function () {
+      let redirectIDParam = this.$route.params.redirectID;
+      this.changeRedirectParam(redirectIDParam);
+      return redirectIDParam;
     },
-    comments: {},
-    computed: {
-      checkRedirectID: function () {
-        let redirectIDParam = this.$route.params.redirectID;
-        this.changeRedirectParam(redirectIDParam);
-        return redirectIDParam;
-      },
-      isRedirectEdit: function () {
-        let redirectParam = this.$route.params.dataSelectRange;
-        this.checkRedirectEditPage(redirectParam);
-        return redirectParam;
-      },
-      isReadOnly() {
-        return false;
-      },
-      projectId() {
-        return this.$store.state.projectId
-      },
+    isRedirectEdit: function () {
+      let redirectParam = this.$route.params.dataSelectRange;
+      this.checkRedirectEditPage(redirectParam);
+      return redirectParam;
     },
-    data() {
-      return {
-        redirectID: '',
-        renderComponent: true,
-        isHide: true,
-        activeName: 'default',
-        redirectFlag: 'none',
-        currentModule: null,
-        moduleOptions: [],
-        tabs: [],
-        loading: false,
-        trashEnable: false,
-        selectNodeIds: [],
-        nodeTree: [],
-        currentModulePath: "",
-        customNum: false
-      }
+    isReadOnly() {
+      return false;
     },
-    mounted() {
-      this.getProject();
+    projectId() {
+      return this.$store.state.projectId;
     },
-    watch: {
-      redirectID() {
-        this.renderComponent = false;
-        this.$nextTick(() => {
-          // 在 DOM 中添加 my-component 组件
-          this.renderComponent = true;
-        });
-      },
-      '$route'(to, from) {  //  路由改变时,把接口定义界面中的 ctrl s 保存快捷键监听移除
-        if (to.path.indexOf('/api/automation') == -1) {
-          if (this.$refs && this.$refs.autoScenarioConfig) {
-            this.$refs.autoScenarioConfig.forEach(item => {
-              item.removeListener();
-            });
-          }
+  },
+  data() {
+    return {
+      redirectID: '',
+      renderComponent: true,
+      isHide: true,
+      activeName: 'default',
+      redirectFlag: 'none',
+      currentModule: null,
+      moduleOptions: [],
+      tabs: [],
+      loading: false,
+      trashEnable: false,
+      selectNodeIds: [],
+      nodeTree: [],
+      currentModulePath: "",
+      customNum: false
+    };
+  },
+  mounted() {
+    this.getProject();
+  },
+  watch: {
+    redirectID() {
+      this.renderComponent = false;
+      this.$nextTick(() => {
+        // 在 DOM 中添加 my-component 组件
+        this.renderComponent = true;
+      });
+    },
+    '$route'(to, from) {  //  路由改变时,把接口定义界面中的 ctrl s 保存快捷键监听移除
+      if (to.path.indexOf('/api/automation') == -1) {
+        if (this.$refs && this.$refs.autoScenarioConfig) {
+          this.$refs.autoScenarioConfig.forEach(item => {
+            item.removeListener();
+          });
         }
-      },
-      selectNodeIds() {
-        this.activeName = "default";
       }
     },
-    methods: {
-      exportAPI() {
-        this.$refs.apiScenarioList.exportApi();
-      },
-      exportJmx() {
-        this.$refs.apiScenarioList.exportJmx();
-      },
-      checkRedirectEditPage(redirectParam) {
-        if (redirectParam != null) {
-          let selectParamArr = redirectParam.split("edit:");
-          if (selectParamArr.length == 2) {
-            let scenarioId = selectParamArr[1];
-            let projectId = this.projectId;
-            //查找单条数据,跳转修改页面
-            let url = "/api/automation/list/" + 1 + "/" + 1;
-            this.$post(url, {id: scenarioId, projectId: projectId}, response => {
-              let data = response.data;
-              if (data != null) {
-                //如果树未加载
-                if (JSON.stringify(this.moduleOptions) === '{}') {
-                  this.$refs.nodeTree.list();
-                }
-                let row = data.listObject[0];
-                if (row.tags.length > 0) {
-                  row.tags = JSON.parse(row.tags);
-                }
-
-                this.editScenario(row);
+    selectNodeIds() {
+      this.activeName = "default";
+    }
+  },
+  methods: {
+    hasPermission,
+    exportAPI() {
+      this.$refs.apiScenarioList.exportApi();
+    },
+    exportJmx() {
+      this.$refs.apiScenarioList.exportJmx();
+    },
+    checkRedirectEditPage(redirectParam) {
+      if (redirectParam != null) {
+        let selectParamArr = redirectParam.split("edit:");
+        if (selectParamArr.length == 2) {
+          let scenarioId = selectParamArr[1];
+          let projectId = this.projectId;
+          //查找单条数据,跳转修改页面
+          let url = "/api/automation/list/" + 1 + "/" + 1;
+          this.$post(url, {id: scenarioId, projectId: projectId}, response => {
+            let data = response.data;
+            if (data != null) {
+              //如果树未加载
+              if (JSON.stringify(this.moduleOptions) === '{}') {
+                this.$refs.nodeTree.list();
               }
-            });
-          }
-        }
-      },
-      changeRedirectParam(redirectIDParam) {
-        this.redirectID = redirectIDParam;
-        if (redirectIDParam != null) {
-          if (this.redirectFlag == "none") {
-            this.activeName = "default";
-            this.addListener();
-            this.redirectFlag = "redirected";
-          }
-        } else {
-          this.redirectFlag = "none";
-        }
-      },
-      getPath(id, arr) {
-        if (id === null) {
-          return null;
-        }
-        if(arr) {
-          arr.forEach(item => {
-            if (item.id === id) {
-              this.currentModulePath = item.path;
-            }
-            if (item.children && item.children.length > 0) {
-              this.getPath(id, item.children);
+              let row = data.listObject[0];
+              if (row.tags.length > 0) {
+                row.tags = JSON.parse(row.tags);
+              }
+
+              this.editScenario(row);
             }
           });
         }
-      },
-      addTab(tab) {
-        if (tab.name === 'default') {
-          this.$refs.apiScenarioList.search();
+      }
+    },
+    changeRedirectParam(redirectIDParam) {
+      this.redirectID = redirectIDParam;
+      if (redirectIDParam != null) {
+        if (this.redirectFlag == "none") {
+          this.activeName = "default";
+          this.addListener();
+          this.redirectFlag = "redirected";
         }
-        if (!this.projectId) {
-          this.$warning(this.$t('commons.check_project_tip'));
-          return;
-        }
-        this.currentModulePath = "";
-        if (tab.name === 'add') {
-          let label = this.$t('api_test.automation.add_scenario');
-          let name = getUUID().substring(0, 8);
-          this.activeName = name;
-          let currentScenario = {
-            status: "Underway", principal: getCurrentUser().id,
-            apiScenarioModuleId: "default-module", id: getUUID(),
-            modulePath: "/" + this.$t("commons.module_title")
-          };
-          if (this.nodeTree && this.nodeTree.length > 0) {
-            currentScenario.apiScenarioModuleId = this.nodeTree[0].id;
-            this.getPath(this.nodeTree[0].id, this.moduleOptions);
-            currentScenario.modulePath = this.currentModulePath;
+      } else {
+        this.redirectFlag = "none";
+      }
+    },
+    getPath(id, arr) {
+      if (id === null) {
+        return null;
+      }
+      if (arr) {
+        arr.forEach(item => {
+          if (item.id === id) {
+            this.currentModulePath = item.path;
           }
+          if (item.children && item.children.length > 0) {
+            this.getPath(id, item.children);
+          }
+        });
+      }
+    },
+    addTab(tab) {
+      if (tab.name === 'default') {
+        this.$refs.apiScenarioList.search();
+      }
+      if (!this.projectId) {
+        this.$warning(this.$t('commons.check_project_tip'));
+        return;
+      }
+      this.currentModulePath = "";
+      if (tab.name === 'add') {
+        let label = this.$t('api_test.automation.add_scenario');
+        let name = getUUID().substring(0, 8);
+        this.activeName = name;
+        let currentScenario = {
+          status: "Underway", principal: getCurrentUser().id,
+          apiScenarioModuleId: "default-module", id: getUUID(),
+          modulePath: "/" + this.$t("commons.module_title")
+        };
+        if (this.nodeTree && this.nodeTree.length > 0) {
+          currentScenario.apiScenarioModuleId = this.nodeTree[0].id;
+          this.getPath(this.nodeTree[0].id, this.moduleOptions);
+          currentScenario.modulePath = this.currentModulePath;
+        }
 
         if (this.selectNodeIds && this.selectNodeIds.length > 0) {
           currentScenario.apiScenarioModuleId = this.selectNodeIds[0];
@@ -309,28 +310,28 @@ import MsEditApiScenario from "./scenario/EditApiScenario";
     selectModule(data) {
       this.currentModule = data;
     },
-      saveScenario(data) {
-        this.setTabLabel(data);
-        this.$refs.apiScenarioList.search(data);
-      },
-      refresh(data) {
-        this.setTabTitle(data);
-        this.$refs.apiScenarioList.search(data);
-        this.$refs.nodeTree.list();
-      },
-      refreshTree() {
-        this.$refs.nodeTree.list();
-      },
-      refreshAll() {
-        this.$refs.nodeTree.list();
-        this.$refs.apiScenarioList.search();
-      },
-      setTabTitle(data) {
-        for (let index in this.tabs) {
-          let tab = this.tabs[index];
-          if (tab.name === this.activeName) {
-            tab.label = data.name;
-            break;
+    saveScenario(data) {
+      this.setTabLabel(data);
+      this.$refs.apiScenarioList.search(data);
+    },
+    refresh(data) {
+      this.setTabTitle(data);
+      this.$refs.apiScenarioList.search(data);
+      this.$refs.nodeTree.list();
+    },
+    refreshTree() {
+      this.$refs.nodeTree.list();
+    },
+    refreshAll() {
+      this.$refs.nodeTree.list();
+      this.$refs.apiScenarioList.search();
+    },
+    setTabTitle(data) {
+      for (let index in this.tabs) {
+        let tab = this.tabs[index];
+        if (tab.name === this.activeName) {
+          tab.label = data.name;
+          break;
         }
       }
     },
diff --git a/frontend/src/business/components/api/definition/ApiDefinition.vue b/frontend/src/business/components/api/definition/ApiDefinition.vue
index 877b28dbd2..b030ee2035 100644
--- a/frontend/src/business/components/api/definition/ApiDefinition.vue
+++ b/frontend/src/business/components/api/definition/ApiDefinition.vue
@@ -120,7 +120,7 @@
             </div>
           </el-tab-pane>
 
-          <el-tab-pane name="add">
+          <el-tab-pane name="add" v-if="hasPermission('PROJECT_API_DEFINITION:READ+CREATE_API')">
             <template v-slot:label>
               <el-dropdown @command="handleCommand">
                 <el-button type="primary" plain icon="el-icon-plus" size="mini"/>
@@ -160,7 +160,7 @@ import MsRunTestHttpPage from "./components/runtest/RunTestHTTPPage";
 import MsRunTestTcpPage from "./components/runtest/RunTestTCPPage";
 import MsRunTestSqlPage from "./components/runtest/RunTestSQLPage";
 import MsRunTestDubboPage from "./components/runtest/RunTestDubboPage";
-import {getCurrentUser, getUUID} from "@/common/js/utils";
+import {getCurrentUser, getUUID, hasPermission} from "@/common/js/utils";
 import MsApiModule from "./components/module/ApiModule";
 import ApiCaseSimpleList from "./components/list/ApiCaseSimpleList";
 
@@ -281,6 +281,7 @@ export default {
   },
 
   methods: {
+    hasPermission,
     getPath(id, arr) {
       if (id === null) {
         return null;
diff --git a/frontend/src/business/components/track/case/TestCase.vue b/frontend/src/business/components/track/case/TestCase.vue
index 346445601b..d123842993 100644
--- a/frontend/src/business/components/track/case/TestCase.vue
+++ b/frontend/src/business/components/track/case/TestCase.vue
@@ -72,10 +72,10 @@
             </test-case-edit>
           </div>
         </el-tab-pane>
-        <el-tab-pane name="add">
+        <el-tab-pane name="add" v-if="hasPermission('PROJECT_TRACK_CASE:READ+CREATE')">
           <template v-slot:label>
             <el-dropdown @command="handleCommand" v-permission="['PROJECT_TRACK_CASE:READ+CREATE']">
-              <el-button type="primary" plain icon="el-icon-plus" size="mini" />
+              <el-button type="primary" plain icon="el-icon-plus" size="mini"/>
               <el-dropdown-menu slot="dropdown">
                 <el-dropdown-item command="ADD" v-permission="['PROJECT_TRACK_CASE:READ+CREATE']">
                   {{ $t('test_track.case.create') }}
@@ -105,7 +105,7 @@ import SelectMenu from "../common/SelectMenu";
 import MsContainer from "../../common/components/MsContainer";
 import MsAsideContainer from "../../common/components/MsAsideContainer";
 import MsMainContainer from "../../common/components/MsMainContainer";
-import {getUUID} from "../../../../common/js/utils";
+import {getUUID, hasPermission} from "@/common/js/utils";
 import TestCaseNodeTree from "../common/TestCaseNodeTree";
 
 import MsTabButton from "@/business/components/common/components/MsTabButton";
@@ -190,6 +190,7 @@ export default {
     }
   },
   methods: {
+    hasPermission,
     handleCommand(e) {
       switch (e) {
         case "ADD":