Skip to content

Commit

Permalink
Skip ui setting update for non workspace admin
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam committed Dec 4, 2024
1 parent 93f4f22 commit c1b9545
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
SavedObjectsClientContract,
IUiSettingsClient,
ApplicationStart,
WorkspacesSetup,
} from 'opensearch-dashboards/public';
import { UiStatsMetricType } from '@osd/analytics';
import { TelemetryPluginStart } from '../../../telemetry/public';
Expand Down Expand Up @@ -77,6 +78,7 @@ export interface HomeOpenSearchDashboardsServices {
};
dataSource?: DataSourcePluginStart;
sectionTypes: SectionTypeService;
workspaces?: WorkspacesSetup;
}

let services: HomeOpenSearchDashboardsServices | null = null;
Expand Down
20 changes: 15 additions & 5 deletions src/plugins/home/public/application/sample_data_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,26 @@ export async function listSampleDataSets(dataSourceId) {
return await getServices().http.get(sampleDataUrl, { query });
}

const isWorkspaceEnabled = () => {
const workspaces = getServices().application.capabilities.workspaces;
return !!(workspaces && workspaces.enabled);
const canUpdateUISetting = () => {
const {
application: { capabilities },
workspaces,
} = getServices();
if (

Check warning on line 49 in src/plugins/home/public/application/sample_data_client.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/sample_data_client.js#L48-L49

Added lines #L48 - L49 were not covered by tests
capabilities.workspaces &&
capabilities.workspaces.enabled &&
capabilities.workspaces.permissionEnabled
) {
return !!workspaces?.currentWorkspace$.getValue()?.owner;

Check warning on line 54 in src/plugins/home/public/application/sample_data_client.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/sample_data_client.js#L54

Added line #L54 was not covered by tests
}
return true;

Check warning on line 56 in src/plugins/home/public/application/sample_data_client.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/sample_data_client.js#L56

Added line #L56 was not covered by tests
};

export async function installSampleDataSet(id, sampleDataDefaultIndex, dataSourceId) {
const query = buildQuery(dataSourceId);
await getServices().http.post(`${sampleDataUrl}/${id}`, { query });

if (!isWorkspaceEnabled() && getServices().uiSettings.isDefault('defaultIndex')) {
if (canUpdateUISetting() && getServices().uiSettings.isDefault('defaultIndex')) {

Check warning on line 63 in src/plugins/home/public/application/sample_data_client.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/sample_data_client.js#L63

Added line #L63 was not covered by tests
getServices().uiSettings.set('defaultIndex', sampleDataDefaultIndex);
}

Expand All @@ -64,7 +74,7 @@ export async function uninstallSampleDataSet(id, sampleDataDefaultIndex, dataSou
const uiSettings = getServices().uiSettings;

if (
!isWorkspaceEnabled() &&
canUpdateUISetting() &&
!uiSettings.isDefault('defaultIndex') &&
uiSettings.get('defaultIndex') === sampleDataDefaultIndex
) {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/home/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export class HomePublicPlugin
injectedMetadata: coreStart.injectedMetadata,
dataSource,
sectionTypes: this.sectionTypeService,
workspaces: core.workspaces,
...homeOpenSearchDashboardsServices,
});
};
Expand Down

0 comments on commit c1b9545

Please sign in to comment.