mirror of
https://github.com/MCSManager/MCSManager.git
synced 2024-11-27 06:59:54 +08:00
fix: user assignment list not cleared when deleting instance
fixed #1415
This commit is contained in:
parent
3822a7bfb4
commit
1dd417f05c
@ -12,6 +12,7 @@ import { getUserUuid } from "../service/passport_service";
|
||||
import { isHaveInstanceByUuid, isTopPermissionByUuid } from "../service/permission_service";
|
||||
import { ROLE } from "../entity/user";
|
||||
import { removeTrail } from "common";
|
||||
import userSystem from "../service/user_service";
|
||||
|
||||
const router = new Router({ prefix: "/instance" });
|
||||
|
||||
@ -131,6 +132,10 @@ router.delete(
|
||||
const instanceUuids = ctx.request.body.uuids;
|
||||
const deleteFile = ctx.request.body.deleteFile;
|
||||
const remoteService = RemoteServiceSubsystem.getInstance(daemonId);
|
||||
const instanceIds = instanceUuids.map((uuid: string) => {
|
||||
return { instanceUuid: uuid, daemonId };
|
||||
});
|
||||
userSystem.deleteUserInstances(null, instanceIds, true);
|
||||
const result = await new RemoteRequest(remoteService).request("instance/delete", {
|
||||
instanceUuids,
|
||||
deleteFile
|
||||
|
@ -109,6 +109,27 @@ class UserSubsystem {
|
||||
});
|
||||
}
|
||||
|
||||
deleteUserInstances(uuid: string, instanceIds: IUserApp[], allUsers: false): void;
|
||||
deleteUserInstances(uuid: null, instanceIds: IUserApp[], allUsers: true): void;
|
||||
deleteUserInstances(uuid: string | null, instanceIds: IUserApp[], allUsers = false) {
|
||||
const users = allUsers ? Array.from(this.objects.values()) : [this.getInstance(uuid!)];
|
||||
if (!users || users.length === 0) return;
|
||||
instanceIds.forEach((value) => {
|
||||
if (!value.daemonId || !value.instanceUuid)
|
||||
throw new Error("Type error, The instances of user must be IUserHaveInstance array.");
|
||||
});
|
||||
users.forEach((user) => {
|
||||
if (!user) return;
|
||||
user.instances = user.instances.filter((value) => {
|
||||
for (const instance of instanceIds) {
|
||||
if (instance.daemonId === value.daemonId && instance.instanceUuid === value.instanceUuid)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getUserByUserName(userName: string) {
|
||||
for (const map of this.objects) {
|
||||
const user = map[1];
|
||||
|
Loading…
Reference in New Issue
Block a user