Browse Source

fix: delete comments on model delete (#8706)

* fix: missing transaction

* fix: hard delete comments on model delete
pull/8713/head
Mert E 6 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; return true;
} }
static async deleteRowComments( static async deleteModelComments(
context: NcContext, context: NcContext,
fk_model_id: string, fk_model_id: string,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
return ncMeta.metaUpdate( return ncMeta.metaDelete(
context.workspace_id, context.workspace_id,
context.base_id, context.base_id,
MetaTable.COMMENTS, MetaTable.COMMENTS,
{
is_deleted: true,
},
{ {
fk_model_id, 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({ const convertedAttachment = await this.convertAttachmentType(
banner_image_url: view?.banner_image_url, {
logo_url: view?.logo_url, banner_image_url: view?.banner_image_url,
}); logo_url: view?.logo_url,
},
ncMeta,
);
view.banner_image_url = convertedAttachment.banner_image_url || null; view.banner_image_url = convertedAttachment.banner_image_url || null;
view.logo_url = convertedAttachment.logo_url || null; view.logo_url = convertedAttachment.logo_url || null;
@ -221,6 +224,7 @@ export default class FormView implements FormViewType {
protected static async convertAttachmentType( protected static async convertAttachmentType(
formAttachments: Record<string, any>, formAttachments: Record<string, any>,
ncMeta = Noco.ncMeta,
) { ) {
try { try {
if (formAttachments) { if (formAttachments) {
@ -236,9 +240,12 @@ export default class FormView implements FormViewType {
if (formAttachments[key]?.path) { if (formAttachments[key]?.path) {
promises.push( promises.push(
PresignedUrl.getSignedUrl({ PresignedUrl.getSignedUrl(
path: formAttachments[key].path.replace(/^download\//, ''), {
}).then((r) => (formAttachments[key].signedPath = r)), path: formAttachments[key].path.replace(/^download\//, ''),
},
ncMeta,
).then((r) => (formAttachments[key].signedPath = r)),
); );
} else if (formAttachments[key]?.url) { } else if (formAttachments[key]?.url) {
if (formAttachments[key].url.includes('.amazonaws.com/')) { if (formAttachments[key].url.includes('.amazonaws.com/')) {
@ -246,10 +253,13 @@ export default class FormView implements FormViewType {
formAttachments[key].url.split('.amazonaws.com/')[1], formAttachments[key].url.split('.amazonaws.com/')[1],
); );
promises.push( promises.push(
PresignedUrl.getSignedUrl({ PresignedUrl.getSignedUrl(
path: relativePath, {
s3: true, path: relativePath,
}).then((r) => (formAttachments[key].signedUrl = r)), 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, ncMeta = Noco.ncMeta,
force = false, force = false,
): Promise<boolean> { ): 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)) { for (const view of await this.getViews(context, true, ncMeta)) {
await view.delete(context, ncMeta); await view.delete(context, ncMeta);

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

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

Loading…
Cancel
Save