Skip to content

Commit

Permalink
Fix getApiRootUri in tests. Update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiostalla committed Dec 27, 2023
1 parent 0bf8748 commit 4f8c6d2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Possibility to specify the project root with --dev for PortofinoDrivenBootApplication
- Notes on how to connect using JNDI in `hibernate.properties`

### Changed
- Rationalized how the API root URI is computed across the codebase

### Fixed
- Search field disabled for foreign keys [#618](https://github.com/ManyDesigns/Portofino/issues/618)
- Several security vulnerabilities in dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,21 @@ public String getApiRootUri() {
}

public static String getApiRootUri(ServletContext servletContext, UriInfo uriInfo) {
return getApiRootUri(servletContext, uriInfo.getBaseUri());
return getApiRootUri(servletContext, uriInfo != null ? uriInfo.getBaseUri() : null);
}

public static String getApiRootUri(ServletContext servletContext, URI baseUri) {
String apiRoot = servletContext.getInitParameter("portofino.api.root");
if (apiRoot == null) {
apiRoot = "";
}
if (apiRoot.contains("://")) {
//Keep as is
} else if (!apiRoot.startsWith("/")) {
if (!apiRoot.contains("://") && !apiRoot.startsWith("/")) {
apiRoot = servletContext.getContextPath() + "/" + apiRoot;
}
if (!apiRoot.contains("://")) {
if (baseUri == null) {
throw new IllegalArgumentException("baseUri cannot be null when apiRoot is not absolute (" + apiRoot + ")");
}
String baseAddress = baseUri.getScheme() + "://" + baseUri.getAuthority();
if (!apiRoot.startsWith("/")) {
baseAddress += servletContext.getContextPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void delete() {
req.setParameter("name", "name");
req.setParameter("productid", "1");
req.setParameter("category", "BIRDS");
crudAction.httpPostMultipart();
crudAction.httpPostMultipart().close();
assertTrue(crudAction.form.validate());
blobField = (FileBlobField) crudAction.form.findFieldByPropertyName("descn");
assertNotNull(blobField.getValue());
Expand All @@ -276,7 +276,7 @@ public void delete() {
fail("The blob was not saved");
}

crudAction.httpPutMultipart();
crudAction.httpPutMultipart().close();
assertTrue(crudAction.form.validate());
blobField = (FileBlobField) crudAction.form.findFieldByPropertyName("descn");
assertNotNull(blobField.getValue());
Expand Down
21 changes: 12 additions & 9 deletions ui/projects/portofino/src/lib/portofino.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ export class PortofinoService {
//Avoid refreshing the token on startup as this might hit the wrong login action
const headers = {};
headers[NO_REFRESH_TOKEN_HEADER] = true;
this.http.get<ApiInfo>(this.localApiPath, { headers: headers }).subscribe(response => {
this.apiRoot = this.sanitizeApiRoot(response.apiRoot);
this.injector.get(AuthenticationStrategy).init({
apiRoot: this.apiRoot
});
if(response.disableAdministration) {
this.localApiPath = null; //Disable local API
this.http.get<ApiInfo>(this.localApiPath, { headers: headers }).subscribe({
next(response) {
this.apiRoot = this.sanitizeApiRoot(response.apiRoot);
this.injector.get(AuthenticationStrategy).init({
apiRoot: this.apiRoot
});
if (response.disableAdministration) {
this.localApiPath = null; //Disable local API
}
},
error() {
this.fallbackInit();
}
}, error => {
this.fallbackInit();
});
}

Expand Down

0 comments on commit 4f8c6d2

Please sign in to comment.