Browse Source

feat: ajv validation

pull/8281/head
Pranav C 6 months ago
parent
commit
579b64f5b7
  1. 10
      packages/nocodb/src/models/GalleryViewColumn.ts
  2. 6
      packages/nocodb/src/models/KanbanViewColumn.ts
  3. 39
      packages/nocodb/src/services/view-columns.service.ts

10
packages/nocodb/src/models/GalleryViewColumn.ts

@ -122,20 +122,12 @@ export default class GalleryViewColumn {
return views?.map((v) => new GalleryViewColumn(v)); return views?.map((v) => new GalleryViewColumn(v));
} }
// todo: update prop names
static async update( static async update(
columnId: string, columnId: string,
body: Partial<GalleryViewColumn>, body: Partial<GalleryViewColumn>,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
const updateObj = extractProps(body, [ const updateObj = extractProps(body, ['order', 'show']);
'order',
'show',
'width',
'group_by',
'group_by_order',
'group_by_sort',
]);
// get existing cache // get existing cache
const key = `${CacheScope.GALLERY_VIEW_COLUMN}:${columnId}`; const key = `${CacheScope.GALLERY_VIEW_COLUMN}:${columnId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);

6
packages/nocodb/src/models/KanbanViewColumn.ts

@ -121,11 +121,7 @@ export default class KanbanViewColumn implements KanbanColumnType {
) { ) {
const updateObj = extractProps(body, [ const updateObj = extractProps(body, [
'order', 'order',
'show', 'show'
'width',
'group_by',
'group_by_order',
'group_by_sort',
]); ]);
// get existing cache // get existing cache
const key = `${CacheScope.KANBAN_VIEW_COLUMN}:${columnId}`; const key = `${CacheScope.KANBAN_VIEW_COLUMN}:${columnId}`;

39
packages/nocodb/src/services/view-columns.service.ts

@ -105,7 +105,11 @@ export class ViewColumnsService {
const columns = Array.isArray(param.columns) const columns = Array.isArray(param.columns)
? param.columns ? param.columns
: param.columns[APIContext.VIEW_COLUMNS]; : param.columns?.[APIContext.VIEW_COLUMNS];
if (!columns) {
NcError.badRequest('Invalid request - fields not found');
}
const view = await View.get(viewId); const view = await View.get(viewId);
@ -113,11 +117,12 @@ export class ViewColumnsService {
let result: any; let result: any;
const ncMeta = await Noco.ncMeta.startTransaction(); const ncMeta = await Noco.ncMeta.startTransaction();
try {
if (!view) {
NcError.notFound('View not found');
}
if (!view) {
NcError.notFound('View not found');
}
try {
const table = View.extractViewColumnsTableName(view); const table = View.extractViewColumnsTableName(view);
// iterate over view columns and update/insert accordingly // iterate over view columns and update/insert accordingly
@ -132,6 +137,10 @@ export class ViewColumnsService {
switch (view.type) { switch (view.type) {
case ViewTypes.GRID: case ViewTypes.GRID:
validatePayload(
'swagger.json#/components/schemas/GridColumnReq',
column,
);
if (existingCol) { if (existingCol) {
updateOrInsertOptions.push( updateOrInsertOptions.push(
GridViewColumn.update(existingCol.id, column, ncMeta), GridViewColumn.update(existingCol.id, column, ncMeta),
@ -150,6 +159,10 @@ export class ViewColumnsService {
} }
break; break;
case ViewTypes.GALLERY: case ViewTypes.GALLERY:
validatePayload(
'swagger.json#/components/schemas/GalleryColumnReq',
column,
);
if (existingCol) { if (existingCol) {
updateOrInsertOptions.push( updateOrInsertOptions.push(
GalleryViewColumn.update(existingCol.id, column, ncMeta), GalleryViewColumn.update(existingCol.id, column, ncMeta),
@ -168,6 +181,10 @@ export class ViewColumnsService {
} }
break; break;
case ViewTypes.KANBAN: case ViewTypes.KANBAN:
validatePayload(
'swagger.json#/components/schemas/KanbanColumnReq',
column,
);
if (existingCol) { if (existingCol) {
updateOrInsertOptions.push( updateOrInsertOptions.push(
KanbanViewColumn.update(existingCol.id, column, ncMeta), KanbanViewColumn.update(existingCol.id, column, ncMeta),
@ -186,6 +203,10 @@ export class ViewColumnsService {
} }
break; break;
case ViewTypes.MAP: case ViewTypes.MAP:
validatePayload(
'swagger.json#/components/schemas/MapColumn',
column,
);
if (existingCol) { if (existingCol) {
updateOrInsertOptions.push( updateOrInsertOptions.push(
MapViewColumn.update(existingCol.id, column, ncMeta), MapViewColumn.update(existingCol.id, column, ncMeta),
@ -204,6 +225,10 @@ export class ViewColumnsService {
} }
break; break;
case ViewTypes.FORM: case ViewTypes.FORM:
validatePayload(
'swagger.json#/components/schemas/FormColumnReq',
column,
);
if (existingCol) { if (existingCol) {
updateOrInsertOptions.push( updateOrInsertOptions.push(
FormViewColumn.update(existingCol.id, column, ncMeta), FormViewColumn.update(existingCol.id, column, ncMeta),
@ -222,6 +247,10 @@ export class ViewColumnsService {
} }
break; break;
case ViewTypes.CALENDAR: case ViewTypes.CALENDAR:
validatePayload(
'swagger.json#/components/schemas/CalendarColumnReq',
column,
);
if (existingCol) { if (existingCol) {
updateOrInsertOptions.push( updateOrInsertOptions.push(
CalendarViewColumn.update(existingCol.id, column, ncMeta), CalendarViewColumn.update(existingCol.id, column, ncMeta),

Loading…
Cancel
Save