Skip to content

Commit

Permalink
remove version for user level settings
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Sep 3, 2024
1 parent 6776cdc commit b45550a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('UserUISettingsClientWrapper', () => {
it('should replace user id placeholder with real user id', async () => {
await wrapperClient.get('config', `${CURRENT_USER}_3.0.0`);

expect(mockedClient.get).toBeCalledWith('config', 'test_user_3.0.0', {});
expect(mockedClient.get).toBeCalledWith('config', 'test_user', {});
});
});

Expand All @@ -80,7 +80,7 @@ describe('UserUISettingsClientWrapper', () => {
it('should replace user id placeholder with real user id', async () => {
await wrapperClient.update('config', `${CURRENT_USER}_3.0.0`, {});

expect(mockedClient.update).toBeCalledWith('config', 'test_user_3.0.0', {}, {});
expect(mockedClient.update).toBeCalledWith('config', 'test_user', {}, {});
});
});

Expand Down Expand Up @@ -110,7 +110,7 @@ describe('UserUISettingsClientWrapper', () => {
'config',
{},
{
id: 'test_user_3.0.0',
id: 'test_user',
references: [
{
id: 'test_user',
Expand All @@ -130,7 +130,7 @@ describe('UserUISettingsClientWrapper', () => {
'config',
{},
{
id: 'test_user_3.0.0',
id: 'test_user',
references: [
{
id: 'test_user',
Expand Down Expand Up @@ -226,3 +226,60 @@ describe('UserUISettingsClientWrapper', () => {
});
});
});

describe('UserUISettingsClientWrapper - security not enabled', () => {
// security not enabled
beforeEach(() => {
jest.mock('../utils');
});

const requestHandlerContext = coreMock.createRequestHandlerContext();
const mockedClient = savedObjectsClientMock.create();
const requestMock = httpServerMock.createOpenSearchDashboardsRequest();

const buildWrapperInstance = (permissionEnabled: boolean) => {
const wrapperInstance = new UserUISettingsClientWrapper(loggerMock.create(), permissionEnabled);
const wrapperClient = wrapperInstance.wrapperFactory({
client: mockedClient,
typeRegistry: requestHandlerContext.savedObjects.typeRegistry,
request: requestMock,
});
return wrapperClient;
};

const wrapperClient = buildWrapperInstance(false);

describe('#get', () => {
beforeEach(() => {
jest.resetAllMocks();
});

it('should replace user id placeholder with version', async () => {
await wrapperClient.get('config', `${CURRENT_USER}_3.0.0`);

expect(mockedClient.get).toBeCalledWith('config', '3.0.0', {});
});
});

describe('#update', () => {
it('should replace user id placeholder with version', async () => {
await wrapperClient.update('config', `${CURRENT_USER}_3.0.0`, {});

expect(mockedClient.update).toBeCalledWith('config', '3.0.0', {}, {});
});
});

describe('#create', () => {
it('should replace user id placeholder with version', async () => {
await wrapperClient.create('config', {}, { id: `${CURRENT_USER}_3.0.0` });

expect(mockedClient.create).toBeCalledWith(
'config',
{},
{
id: '3.0.0',
}
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export class UserUISettingsClientWrapper {
const userName = extractUserName(request, core);
if (this.isUserLevelSetting(id)) {
if (userName) {
return id.replace(CURRENT_USER, userName);
// return id.replace(CURRENT_USER, userName); // uncomment this to support version for user personal setting
return userName;
} else {
// security is not enabled, using global setting id
return id.replace(`${CURRENT_USER}_`, '');
}
}
Expand Down Expand Up @@ -102,8 +104,11 @@ export class UserUISettingsClientWrapper {
.getPermissions()!,
};

// remove buildNum from attributes
const { buildNum, ...others } = attributes as any;

// create with reference, the reference field will used for filter settings by user
return await wrapperOptions.client.create(type, attributes, {
return await wrapperOptions.client.create(type, others, {
...options,
id: docId,
references: [
Expand Down

0 comments on commit b45550a

Please sign in to comment.