Skip to content

Commit 5eb7c5a

Browse files
committed
✨ 优化授权管理
1 parent 0c43741 commit 5eb7c5a

File tree

14 files changed

+295
-97
lines changed

14 files changed

+295
-97
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- release/*
78
- dev
89

910
jobs:

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- release/*
78
- dev
89
- develop/*
910
pull_request:

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptcat",
3-
"version": "0.16.0",
3+
"version": "0.15.1",
44
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
55
"author": "CodFrm",
66
"license": "GPLv3",
@@ -16,7 +16,7 @@
1616
"changlog": "gitmoji-changelog"
1717
},
1818
"dependencies": {
19-
"@arco-design/web-react": "^2.47.0",
19+
"@arco-design/web-react": "^2.51.1",
2020
"@dnd-kit/core": "^6.0.5",
2121
"@dnd-kit/sortable": "^7.0.1",
2222
"@dnd-kit/utilities": "^3.2.0",

src/app/cache.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ export default class Cache {
3535
public del(key: string): void {
3636
this.map.delete(key);
3737
}
38+
39+
public list(): string[] {
40+
return Array.from(this.map.keys());
41+
}
3842
}

src/app/service/permission/controller.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,19 @@ export default class PermissionController {
4545
confirm,
4646
});
4747
}
48+
49+
// 添加权限
50+
addPermission(scriptId: number, permission: Permission) {
51+
return this.msg.syncSend("addPermission", {
52+
scriptId,
53+
permission,
54+
});
55+
}
56+
57+
// 重置权限
58+
resetPermission(scriptId: number) {
59+
return this.msg.syncSend("resetPermission", {
60+
scriptId,
61+
});
62+
}
4863
}

src/locales/en-US/translation.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ script_setting: Script Setting
198198
basic_info: Basic Information
199199
update_url: Update URL
200200
permission_management: Permission Management
201+
add_permission: Add Permission
201202
# Script Setting Match ScriptSetting/Match
202203
match: Match
203204
user_setting: User Setting

src/locales/zh-CN/translation.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ script_setting: 脚本设置
199199
basic_info: 基本信息
200200
update_url: 更新URL
201201
permission_management: 授权管理
202+
add_permission: 添加授权
203+
permission_cors: 跨域(cors)
204+
permission_cookie: 管理cookie
202205
# 脚本设置Match ScriptSetting/Match
203206
match: 匹配
204207
user_setting: 用户设定

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "ScriptCat",
4-
"version": "0.16.0",
4+
"version": "0.15.1",
55
"author": "CodFrm",
66
"description": "脚本猫,一个用户脚本管理器,支持后台脚本、定时脚本、页面脚本,可编写脚本每天帮你自动处理事务.",
77
"options_ui": {

src/pages/components/ScriptSetting/Match.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ const Match: React.FC<{
289289
</Popconfirm>
290290
</Space>
291291
</div>
292-
<Table columns={columns} data={match} rowKey="id" />
292+
<Table columns={columns} data={match} rowKey="id" pagination={false} />
293293
<Divider />
294294
<div className="flex flex-row justify-between pb-2">
295295
<Typography.Title heading={6}>{t("website_exclude")}</Typography.Title>
@@ -318,7 +318,7 @@ const Match: React.FC<{
318318
</Popconfirm>
319319
</Space>
320320
</div>
321-
<Table columns={columns} data={exclude} rowKey="id" />
321+
<Table columns={columns} data={exclude} rowKey="id" pagination={false} />
322322
<Divider />
323323
</>
324324
);
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
import React, { useEffect, useState } from "react";
2+
import { Permission } from "@App/app/repo/permission";
3+
import { Script } from "@App/app/repo/scripts";
4+
import { useTranslation } from "react-i18next";
5+
import IoC from "@App/app/ioc";
6+
import PermissionController from "@App/app/service/permission/controller";
7+
import {
8+
Space,
9+
Popconfirm,
10+
Message,
11+
Button,
12+
Checkbox,
13+
Input,
14+
Modal,
15+
Select,
16+
Typography,
17+
} from "@arco-design/web-react";
18+
import Table, { ColumnProps } from "@arco-design/web-react/es/Table";
19+
import { IconDelete } from "@arco-design/web-react/icon";
20+
21+
const PermissionManager: React.FC<{
22+
script: Script;
23+
}> = ({ script }) => {
24+
const permissionCtrl = IoC.instance(
25+
PermissionController
26+
) as PermissionController;
27+
const [permission, setPermission] = useState<Permission[]>([]);
28+
const [permissionVisible, setPermissionVisible] = useState<boolean>(false);
29+
const [permissionValue, setPermissionValue] = useState<Permission>();
30+
31+
const { t } = useTranslation();
32+
33+
const columns: ColumnProps[] = [
34+
{
35+
title: t("type"),
36+
dataIndex: "permission",
37+
key: "permission",
38+
width: 100,
39+
},
40+
{
41+
title: t("permission_value"),
42+
dataIndex: "permissionValue",
43+
key: "permissionValue",
44+
},
45+
{
46+
title: t("allow"),
47+
dataIndex: "allow",
48+
key: "allow",
49+
render(col) {
50+
if (col) {
51+
return <span style={{ color: "#52c41a" }}>{t("yes")}</span>;
52+
}
53+
return <span style={{ color: "#f5222d" }}>{t("no")}</span>;
54+
},
55+
},
56+
{
57+
title: t("action"),
58+
render(_, item: Permission) {
59+
return (
60+
<Space>
61+
<Popconfirm
62+
title={t("confirm_delete_permission")}
63+
onOk={() => {
64+
permissionCtrl
65+
.deletePermission(script!.id, {
66+
permission: item.permission,
67+
permissionValue: item.permissionValue,
68+
})
69+
.then(() => {
70+
Message.success(t("delete_success")!);
71+
setPermission(permission.filter((i) => i.id !== item.id));
72+
})
73+
.catch(() => {
74+
Message.error(t("delete_failed")!);
75+
});
76+
}}
77+
>
78+
<Button type="text" iconOnly icon={<IconDelete />} />
79+
</Popconfirm>
80+
</Space>
81+
);
82+
},
83+
},
84+
];
85+
86+
useEffect(() => {
87+
if (script) {
88+
permissionCtrl.getPermissions(script.id).then((list) => {
89+
setPermission(list);
90+
});
91+
}
92+
}, [script]);
93+
94+
return (
95+
<>
96+
<Modal
97+
title={t("add_permission")}
98+
visible={permissionVisible}
99+
onCancel={() => setPermissionVisible(false)}
100+
onOk={() => {
101+
if (permissionValue) {
102+
permission.push({
103+
id: 0,
104+
scriptId: script.id,
105+
permission: permissionValue.permission,
106+
permissionValue: permissionValue.permissionValue,
107+
allow: permissionValue.allow,
108+
createtime: new Date().getTime(),
109+
updatetime: 0,
110+
});
111+
permissionCtrl
112+
.addPermission(script.id, permissionValue)
113+
.then(() => {
114+
setPermission([...permission]);
115+
setPermissionVisible(false);
116+
});
117+
}
118+
}}
119+
>
120+
<Space className="w-full" direction="vertical">
121+
<Select
122+
value={permissionValue?.permission}
123+
onChange={(e) => {
124+
permissionValue &&
125+
setPermissionValue({ ...permissionValue, permission: e });
126+
}}
127+
>
128+
<Select.Option value="cors">{t("permission_cors")}</Select.Option>
129+
<Select.Option value="cookie">
130+
{t("permission_cookie")}
131+
</Select.Option>
132+
</Select>
133+
<Input
134+
value={permissionValue?.permissionValue}
135+
onChange={(e) => {
136+
permissionValue &&
137+
setPermissionValue({ ...permissionValue, permissionValue: e });
138+
}}
139+
/>
140+
<Checkbox
141+
checked={permissionValue?.allow}
142+
onChange={(e) => {
143+
permissionValue &&
144+
setPermissionValue({ ...permissionValue, allow: e });
145+
}}
146+
>
147+
{t("allow")}
148+
</Checkbox>
149+
</Space>
150+
</Modal>
151+
<div className="flex flex-row justify-between pb-2">
152+
<Typography.Title heading={6}>
153+
{t("permission_management")}
154+
</Typography.Title>
155+
<Space>
156+
<Button
157+
type="primary"
158+
size="small"
159+
onClick={() => {
160+
setPermissionValue({
161+
id: 0,
162+
scriptId: script.id,
163+
permission: "cors",
164+
permissionValue: "",
165+
allow: true,
166+
createtime: 0,
167+
updatetime: 0,
168+
});
169+
setPermissionVisible(true);
170+
}}
171+
>
172+
{t("add_permission")}
173+
</Button>
174+
<Popconfirm
175+
title={t("confirm_reset")}
176+
onOk={() => {
177+
permissionCtrl.resetPermission(script.id).then(() => {
178+
setPermission([]);
179+
});
180+
}}
181+
>
182+
<Button type="primary" size="small" status="warning">
183+
{t("reset")}
184+
</Button>
185+
</Popconfirm>
186+
</Space>
187+
</div>
188+
<Table
189+
columns={columns}
190+
data={permission}
191+
rowKey="id"
192+
pagination={false}
193+
/>
194+
</>
195+
);
196+
};
197+
198+
export default PermissionManager;

0 commit comments

Comments
 (0)