Skip to content

Commit

Permalink
✨ 重置权限
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Aug 30, 2023
1 parent 879523d commit c00158a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/app/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ export default class Cache {
public del(key: string): void {
this.map.delete(key);
}

public list(): string[] {
return Array.from(this.map.keys());
}
}
7 changes: 7 additions & 0 deletions src/app/service/permission/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ export default class PermissionController {
permission,
});
}

// 重置权限
resetPermission(scriptId: number) {
return this.msg.syncSend("resetPermission", {
scriptId,
});
}
}
6 changes: 3 additions & 3 deletions src/pages/components/ScriptSetting/Permission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ import {
} from "@arco-design/web-react";
import Table, { ColumnProps } from "@arco-design/web-react/es/Table";
import { IconDelete } from "@arco-design/web-react/icon";
import ScriptController from "@App/app/service/script/controller";

const PermissionManager: React.FC<{
script: Script;
}> = ({ script }) => {
const permissionCtrl = IoC.instance(
PermissionController
) as PermissionController;
const scriptCtrl = IoC.instance(ScriptController) as ScriptController;
const [permission, setPermission] = useState<Permission[]>([]);
const [permissionVisible, setPermissionVisible] = useState<boolean>(false);
const [permissionValue, setPermissionValue] = useState<Permission>();
Expand Down Expand Up @@ -176,7 +174,9 @@ const PermissionManager: React.FC<{
<Popconfirm
title={t("confirm_reset")}
onOk={() => {
scriptCtrl.resetExclude(script.id, undefined).then(() => {});
permissionCtrl.resetPermission(script.id).then(() => {
setPermission([]);
});
}}
>
<Button type="primary" size="small" status="warning">
Expand Down
19 changes: 19 additions & 0 deletions src/runtime/background/permission_verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ export default class PermissionVerify {
return Promise.resolve(true);
}
);
// 监听重置权限
message.setHandler(
"resetPermission",
async (_action, data: { scriptId: number }) => {
// 先删除缓存
Cache.getInstance()
.list()
.forEach((key) => {
if (key.startsWith(`permission:${data.scriptId.toString()}:`)) {
Cache.getInstance().del(key);
}
});
// 从数据库中查询是否有此权限
await this.permissionDAO.delete({
scriptId: data.scriptId,
});
return Promise.resolve(true);
}
);
this.dealConfirmQueue();
}

Expand Down

0 comments on commit c00158a

Please sign in to comment.