Parcourir la source

阻止basic用户修改可见性

visuddhinanda il y a 2 ans
Parent
commit
2419f27923
1 fichiers modifiés avec 26 ajouts et 2 suppressions
  1. 26 2
      dashboard/src/components/channel/Edit.tsx

+ 26 - 2
dashboard/src/components/channel/Edit.tsx

@@ -6,12 +6,17 @@ import {
 } from "@ant-design/pro-components";
 import { Alert, message } from "antd";
 
-import { IApiResponseChannel } from "../../components/api/Channel";
+import {
+  IApiResponseChannel,
+  IApiResponseChannelData,
+} from "../../components/api/Channel";
 import { get, put } from "../../request";
 import ChannelTypeSelect from "../../components/channel/ChannelTypeSelect";
 import LangSelect from "../../components/general/LangSelect";
 import PublicitySelect from "../../components/studio/PublicitySelect";
 import { useState } from "react";
+import { useAppSelector } from "../../hooks";
+import { currentUser } from "../../reducers/current-user";
 
 interface IFormData {
   name: string;
@@ -30,6 +35,9 @@ interface IWidget {
 const EditWidget = ({ studioName, channelId, onLoad }: IWidget) => {
   const intl = useIntl();
   const [isSystem, setIsSystem] = useState<Boolean>();
+  const [data, setData] = useState<IApiResponseChannelData>();
+
+  const user = useAppSelector(currentUser);
   return (
     <>
       {isSystem ? (
@@ -53,6 +61,18 @@ const EditWidget = ({ studioName, channelId, onLoad }: IWidget) => {
           const res = await get<IApiResponseChannel>(
             `/v2/channel/${channelId}`
           );
+          if (res.ok === false) {
+            return {
+              name: "",
+              type: "",
+              lang: "",
+              summary: "",
+              status: 0,
+              studio: "",
+              isSystem: true,
+            };
+          }
+          setData(res.data);
           if (typeof onLoad !== "undefined") {
             onLoad(res.data);
           }
@@ -89,7 +109,11 @@ const EditWidget = ({ studioName, channelId, onLoad }: IWidget) => {
         </ProForm.Group>
         <ProForm.Group>
           <PublicitySelect
-            readonly={isSystem ? true : false}
+            readonly={
+              isSystem || user?.roles?.includes("basic") || data?.status === 5
+                ? true
+                : false
+            }
             disable={["public_no_list"]}
           />
         </ProForm.Group>