Browse Source

fix: delete comments on model delete (#8706)

* fix: missing transaction

* fix: hard delete comments on model delete
pull/8713/head
Mert E 4 months ago committed by GitHub
parent
commit
d0f7fb8f6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      packages/nocodb/src/models/Comment.ts
  2. 32
      packages/nocodb/src/models/FormView.ts
  3. 2
      packages/nocodb/src/models/Model.ts
  4. 4
      packages/nocodb/src/models/PresignedUrl.ts

7
packages/nocodb/src/models/Comment.ts

@ -142,18 +142,15 @@ export default class Comment implements CommentType {
return true;
}
static async deleteRowComments(
static async deleteModelComments(
context: NcContext,
fk_model_id: string,
ncMeta = Noco.ncMeta,
) {
return ncMeta.metaUpdate(
return ncMeta.metaDelete(
context.workspace_id,
context.base_id,
MetaTable.COMMENTS,
{
is_deleted: true,
},
{
fk_model_id,
},

32
packages/nocodb/src/models/FormView.ts

@ -74,10 +74,13 @@ export default class FormView implements FormViewType {
}
}
const convertedAttachment = await this.convertAttachmentType({
banner_image_url: view?.banner_image_url,
logo_url: view?.logo_url,
});
const convertedAttachment = await this.convertAttachmentType(
{
banner_image_url: view?.banner_image_url,
logo_url: view?.logo_url,
},
ncMeta,
);
view.banner_image_url = convertedAttachment.banner_image_url || null;
view.logo_url = convertedAttachment.logo_url || null;
@ -221,6 +224,7 @@ export default class FormView implements FormViewType {
protected static async convertAttachmentType(
formAttachments: Record<string, any>,
ncMeta = Noco.ncMeta,
) {
try {
if (formAttachments) {
@ -236,9 +240,12 @@ export default class FormView implements FormViewType {
if (formAttachments[key]?.path) {
promises.push(
PresignedUrl.getSignedUrl({
path: formAttachments[key].path.replace(/^download\//, ''),
}).then((r) => (formAttachments[key].signedPath = r)),
PresignedUrl.getSignedUrl(
{
path: formAttachments[key].path.replace(/^download\//, ''),
},
ncMeta,
).then((r) => (formAttachments[key].signedPath = r)),
);
} else if (formAttachments[key]?.url) {
if (formAttachments[key].url.includes('.amazonaws.com/')) {
@ -246,10 +253,13 @@ export default class FormView implements FormViewType {
formAttachments[key].url.split('.amazonaws.com/')[1],
);
promises.push(
PresignedUrl.getSignedUrl({
path: relativePath,
s3: true,
}).then((r) => (formAttachments[key].signedUrl = r)),
PresignedUrl.getSignedUrl(
{
path: relativePath,
s3: true,
},
ncMeta,
).then((r) => (formAttachments[key].signedUrl = r)),
);
}
}

2
packages/nocodb/src/models/Model.ts

@ -481,7 +481,7 @@ export default class Model implements TableType {
ncMeta = Noco.ncMeta,
force = false,
): Promise<boolean> {
await Comment.deleteRowComments(context, this.id, ncMeta);
await Comment.deleteModelComments(context, this.id, ncMeta);
for (const view of await this.getViews(context, true, ncMeta)) {
await view.delete(context, ncMeta);

4
packages/nocodb/src/models/PresignedUrl.ts

@ -92,7 +92,7 @@ export default class PresignedUrl {
expireSeconds?: number;
s3?: boolean;
},
_ncMeta = Noco.ncMeta,
ncMeta = Noco.ncMeta,
) {
const { path, expireSeconds = DEFAULT_EXPIRE_SECONDS, s3 = false } = param;
const expireAt = roundExpiry(
@ -124,7 +124,7 @@ export default class PresignedUrl {
if (s3) {
// if not present, create a new url
const storageAdapter = await NcPluginMgrv2.storageAdapter();
const storageAdapter = await NcPluginMgrv2.storageAdapter(ncMeta);
tempUrl = await (storageAdapter as any).getSignedUrl(
path,

Loading…
Cancel
Save