Skip to content

Commit d4a4495

Browse files
Merge branch 'main' into dxho-maintainer
2 parents 6f752c2 + 3bff6db commit d4a4495

File tree

3 files changed

+106
-7
lines changed

3 files changed

+106
-7
lines changed

public/apps/configuration/constants.tsx

+43-3
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,64 @@ export const CLUSTER_PERMISSIONS: string[] = [
145145
'cluster:admin/opensearch/ql/async_query/result',
146146
'cluster:admin/opensearch/ql/async_query/delete',
147147
'cluster:admin/opensearch/ppl',
148+
'cluster:admin/opensearch/ml/agents/delete',
149+
'cluster:admin/opensearch/ml/agents/get',
150+
'cluster:admin/opensearch/ml/agents/register',
151+
'cluster:admin/opensearch/ml/agents/search',
152+
'cluster:admin/opensearch/ml/config/get',
153+
'cluster:admin/opensearch/ml/create_connector',
154+
'cluster:admin/opensearch/ml/connectors/get',
155+
'cluster:admin/opensearch/ml/connectors/search',
156+
'cluster:admin/opensearch/ml/connectors/update',
157+
'cluster:admin/opensearch/ml/controllers/create',
158+
'cluster:admin/opensearch/ml/controllers/delete',
159+
'cluster:admin/opensearch/ml/controllers/deploy',
160+
'cluster:admin/opensearch/ml/controllers/get',
161+
'cluster:admin/opensearch/ml/controllers/undeploy',
162+
'cluster:admin/opensearch/ml/controllers/update',
148163
'cluster:admin/opensearch/ml/create_model_meta',
149164
'cluster:admin/opensearch/ml/execute',
150-
'cluster:admin/opensearch/ml/load_model',
151-
'cluster:admin/opensearch/ml/load_model_on_nodes',
165+
'cluster:admin/opensearch/ml/deploy_model',
166+
'cluster:admin/opensearch/ml/deploy_model_on_nodes',
167+
'cluster:admin/opensearch/ml/memory/conversation/get',
168+
'cluster:admin/opensearch/ml/memory/conversation/interaction/search',
169+
'cluster:admin/opensearch/ml/memory/conversation/delete',
170+
'cluster:admin/opensearch/ml/memory/conversation/list',
171+
'cluster:admin/opensearch/ml/memory/conversation/search',
172+
'cluster:admin/opensearch/ml/memory/conversation/create',
173+
'cluster:admin/opensearch/ml/memory/conversation/update',
174+
'cluster:admin/opensearch/ml/memory/interaction/create',
175+
'cluster:admin/opensearch/ml/memory/interaction/update',
176+
'cluster:admin/opensearch/ml/memory/interaction/get',
177+
'cluster:admin/opensearch/ml/memory/interaction/list',
178+
'cluster:admin/opensearch/ml/memory/trace/get',
179+
'cluster:admin/opensearch/ml/model_groups/delete',
180+
'cluster:admin/opensearch/ml/model_groups/get',
181+
'cluster:admin/opensearch/ml/model_groups/search',
182+
'cluster:admin/opensearch/ml/register_model_group',
183+
'cluster:admin/opensearch/ml/update_model_group',
152184
'cluster:admin/opensearch/ml/models/delete',
153185
'cluster:admin/opensearch/ml/models/get',
154186
'cluster:admin/opensearch/ml/models/search',
187+
'cluster:admin/opensearch/ml/models/update',
188+
'cluster:admin/opensearch/ml/models/update_cache',
155189
'cluster:admin/opensearch/ml/predict',
156190
'cluster:admin/opensearch/ml/profile/nodes',
191+
'cluster:admin/opensearch/ml/register_model',
192+
'cluster:admin/opensearch/ml/register_model_meta',
157193
'cluster:admin/opensearch/ml/stats/nodes',
158194
'cluster:admin/opensearch/ml/tasks/delete',
159195
'cluster:admin/opensearch/ml/tasks/get',
160196
'cluster:admin/opensearch/ml/tasks/search',
197+
'cluster:admin/opensearch/ml/tools/get',
198+
'cluster:admin/opensearch/ml/tools/list',
161199
'cluster:admin/opensearch/ml/train',
162200
'cluster:admin/opensearch/ml/trainAndPredict',
163-
'cluster:admin/opensearch/ml/unload_model',
201+
'cluster:admin/opensearch/ml/undeploy_model',
202+
'cluster:admin/opensearch/ml/undeploy_models',
164203
'cluster:admin/opensearch/ml/upload_model',
165204
'cluster:admin/opensearch/ml/upload_model_chunk',
205+
'cluster:admin/opensearch/mlinternal/forward',
166206
'cluster:admin/opensearch/observability/create',
167207
'cluster:admin/opensearch/observability/delete',
168208
'cluster:admin/opensearch/observability/get',

public/apps/login/login-page.tsx

+22-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
OPENID_AUTH_LOGIN_WITH_FRAGMENT,
3636
SAML_AUTH_LOGIN_WITH_FRAGMENT,
3737
} from '../../../common';
38+
import { getSavedTenant } from '../../utils/storage-utils';
3839

