Skip to content

mtx-separate: delete bug #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/aws-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module.exports = class AWSAttachmentsService extends require("./basic") {

const stored = super.put(attachments, metadata);
await Promise.all([stored, multipartUpload.done()]);
if (this.kind === 's3') scanRequest(attachments, { ID: metadata.ID })
if (this.kind === 's3') scanRequest(attachments, { ID: metadata.ID },req)
} catch (err) {
console.error(err); // eslint-disable-line no-console
}
Expand All @@ -128,21 +128,21 @@ module.exports = class AWSAttachmentsService extends require("./basic") {
}
}

async deleteAttachment(key) {
async deleteAttachment(key,req) {
if (!key) return;
return await this.delete(key);
return await this.delete(key,req);
}

async deleteAttachmentsWithKeys(records, req) {
if (req?.attachmentsToDelete?.length > 0) {
req.attachmentsToDelete.forEach((attachment) => {
this.deleteAttachment(attachment.url);
this.deleteAttachment(attachment.url,req);
});
}
}

async attachDeletionData(req) {
const attachments = cds.model.definitions[req?.query?.target?.name + ".attachments"];
const attachments = cds.model.definitions[req?.target?.name + ".attachments"];
if (attachments) {
const diffData = await req.diff();
let deletedAttachments = [];
Expand Down Expand Up @@ -186,7 +186,7 @@ module.exports = class AWSAttachmentsService extends require("./basic") {
await Promise.all([multipartUpload.done()]);

const keys = { ID: req.data.ID }
scanRequest(req.target, keys)
scanRequest(req.target, keys,req)
}
} else if (req?.data?.note) {
const key = { ID: req.data.ID };
Expand All @@ -209,8 +209,8 @@ module.exports = class AWSAttachmentsService extends require("./basic") {
}

async attachDraftDeletionData(req) {
const draftEntity = cds.model.definitions[req?.query?.target?.name];
const name = req?.query?.target?.name;
const draftEntity = cds.model.definitions[req?.target?.name];
const name = req?.target?.name;
const activeEntity = name ? cds.model.definitions?.[name.split(".").slice(0, -1).join(".")] : undefined;

if (!draftEntity || !activeEntity) return;
Expand Down Expand Up @@ -295,8 +295,8 @@ module.exports = class AWSAttachmentsService extends require("./basic") {
return response.DeleteMarker;
}

async deleteInfectedAttachment(Attachments, key) {
async deleteInfectedAttachment(Attachments, key,req) {
const response = await SELECT.from(Attachments, key).columns('url')
return await this.delete(response.url);
return await this.delete(response.url,req);
}
};
4 changes: 2 additions & 2 deletions lib/malwareScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const cds = require('@sap/cds')
const DEBUG = cds.debug('attachments')
const { SELECT } = cds.ql;

async function scanRequest(Attachments, key) {
async function scanRequest(Attachments, key,req) {
const scanEnabled = cds.env.requires?.attachments?.scan ?? true
const AttachmentsSrv = await cds.connect.to("attachments")

Expand Down Expand Up @@ -64,7 +64,7 @@ async function scanRequest(Attachments, key) {
const status = responseText.malwareDetected ? "Infected" : "Clean"
if (status === "Infected") {
DEBUG?.("Malware detected in the file, deleting attachment content from db", key)
await AttachmentsSrv.deleteInfectedAttachment(currEntity, key)
await AttachmentsSrv.deleteInfectedAttachment(currEntity, key,req)
}
await updateStatus(AttachmentsSrv, key, status, currEntity, draftEntity, activeEntity)
} catch (err) {
Expand Down
Loading