diff --git a/OpenFlow/src/DatabaseConnection.ts b/OpenFlow/src/DatabaseConnection.ts index 78997679..95356fb3 100644 --- a/OpenFlow/src/DatabaseConnection.ts +++ b/OpenFlow/src/DatabaseConnection.ts @@ -2964,7 +2964,7 @@ export class DatabaseConnection extends events.EventEmitter { for (let i = 0; i < collections.length; i++) { let collection = collections[i]; // var res = await this.DeleteMany(query, null, collection.name, null, jwt, span); - var res = await this.DeleteMany({}, null, collection.name, doc._id, jwt, span); + var res = await this.DeleteMany({}, null, collection.name, doc._id, false, jwt, span); Logger.instanse.info("DatabaseConnection", "DeleteOne", "[" + user.username + "][" + collection.name + "] Deleted " + res + " items from " + collection.name + " cleaning up after company " + doc.name); } // } @@ -3049,7 +3049,7 @@ export class DatabaseConnection extends events.EventEmitter { continue; } let startTime = new Date(); - var res = await this.DeleteMany({ "$or": [{ "_createdbyid": doc._id }, { "_modifiedbyid": doc._id }] }, null, collection.name, doc._id, jwt, span); + var res = await this.DeleteMany({ "$or": [{ "_createdbyid": doc._id }, { "_modifiedbyid": doc._id }] }, null, collection.name, doc._id, false, jwt, span); // @ts-ignore var timeDiff = ((new Date()) - startTime); //in ms Logger.instanse.info("DatabaseConnection", "DeleteOne", "[" + user.username + "][" + collection.name + "] Deleted " + res + " items from " + collection.name + " cleaning up after user " + doc.name + " (" + timeDiff + "ms)"); @@ -3108,7 +3108,7 @@ export class DatabaseConnection extends events.EventEmitter { * @param {string} jwt JWT of user who is doing the delete, ensuring rights * @returns Promise */ - async DeleteMany(query: string | any, ids: string[], collectionname: string, queryas: string, jwt: string, parent: Span): Promise { + async DeleteMany(query: string | any, ids: string[], collectionname: string, queryas: string, recursive: boolean, jwt: string, parent: Span): Promise { if (NoderedUtil.IsNullUndefinded(ids) && NoderedUtil.IsNullUndefinded(query)) { throw Error("id cannot be null"); } const span: Span = Logger.otel.startSubSpan("db.DeleteMany", parent); try { @@ -3201,6 +3201,11 @@ export class DatabaseConnection extends events.EventEmitter { } Logger.instanse.verbose("DatabaseConnection", "DeleteMany", "[" + user.username + "][" + collectionname + "] deleted " + deletecounter + " files in database"); return deletecounter; + } else if (recursive && !NoderedUtil.IsNullUndefinded(ids) && ids.length > 0) { + for (let i = 0; i < ids.length; i++) { + await this.DeleteOne(ids[i], collectionname, recursive, jwt, span); + } + return ids.length; } else { let bulkInsert = this.db.collection(collectionname + "_hist").initializeUnorderedBulkOp(); let bulkRemove = this.db.collection(collectionname).initializeUnorderedBulkOp() diff --git a/OpenFlow/src/Messages/Message.ts b/OpenFlow/src/Messages/Message.ts index b1bb47d4..114bcbba 100644 --- a/OpenFlow/src/Messages/Message.ts +++ b/OpenFlow/src/Messages/Message.ts @@ -1474,7 +1474,7 @@ export class Message { try { msg = DeleteManyMessage.assign(this.data); if (NoderedUtil.IsNullEmpty(msg.jwt)) { msg.jwt = this.jwt; } - msg.affectedrows = await Config.db.DeleteMany(msg.query, msg.ids, msg.collectionname, null, msg.jwt, span); + msg.affectedrows = await Config.db.DeleteMany(msg.query, msg.ids, msg.collectionname, null, msg.recursive, msg.jwt, span); delete msg.ids; } catch (error) { if (NoderedUtil.IsNullUndefinded(msg)) { (msg as any) = {}; } @@ -5202,7 +5202,7 @@ export class Message { msg.result = await Config.db._UpdateOne(null, wiq as any, "mq", 1, true, jwt, parent); if (msg.purge) { - await Config.db.DeleteMany({ "_type": "workitem", "wiqid": wiq._id }, null, "workitems", null, jwt, parent); + await Config.db.DeleteMany({ "_type": "workitem", "wiqid": wiq._id }, null, "workitems", null, false, jwt, parent); var items = await Config.db.query({ query: { "_type": "workitem", "wiqid": wiq._id }, collectionname: "workitems", top: 1, jwt }, parent); if (items.length > 0) { } @@ -5210,7 +5210,7 @@ export class Message { if (items.length > 0) { throw new Error("Failed purging workitemqueue " + wiq.name); } - await Config.db.DeleteMany({ "metadata.wiqid": wiq._id }, null, "fs.files", null, jwt, parent); + await Config.db.DeleteMany({ "metadata.wiqid": wiq._id }, null, "fs.files", null, false, jwt, parent); } } catch (error) { await handleError(null, error); @@ -5249,7 +5249,7 @@ export class Message { user = this.tuser; if (msg.purge) { - await Config.db.DeleteMany({ "_type": "workitem", "wiqid": wiq._id }, null, "workitems", null, jwt, parent); + await Config.db.DeleteMany({ "_type": "workitem", "wiqid": wiq._id }, null, "workitems", null, false, jwt, parent); var items = await Config.db.query({ query: { "_type": "workitem", "wiqid": wiq._id }, collectionname: "workitems", top: 1, jwt }, parent); if (items.length > 0) { items = await Config.db.query({ query: { "_type": "workitem", "wiqid": wiq._id }, collectionname: "workitems", top: 1, jwt }, parent); @@ -5257,7 +5257,7 @@ export class Message { if (items.length > 0) { throw new Error("Failed purging workitemqueue " + wiq.name); } - await Config.db.DeleteMany({ "metadata.wiqid": wiq._id }, null, "fs.files", null, jwt, parent); + await Config.db.DeleteMany({ "metadata.wiqid": wiq._id }, null, "fs.files", null, false, jwt, parent); } else { var items = await Config.db.query({ query: { "_type": "workitem", "wiqid": wiq._id }, collectionname: "workitems", top: 1, jwt }, parent); if (items.length > 0) { @@ -5296,7 +5296,7 @@ export class Message { switch (msg.command) { case "dumpwebsocketclients": if (!this.tuser.HasRoleId(WellknownIds.admins)) throw new Error("Access denied"); - await Config.db.DeleteMany({ "_type": "websocketclient" }, null, "websocketclients", null, jwt, parent); + await Config.db.DeleteMany({ "_type": "websocketclient" }, null, "websocketclients", null, false, jwt, parent); amqpwrapper.Instance().send("openflow", "", { "command": "dumpwebsocketclients" }, 10000, null, "", 1); break; case "killwebsocketclient": diff --git a/OpenFlow/src/OAuthProvider.ts b/OpenFlow/src/OAuthProvider.ts index eca84b2c..5be89a7c 100644 --- a/OpenFlow/src/OAuthProvider.ts +++ b/OpenFlow/src/OAuthProvider.ts @@ -436,7 +436,7 @@ export class Account { return token.item; } static async RemoveTokenRequest(code: string, parent: Span) { - let tokens = await Config.db.DeleteMany({ _type: "tokenrequest", "code": code }, null, "oauthtokens", null, Crypt.rootToken(), parent); + let tokens = await Config.db.DeleteMany({ _type: "tokenrequest", "code": code }, null, "oauthtokens", null, false, Crypt.rootToken(), parent); return tokens[0]; } } diff --git a/OpenFlowNodeRED/package.json b/OpenFlowNodeRED/package.json index 8afcf028..287dff2a 100644 --- a/OpenFlowNodeRED/package.json +++ b/OpenFlowNodeRED/package.json @@ -25,7 +25,7 @@ }, "dependencies": { "@nodemailer/mailparser2": "^1.0.3", - "@openiap/openflow-api": "^2.1.1", + "@openiap/openflow-api": "^2.1.2", "@opentelemetry/api-metrics": "^0.32.0", "@opentelemetry/exporter-metrics-otlp-grpc": "^0.32.0", "@opentelemetry/exporter-trace-otlp-grpc": "^0.32.0", diff --git a/package.json b/package.json index c4bf27f9..76e85e09 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "dependencies": { "@fortawesome/fontawesome-free": "^5.15.3", "@kubernetes/client-node": "0.17.0", - "@openiap/openflow-api": "^2.1.1", + "@openiap/openflow-api": "^2.1.2", "@opentelemetry/api-metrics": "^0.32.0", "@opentelemetry/exporter-metrics-otlp-grpc": "^0.32.0", "@opentelemetry/exporter-trace-otlp-grpc": "^0.32.0",