Skip to content

Commit

Permalink
Add error for move folder (#51)
Browse files Browse the repository at this point in the history
* Add error for move folder

* Add checkFileConnectionsExistence to Utils

* Fix imports
  • Loading branch information
Sergey-weber authored Jan 11, 2024
1 parent 8593b5e commit c033701
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/components/error-response-presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export default (error: AppError | DBError) => {
},
};
}
case US_ERRORS.FOLDER_ALREADY_EXIST_IN_TENANT:
case US_ERRORS.FOLDER_MOVE_FILE_CONNECTION_ERROR:
case US_ERRORS.ENTRY_IS_ALREADY_IN_WORKBOOK:
case US_ERRORS.ENTRY_IS_NOT_IN_WORKBOOK:
case US_ERRORS.FOLDER_DESTINATION_NOT_EXIST:
Expand Down
2 changes: 2 additions & 0 deletions src/const/us-error-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const US_ERRORS = {
LOCK_TOKEN_REQUIRED: 'LOCK_TOKEN_REQUIRED',
NOT_EXIST_LOCKED_ENTRY: 'NOT_EXIST_LOCKED_ENTRY',
NOT_EXIST_FOLDER: 'NOT_EXIST_FOLDER',
FOLDER_ALREADY_EXIST_IN_TENANT: 'FOLDER_ALREADY_EXIST_IN_TENANT',
FOLDER_MOVE_FILE_CONNECTION_ERROR: 'FOLDER_MOVE_FILE_CONNECTION_ERROR',
SCOPE_NOT_ALLOWED: 'SCOPE_NOT_ALLOWED',
NOT_EXIST_STATE_BY_HASH: 'NOT_EXIST_STATE_BY_HASH',
TENANTS_PER_CLOUD_QUOTA_EXCEEDED: 'TENANTS_PER_CLOUD_QUOTA_EXCEEDED',
Expand Down
18 changes: 1 addition & 17 deletions src/db/models/new/entry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,7 @@ import {Model} from '../../..';
import {RevisionModel} from '../revision';
import {WorkbookModel} from '../workbook';
import {Favorite} from '../favorite';

export enum EntryScope {
Connection = 'connection',
Dataset = 'dataset',
Widget = 'widget',
Dash = 'dash',
Folder = 'folder',
Config = 'config',
Pdf = 'pdf',
}

// "type" is a string field and value can be any string, this enum is only used for checks in code
export enum EntryType {
File = 'file',
GsheetsV2 = 'gsheets_v2',
// types can be added as needed
}
import {EntryScope} from './types';

export const EntryColumn = {
Scope: 'scope',
Expand Down
16 changes: 16 additions & 0 deletions src/db/models/new/entry/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export enum EntryScope {
Connection = 'connection',
Dataset = 'dataset',
Widget = 'widget',
Dash = 'dash',
Folder = 'folder',
Config = 'config',
Pdf = 'pdf',
}

// "type" is a string field and value can be any string, this enum is only used for checks in code
export enum EntryType {
File = 'file',
GsheetsV2 = 'gsheets_v2',
// types can be added as needed
}
3 changes: 2 additions & 1 deletion src/services/entry/actions/copy-to-workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {TransactionOrKnex} from 'objection';
import {AppError} from '@gravity-ui/nodekit';

import {getId} from '../../../db';
import {Entry, EntryColumn, EntryScope, EntryType} from '../../../db/models/new/entry';
import {Entry, EntryColumn} from '../../../db/models/new/entry';
import {EntryScope, EntryType} from '../../../db/models/new/entry/types';
import {JoinedEntryRevision} from '../../../db/presentations/joined-entry-revision';
import {WorkbookModel} from '../../../db/models/new/workbook';
import {CTX} from '../../../types/models';
Expand Down
3 changes: 2 additions & 1 deletion src/services/new/entry/copy-entry-to-workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {AppError} from '@gravity-ui/nodekit';
import {transaction} from 'objection';
import {getId} from '../../../db';
import OldEntry from '../../../db/models/entry';
import {Entry, EntryScope} from '../../../db/models/new/entry';
import {EntryScope} from '../../../db/models/new/entry/types';
import {Entry} from '../../../db/models/new/entry';
import {RevisionModel, RevisionModelColumn} from '../../../db/models/new/revision';
import {SyncLinks} from '../../../types/models/link';
import {US_ERRORS, BiTrackingLogs} from '../../../const';
Expand Down
7 changes: 2 additions & 5 deletions src/services/new/workbook/copy-workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {WorkbookModel, WorkbookModelColumn} from '../../../db/models/new/workboo
import {JoinedEntryRevisionColumns} from '../../../db/presentations/joined-entry-revision';
import {RevisionModel} from '../../../db/models/new/revision';
import Link from '../../../db/models/links';
import {Entry, EntryScope, EntryType} from '../../../db/models/new/entry';
import {Entry} from '../../../db/models/new/entry';
import {WorkbookPermission} from '../../../entities/workbook';
import Utils, {logInfo} from '../../../utils';
import {copyToWorkbook} from '../../entry/actions';
Expand Down Expand Up @@ -160,10 +160,7 @@ export const copyWorkbook = async (
})
.timeout(Entry.DEFAULT_QUERY_TIMEOUT);

const fileConnectionTypes: string[] = [EntryType.File, EntryType.GsheetsV2];
const fileConnectionExists = originEntries.some((entry) => {
return entry.scope === EntryScope.Connection && fileConnectionTypes.includes(entry.type);
});
const fileConnectionExists = Utils.checkFileConnectionsExistence(originEntries);

if (fileConnectionExists) {
throw new AppError(US_ERRORS.WORKBOOK_COPY_FILE_CONNECTION_ERROR, {
Expand Down
2 changes: 1 addition & 1 deletion src/services/new/workbook/get-workbook-content.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {makeSchemaValidator} from '../../../components/validation-schema-compiler';
import {RETURN_NAVIGATION_COLUMNS, DEFAULT_PAGE, DEFAULT_PAGE_SIZE} from '../../../const';
import Navigation from '../../../db/models/navigation';
import {EntryScope} from '../../../db/models/new/entry';
import {EntryScope} from '../../../db/models/new/entry/types';
import Utils, {logInfo} from '../../../utils';
import {UsPermission} from '../../../types/models';
import {ServiceArgs} from '../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Permissions} from '../../../../entities/workbook';
import type {WorkbookInstance} from '../../../../registry/common/entities/workbook/types';
import {Feature, isEnabledFeature} from '../../../../components/features';
import type {EntryScope as EntryScopeType} from '../../../../types/models';
import {EntryScope} from '../../../../db/models/new/entry';
import {EntryScope} from '../../../../db/models/new/entry/types';

export const getEntryPermissionsByWorkbook = ({
ctx,
Expand Down
14 changes: 14 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {EntryScope, USAPIResponse} from '../types/models';

import {ID_VARIABLES, CODING_BASE, TRUE_FLAGS, COPY_START, COPY_END} from '../const';

import type {Entry} from '../db/models/new/entry';
import {EntryScope as EntryScopeEnum, EntryType} from '../db/models/new/entry/types';

const PROFILES: {
[key: string]: any;
} = {};
Expand Down Expand Up @@ -347,4 +350,15 @@ export class Utils {
.map((word, index) => (index === 0 ? word : word[0].toUpperCase() + word.slice(1)))
.join('');
}

static checkFileConnectionsExistence(entries: Entry[]) {
const fileConnectionTypes: string[] = [EntryType.File, EntryType.GsheetsV2];

return entries.some((entry) => {
return (
entry.scope === EntryScopeEnum.Connection &&
fileConnectionTypes.includes(entry.type)
);
});
}
}

0 comments on commit c033701

Please sign in to comment.