Browse Source

feat: project update api allow meta prop

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3368/head
mertmit 2 years ago
parent
commit
d87b88f780
  1. 9
      packages/nocodb/src/lib/meta/api/projectApis.ts
  2. 12
      packages/nocodb/src/lib/meta/helpers/extractProps.ts
  3. 2
      packages/nocodb/src/lib/models/Base.ts
  4. 2
      packages/nocodb/src/lib/models/FormViewColumn.ts
  5. 2
      packages/nocodb/src/lib/models/FormulaColumn.ts
  6. 2
      packages/nocodb/src/lib/models/GridViewColumn.ts
  7. 2
      packages/nocodb/src/lib/models/HookLog.ts
  8. 2
      packages/nocodb/src/lib/models/Project.ts
  9. 2
      packages/nocodb/src/lib/models/SyncSource.ts
  10. 2
      packages/nocodb/src/lib/models/User.ts
  11. 2
      packages/nocodb/src/lib/models/View.ts

9
packages/nocodb/src/lib/meta/api/projectApis.ts

@ -23,6 +23,7 @@ import getColumnUiType from '../helpers/getColumnUiType';
import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue'; import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import { extractAndGenerateManyToManyRelations } from './metaDiffApis'; import { extractAndGenerateManyToManyRelations } from './metaDiffApis';
import { metaApiMetrics } from '../helpers/apiMetrics'; import { metaApiMetrics } from '../helpers/apiMetrics';
import { extractPropsAndSanitize } from '../helpers/extractProps';
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4); const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4);
@ -48,10 +49,10 @@ export async function projectUpdate(
) { ) {
const project = await Project.getWithInfo(req.params.projectId); const project = await Project.getWithInfo(req.params.projectId);
// only support updating title at this moment const data: Partial<Project> = extractPropsAndSanitize(req?.body, [
const data: any = { 'title',
title: DOMPurify.sanitize(req?.body?.title), 'meta',
}; ]);
if (await Project.getByTitle(data.title) && project.title !== data.title) { if (await Project.getByTitle(data.title) && project.title !== data.title) {
NcError.badRequest('Project title already in use'); NcError.badRequest('Project title already in use');

12
packages/nocodb/src/lib/meta/helpers/extractProps.ts

@ -1,7 +1,17 @@
export default function extractProps<T>(body: T, props: string[]): Partial<T> { import DOMPurify from 'isomorphic-dompurify';
export function extractProps<T>(body: T, props: string[]): Partial<T> {
// todo: throw error if no props found // todo: throw error if no props found
return props.reduce((o, key) => { return props.reduce((o, key) => {
if (key in body) o[key] = body[key]; if (key in body) o[key] = body[key];
return o; return o;
}, {}); }, {});
} }
export function extractPropsAndSanitize<T>(body: T, props: string[]): Partial<T> {
// todo: throw error if no props found
return props.reduce((o, key) => {
if (key in body) o[key] = DOMPurify.sanitize(body[key]);
return o;
}, {});
}

2
packages/nocodb/src/lib/models/Base.ts

@ -10,7 +10,7 @@ import Model from './Model';
import { BaseType } from 'nocodb-sdk'; import { BaseType } from 'nocodb-sdk';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
import CryptoJS from 'crypto-js'; import CryptoJS from 'crypto-js';
import extractProps from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
// todo: hide credentials // todo: hide credentials
export default class Base implements BaseType { export default class Base implements BaseType {

2
packages/nocodb/src/lib/models/FormViewColumn.ts

@ -3,7 +3,7 @@ import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import { FormColumnType } from 'nocodb-sdk'; import { FormColumnType } from 'nocodb-sdk';
import View from './View'; import View from './View';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
import extractProps from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
export default class FormViewColumn implements FormColumnType { export default class FormViewColumn implements FormColumnType {
id?: string; id?: string;

2
packages/nocodb/src/lib/models/FormulaColumn.ts

@ -1,7 +1,7 @@
import Noco from '../Noco'; import Noco from '../Noco';
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
import extractProps from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
export default class FormulaColumn { export default class FormulaColumn {
formula: string; formula: string;

2
packages/nocodb/src/lib/models/GridViewColumn.ts

@ -1,7 +1,7 @@
import Noco from '../Noco'; import Noco from '../Noco';
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import { GridColumnType } from 'nocodb-sdk'; import { GridColumnType } from 'nocodb-sdk';
import extractProps from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
import View from './View'; import View from './View';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';

2
packages/nocodb/src/lib/models/HookLog.ts

@ -1,6 +1,6 @@
import { MetaTable } from '../utils/globals'; import { MetaTable } from '../utils/globals';
import Noco from '../Noco'; import Noco from '../Noco';
import extractProps from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
import Hook from './Hook'; import Hook from './Hook';
import { HookLogType } from 'nocodb-sdk'; import { HookLogType } from 'nocodb-sdk';

2
packages/nocodb/src/lib/models/Project.ts

@ -7,7 +7,7 @@ import {
CacheScope, CacheScope,
MetaTable, MetaTable,
} from '../utils/globals'; } from '../utils/globals';
import extractProps from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
export default class Project implements ProjectType { export default class Project implements ProjectType {

2
packages/nocodb/src/lib/models/SyncSource.ts

@ -1,6 +1,6 @@
import Noco from '../Noco'; import Noco from '../Noco';
import { MetaTable } from '../utils/globals'; import { MetaTable } from '../utils/globals';
import extractProps from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
import User from './User'; import User from './User';
export default class SyncSource { export default class SyncSource {

2
packages/nocodb/src/lib/models/User.ts

@ -1,7 +1,7 @@
import { UserType } from 'nocodb-sdk'; import { UserType } from 'nocodb-sdk';
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import Noco from '../Noco'; import Noco from '../Noco';
import extractProps from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
export default class User implements UserType { export default class User implements UserType {
id: string; id: string;

2
packages/nocodb/src/lib/models/View.ts

@ -18,7 +18,7 @@ import GalleryViewColumn from './GalleryViewColumn';
import FormViewColumn from './FormViewColumn'; import FormViewColumn from './FormViewColumn';
import Column from './Column'; import Column from './Column';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
import extractProps from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
const { v4: uuidv4 } = require('uuid'); const { v4: uuidv4 } = require('uuid');
export default class View implements ViewType { export default class View implements ViewType {

Loading…
Cancel
Save