mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	don't allow patching relation's value in ETAPI #3998
This commit is contained in:
		@@ -40,19 +40,25 @@ function register(router) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const ALLOWED_PROPERTIES_FOR_PATCH = {
 | 
					    const ALLOWED_PROPERTIES_FOR_PATCH_LABEL = {
 | 
				
			||||||
        'value': [v.notNull, v.isString],
 | 
					        'value': [v.notNull, v.isString],
 | 
				
			||||||
        'position': [v.notNull, v.isInteger]
 | 
					        'position': [v.notNull, v.isInteger]
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const ALLOWED_PROPERTIES_FOR_PATCH_RELATION = {
 | 
				
			||||||
 | 
					        'position': [v.notNull, v.isInteger]
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eu.route(router, 'patch' ,'/etapi/attributes/:attributeId', (req, res, next) => {
 | 
					    eu.route(router, 'patch' ,'/etapi/attributes/:attributeId', (req, res, next) => {
 | 
				
			||||||
        const attribute = eu.getAndCheckAttribute(req.params.attributeId);
 | 
					        const attribute = eu.getAndCheckAttribute(req.params.attributeId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (attribute.type === 'relation') {
 | 
					        if (attribute.type === 'label') {
 | 
				
			||||||
 | 
					            eu.validateAndPatch(attribute, req.body, ALLOWED_PROPERTIES_FOR_PATCH_LABEL);
 | 
				
			||||||
 | 
					        } else if (attribute.type === 'relation') {
 | 
				
			||||||
            eu.getAndCheckNote(req.body.value);
 | 
					            eu.getAndCheckNote(req.body.value);
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        eu.validateAndPatch(attribute, req.body, ALLOWED_PROPERTIES_FOR_PATCH);
 | 
					            eu.validateAndPatch(attribute, req.body, ALLOWED_PROPERTIES_FOR_PATCH_RELATION);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        attribute.save();
 | 
					        attribute.save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user