Fixes #7162: Fix API-populated form fields when BASE_PATH is defined

This commit is contained in:
jeremystretch 2021-09-03 14:22:28 -04:00
parent 27c0e6dd5e
commit acb24489d1
13 changed files with 8 additions and 6 deletions

View File

@ -5,6 +5,7 @@
* [#7131](https://github.com/netbox-community/netbox/issues/7131) - Fix issue where Site fields were hidden when editing a VLAN group
* [#7148](https://github.com/netbox-community/netbox/issues/7148) - Fix issue where static query parameters with multiple values were not queried properly
* [#7153](https://github.com/netbox-community/netbox/issues/7153) - Allow clearing of assigned device type images
* [#7162](https://github.com/netbox-community/netbox/issues/7162) - Fix API-populated form fields when `BASE_PATH` is defined
* [#7164](https://github.com/netbox-community/netbox/issues/7164) - Fix styling of "decommissioned" label for circuits
* [#7169](https://github.com/netbox-community/netbox/issues/7169) - Fix CSV import file upload

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,5 @@
import { createToast } from './bs';
import { getElements, apiPatch, hasError, getSelectedOptions } from './util';
import { getElements, apiPatch, buildUrl, hasError, getSelectedOptions } from './util';
/**
* Mark each option element in the selected columns element as 'selected' so they are submitted to
@ -54,7 +54,8 @@ function removeColumns(event: Event): void {
* Submit form configuration to the NetBox API.
*/
async function submitFormConfig(formConfig: Dict<Dict>): Promise<APIResponse<APIUserConfig>> {
return await apiPatch<APIUserConfig>('/api/users/config/', formConfig);
const url = buildUrl('/api/users/config/');
return await apiPatch<APIUserConfig>(url, formConfig);
}
/**

View File

@ -111,7 +111,8 @@ function getCsrfToken(): string {
* Get the NetBox `settings.BASE_PATH` from the `<html/>` element's data attributes.
*
* @returns If there is no `BASE_PATH` specified, the return value will be `''`.
*/ function getBasePath(): string {
*/
function getBasePath(): string {
const value = document.documentElement.getAttribute('data-netbox-base-path');
if (value === null) {
return '';
@ -156,7 +157,7 @@ function queryParamsToObject(params: string): Record<string, Stringifiable[]> {
*
* @param path Relative path _after_ (excluding) the `BASE_PATH`.
*/
function buildUrl(destination: string): string {
export function buildUrl(destination: string): string {
// Separate the path from any URL search params.
const [pathname, search] = destination.split(/(?=\?)/g);
@ -184,7 +185,7 @@ function buildUrl(destination: string): string {
}
export async function apiRequest<R extends Dict, D extends ReqData = undefined>(
path: string,
url: string,
method: Method,
data?: D,
): Promise<APIResponse<R>> {
@ -196,7 +197,6 @@ export async function apiRequest<R extends Dict, D extends ReqData = undefined>(
body = JSON.stringify(data);
headers.set('content-type', 'application/json');
}
const url = buildUrl(path);
const res = await fetch(url, { method, body, headers, credentials: 'same-origin' });
const contentType = res.headers.get('Content-Type');