3940
interface LoginPageDeps {
4041
http: CoreStart['http'];
@@ -49,16 +50,34 @@ interface LoginButtonConfig {
4950
buttonstyle: string;
5051
}
5152

52-
function redirect(serverBasePath: string) {
53-
// navigate to nextUrl
53+
export function getNextPath(serverBasePath: string) {
5454
const urlParams = new URLSearchParams(window.location.search);
5555
let nextUrl = urlParams.get('nextUrl');
5656
if (!nextUrl || nextUrl.toLowerCase().includes('//')) {
5757
// Appending the next url with trailing slash. We do so because in case the serverBasePath is empty, we can simply
5858
// redirect to '/'.
5959
nextUrl = serverBasePath + '/';
6060
}
61-
window.location.href = nextUrl + window.location.hash;
61+
const savedTenant = getSavedTenant();
62+
const url = new URL(
63+
window.location.protocol + '//' + window.location.host + nextUrl + window.location.hash
64+
);
65+
if (
66+
!!savedTenant &&
67+
!(
68+
url.searchParams.has('security_tenant') ||
69+
url.searchParams.has('securitytenant') ||
70+
url.searchParams.has('securityTenant_')
71+
)
72+
) {
73+
url.searchParams.append('security_tenant', savedTenant);
74+
}
75+
return url.pathname + url.search + url.hash;
76+
}
77+
78+
function redirect(serverBasePath: string) {
79+
// navigate to nextUrl
80+
window.location.href = getNextPath(serverBasePath);
6281
}
6382

6483
export function extractNextUrlFromWindowLocation(): string {

public/apps/login/test/login-page.test.tsx

+41-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
import { shallow } from 'enzyme';
1717
import React from 'react';
1818
import { ClientConfigType } from '../../../types';
19-
import { LoginPage, extractNextUrlFromWindowLocation } from '../login-page';
19+
import { LoginPage, extractNextUrlFromWindowLocation, getNextPath } from '../login-page';
2020
import { validateCurrentPassword } from '../../../utils/login-utils';
2121
import { API_AUTH_LOGOUT } from '../../../../common';
2222
import { chromeServiceMock } from '../../../../../../src/core/public/mocks';
2323
import { AuthType } from '../../../../common';
24+
import { setSavedTenant } from '../../../utils/storage-utils';
2425

2526
jest.mock('../../../utils/login-utils', () => ({
2627
validateCurrentPassword: jest.fn(),
@@ -85,6 +86,45 @@ describe('test extractNextUrlFromWindowLocation', () => {
8586
});
8687
});
8788

89+
describe('test redirect', () => {
90+
test('extract redirect excludes security_tenant when no tenant in local storage', () => {
91+
// Trick to mock window.location
92+
const originalLocation = window.location;
93+
delete window.location;
94+
window.location = new URL('http://localhost:5601/app/login?nextUrl=%2Fapp%2Fdashboards') as any;
95+
setSavedTenant(null);
96+
const nextPath = getNextPath('');
97+
expect(nextPath).toEqual('/app/dashboards');
98+
window.location = originalLocation;
99+
});
100+
101+
test('extract redirect includes security_tenant when tenant in local storage', () => {
102+
const originalLocation = window.location;
103+
delete window.location;
104+
window.location = new URL('http://localhost:5601/app/login?nextUrl=%2Fapp%2Fdashboards');
105+
setSavedTenant('custom');
106+
const nextPath = getNextPath('');
107+
expect(nextPath).toEqual('/app/dashboards?security_tenant=custom');
108+
setSavedTenant(null);
109+
window.location = originalLocation;
110+
});
111+
112+
test('extract redirect includes security_tenant when tenant in local storage, existing url params and hash', () => {
113+
const originalLocation = window.location;
114+
delete window.location;
115+
window.location = new URL(
116+
"http://localhost:5601/app/login?nextUrl=%2Fapp%2Fdashboards?param1=value1#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g=(filters:!(),refreshInterval:(pause:!f,value:900000),time:(from:now-24h,to:now))&_a=(description:'Analyze%20mock%20flight%20data%20for%20OpenSearch-Air,%20Logstash%20Airways,%20OpenSearch%20Dashboards%20Airlines%20and%20BeatsWest',filters:!(),fullScreenMode:!f,options:(hidePanelTitles:!f,useMargins:!t),query:(language:kuery,query:''),timeRestore:!t,title:'%5BFlights%5D%20Global%20Flight%20Dashboard',viewMode:view)"
117+
);
118+
setSavedTenant('custom');
119+
const nextPath = getNextPath('');
120+
expect(nextPath).toEqual(
121+
"/app/dashboards?param1=value1&security_tenant=custom#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g=(filters:!(),refreshInterval:(pause:!f,value:900000),time:(from:now-24h,to:now))&_a=(description:'Analyze%20mock%20flight%20data%20for%20OpenSearch-Air,%20Logstash%20Airways,%20OpenSearch%20Dashboards%20Airlines%20and%20BeatsWest',filters:!(),fullScreenMode:!f,options:(hidePanelTitles:!f,useMargins:!t),query:(language:kuery,query:''),timeRestore:!t,title:'%5BFlights%5D%20Global%20Flight%20Dashboard',viewMode:view)"
122+
);
123+
setSavedTenant(null);
124+
window.location = originalLocation;
125+
});
126+
});
127+
88128
describe('Login page', () => {
89129
let chrome: ReturnType<typeof chromeServiceMock.createStartContract>;
90130
const mockHttpStart = {

0 commit comments

Comments
 (0)