Commit 9344ba7a authored by benjaminParisel's avatar benjaminParisel Committed by julienmege

fix(apiCall): Update regex to put Bonita REST API complete in properties (#2615)

* fix(apiCall): Update regex to put Bonita REST API complete in properties

* Add a new regex for external extension

Covers [UID-11](https://bonitasoft.atlassian.net/browse/UID-11)

* add test to explain not only ../API is parsing
parent beb6d7d5
......@@ -24,6 +24,7 @@ import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static org.bonitasoft.web.designer.config.WebSocketConfig.PREVIEWABLE_REMOVAL;
import static org.bonitasoft.web.designer.config.WebSocketConfig.PREVIEWABLE_UPDATE;
import static org.bonitasoft.web.designer.controller.ResponseHeadersHelper.getMovedResourceResponse;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
......@@ -38,7 +39,6 @@ import org.bonitasoft.web.designer.controller.asset.PageAssetPredicate;
import org.bonitasoft.web.designer.controller.export.properties.BonitaResourcePredicate;
import org.bonitasoft.web.designer.controller.export.properties.BonitaResourceTransformer;
import org.bonitasoft.web.designer.controller.export.properties.ConstantPropertyValuePredicate;
import org.bonitasoft.web.designer.controller.export.properties.PagePropertiesBuilder;
import org.bonitasoft.web.designer.experimental.mapping.ContractToPageMapper;
import org.bonitasoft.web.designer.experimental.mapping.FormScope;
import org.bonitasoft.web.designer.model.JsonViewLight;
......@@ -72,7 +72,9 @@ import org.springframework.web.bind.annotation.RestController;
public class PageResource extends AssetResource<Page> {
protected static final Logger logger = LoggerFactory.getLogger(PageResource.class);
public static final String BONITA_RESOURCE_REGEX = ".+/API/([^ /]*)/([^ /?]*)[/?]?[^/]*"; // matches ..... /API/{}/{}?...
public static final String BONITA_RESOURCE_REGEX = ".+/API/(?!extension)([^ /]*)/([^ /?]*)[/?]?[^/]*";// matches ..... /API/{}/{}?...
public static final String EXTENSION_RESOURCE_REGEX = ".+/API/(?=extension)([^ /]*)/([^ (?|{)]*).*";
private PageRepository pageRepository;
private SimpMessagingTemplate messagingTemplate;
private ContractToPageMapper contractToPageMapper;
......@@ -229,6 +231,12 @@ public class PageResource extends AssetResource<Page> {
filterValues(page.getData(), new BonitaResourcePredicate(BONITA_RESOURCE_REGEX)).values(),
new BonitaResourceTransformer(BONITA_RESOURCE_REGEX)));
List<String> extension = newArrayList(transform(
filterValues(page.getData(), new BonitaResourcePredicate(EXTENSION_RESOURCE_REGEX)).values(),
new BonitaResourceTransformer(EXTENSION_RESOURCE_REGEX)));
resources.addAll(extension);
Iterable<Component> components = componentVisitor.visit(page);
if (any(components, new ConstantPropertyValuePredicate("Start process"))) {
......
......@@ -48,6 +48,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
......@@ -745,6 +746,27 @@ public class PageResourceTest {
assertThat(properties).contains("[GET|bpm/userTask, GET|living/application-menu, POST|bpm/process]");
}
@Test
public void should_add_bonita_api_extensions_resources_found_in_pages_widgets() throws Exception {
setUpPageForResourcesTests();
Set<String> authRules = new TreeSet<>();
authRules.add("POST|bpm/process");
HashMap<String, Data> data = new HashMap<>();
data.put("foo", anApiData("../API/extension/CA31/SQLToObject?filter=mine"));
// Not supported in plateform side. Prefer use queryParam like ?id=4
data.put("bar", anApiData("../API/extension/user/4"));
data.put("aa", anApiData("../API/extension/group/list"));
data.put("session", anApiData("../API/extension/user/group/unusedid"));
data.put("ab", anApiData("http://localhost:8080/bonita/portal/API/extension/vehicule/voiture/roue?p=0&c=10&f=case_id={{caseId}}"));
page.setData(data);
when(authRulesCollector.visit(page)).thenReturn(authRules);
String properties = new String(pageResource.getResources(page.getId()).toString());
assertThat(properties).contains("[GET|extension/group/list, GET|extension/vehicule/voiture/roue, GET|extension/user/4, GET|extension/user/group/unusedid, GET|extension/CA31/SQLToObject, POST|bpm/process]");
}
@Test
public void should_add_start_process_resource_if_a_start_process_submit_is_contained_in_the_page() throws Exception {
setUpPageForResourcesTests();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment