diff --git a/src/components/error-response-presenter.ts b/src/components/error-response-presenter.ts index 6cb5f685..ab2d14fb 100644 --- a/src/components/error-response-presenter.ts +++ b/src/components/error-response-presenter.ts @@ -663,6 +663,24 @@ export default (error: AppError | DBError) => { }, }; } + case US_ERRORS.WORKBOOK_TEMPLATE_CANT_BE_DELETED: { + return { + code: 403, + response: { + code, + message: "Workbook template can't be deleted", + }, + }; + } + case US_ERRORS.COLLECTION_WITH_WORKBOOK_TEMPLATE_CANT_BE_DELETED: { + return { + code: 403, + response: { + code, + message: "Collection with workbook template can't be deleted", + }, + }; + } default: return { code: 500, diff --git a/src/const/us-error-constants.ts b/src/const/us-error-constants.ts index 6d38978c..7f7f2436 100644 --- a/src/const/us-error-constants.ts +++ b/src/const/us-error-constants.ts @@ -95,6 +95,9 @@ const US_ERRORS = { MOVE_TENANT_CONTENT_ERROR: 'MOVE_TENANT_CONTENT_ERROR', INCORRECT_WORKBOOK_ID_HEADER: 'INCORRECT_WORKBOOK_ID_HEADER', WORKBOOK_ISOLATION_INTERRUPTION: 'WORKBOOK_ISOLATION_INTERRUPTION', + WORKBOOK_TEMPLATE_CANT_BE_DELETED: 'WORKBOOK_TEMPLATE_CANT_BE_DELETED', + COLLECTION_WITH_WORKBOOK_TEMPLATE_CANT_BE_DELETED: + 'COLLECTION_WITH_WORKBOOK_TEMPLATE_CANT_BE_DELETED', }; export const ERROR_BY_DLS_STATUS_CODE: {[key: number]: string} = { diff --git a/src/services/new/collection/delete-collection.ts b/src/services/new/collection/delete-collection.ts index 02626eae..f0617510 100644 --- a/src/services/new/collection/delete-collection.ts +++ b/src/services/new/collection/delete-collection.ts @@ -4,12 +4,13 @@ import {ServiceArgs} from '../types'; import {getPrimary} from '../utils'; import {deleteWorkbook} from '../workbook'; import {makeSchemaValidator} from '../../../components/validation-schema-compiler'; -import {CURRENT_TIMESTAMP} from '../../../const'; +import {CURRENT_TIMESTAMP, US_ERRORS} from '../../../const'; import {raw, transaction} from 'objection'; import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection'; import {WorkbookModel, WorkbookModelColumn} from '../../../db/models/new/workbook'; import Utils, {logInfo} from '../../../utils'; import {CollectionPermission} from '../../../entities/collection'; +import {AppError} from '@gravity-ui/nodekit'; const validateArgs = makeSchemaValidator({ type: 'object', @@ -128,6 +129,14 @@ export const deleteCollection = async ( }) .timeout(WorkbookModel.DEFAULT_QUERY_TIMEOUT); + for (const workbook of workbooksForDelete) { + if (workbook.isTemplate) { + throw new AppError("Collection with workbook template can't be deleted", { + code: US_ERRORS.COLLECTION_WITH_WORKBOOK_TEMPLATE_CANT_BE_DELETED, + }); + } + } + // TODO: Rewrite the deletion for the optimal number of requests await Promise.all( workbooksForDelete.map((workbook) => { diff --git a/src/services/new/workbook/delete-workbook.ts b/src/services/new/workbook/delete-workbook.ts index df567a14..ab0ffefe 100644 --- a/src/services/new/workbook/delete-workbook.ts +++ b/src/services/new/workbook/delete-workbook.ts @@ -54,6 +54,12 @@ export const deleteWorkbook = async ( {workbookId}, ); + if (workbook.model.isTemplate) { + throw new AppError("Workbook template can't be deleted", { + code: US_ERRORS.WORKBOOK_TEMPLATE_CANT_BE_DELETED, + }); + } + if (accessServiceEnabled && !skipCheckPermissions) { let parentIds: string[] = [];