feat: demo env disable create/update/destroy actions
This commit is contained in:
		
							parent
							
								
									b6e41a6e45
								
							
						
					
					
						commit
						988b265bb8
					
				@ -119,6 +119,26 @@ api.registerPlugin('plugin-file-manager', [path.resolve(__dirname, '../../../plu
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
(async () => {
 | 
					(async () => {
 | 
				
			||||||
  await api.loadPlugins();
 | 
					  await api.loadPlugins();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  api.resourcer.use(async (ctx, next) => {
 | 
				
			||||||
 | 
					    if (process.env.NOCOBASE_ENV !== 'demo') {
 | 
				
			||||||
 | 
					      return next();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const currentUser = ctx.state.currentUser;
 | 
				
			||||||
 | 
					    if (currentUser && currentUser.username === 'admin') {
 | 
				
			||||||
 | 
					      return next();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const { actionName } = ctx.action.params;
 | 
				
			||||||
 | 
					    if (['create', 'update', 'destroy'].includes(actionName)) {
 | 
				
			||||||
 | 
					      ctx.body = {
 | 
				
			||||||
 | 
					        data: {},
 | 
				
			||||||
 | 
					        meta: {},
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    await next();
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  await api.database.getModel('collections').load({skipExisting: true});
 | 
					  await api.database.getModel('collections').load({skipExisting: true});
 | 
				
			||||||
  api.listen(process.env.HTTP_PORT, () => {
 | 
					  api.listen(process.env.HTTP_PORT, () => {
 | 
				
			||||||
    console.log(`http://localhost:${process.env.HTTP_PORT}/`);
 | 
					    console.log(`http://localhost:${process.env.HTTP_PORT}/`);
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,7 @@ export default async (ctx, next) => {
 | 
				
			|||||||
  const fields = await collection.getFields();
 | 
					  const fields = await collection.getFields();
 | 
				
			||||||
  const actions = await collection.getActions();
 | 
					  const actions = await collection.getActions();
 | 
				
			||||||
  const actionNames = view.options.actionNames||[];
 | 
					  const actionNames = view.options.actionNames||[];
 | 
				
			||||||
  console.log(view.options);
 | 
					  // console.log(view.options);
 | 
				
			||||||
  if (view.type === 'table') {
 | 
					  if (view.type === 'table') {
 | 
				
			||||||
    const defaultTabs = await collection.getTabs({
 | 
					    const defaultTabs = await collection.getTabs({
 | 
				
			||||||
      where: {
 | 
					      where: {
 | 
				
			||||||
 | 
				
			|||||||
@ -223,7 +223,7 @@ export default {
 | 
				
			|||||||
      interface: 'radio',
 | 
					      interface: 'radio',
 | 
				
			||||||
      type: 'virtual',
 | 
					      type: 'virtual',
 | 
				
			||||||
      name: 'defaultPerPage',
 | 
					      name: 'defaultPerPage',
 | 
				
			||||||
      title: '每页显示几行数据',
 | 
					      title: '默认每页显示几行数据',
 | 
				
			||||||
      defaultValue: 50,
 | 
					      defaultValue: 50,
 | 
				
			||||||
      dataSource: [
 | 
					      dataSource: [
 | 
				
			||||||
        {label: '10', value: 10},
 | 
					        {label: '10', value: 10},
 | 
				
			||||||
 | 
				
			|||||||
@ -291,7 +291,7 @@ export default async (ctx, next) => {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
      if (field.get('interface') === 'subTable') {
 | 
					      if (field.get('interface') === 'subTable') {
 | 
				
			||||||
        const children = await field.getChildren();
 | 
					        const children = await field.getChildren();
 | 
				
			||||||
        console.log(children);
 | 
					        // console.log(children);
 | 
				
			||||||
        for (const child of children) {
 | 
					        for (const child of children) {
 | 
				
			||||||
          if (!['subTable', 'linkTo', 'attachment', 'updatedBy', 'createdBy'].includes(child.get('interface'))) {
 | 
					          if (!['subTable', 'linkTo', 'attachment', 'updatedBy', 'createdBy'].includes(child.get('interface'))) {
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user