Skip to content

Commit

Permalink
Hide create data source routes when data_source.manageableBy is none (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
opensearch-trigger-bot[bot] authored Jul 23, 2024
1 parent 5944bd7 commit 805d409
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7298.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Disable certain routes when data_source.manageableBy is none ([#7298](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7298))
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,37 @@ describe('mountManagementSection', () => {
expect(route.prop('path')).not.toEqual(['/:id']);
});
});

it('renders CreateDataSourcePanel when canManageDataSource is true', async () => {
const mockGetStartServices: StartServicesAccessor<DataSourceManagementStartDependencies> = jest
.fn()
.mockResolvedValue([
{
chrome: { docTitle: { reset: jest.fn() } },
application: { capabilities: { dataSource: { canManage: false } } },
savedObjects: {},
uiSettings: {},
notifications: {},
overlays: {},
http: {},
docLinks: {},
},
]);

await mountManagementSection(mockGetStartServices, mockParams, mockAuthMethodsRegistry, true);
const wrapper = shallow(
<OpenSearchDashboardsContextProvider services={{}}>
<I18nProvider>
<Router history={mockParams.history}>
<Switch>
<Route path={['/:id']} component={EditDataSourceWithRouter} />
<Route path={['/']} component={DataSourceHomePanel} />
</Switch>
</Router>
</I18nProvider>
</OpenSearchDashboardsContextProvider>
);

expect(wrapper.find(Route)).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,26 @@ export async function mountManagementSection(
authenticationMethodRegistry: authMethodsRegistry,
};

const canManageDataSource = !!application.capabilities?.dataSource?.canManage;

const content = (
<Router history={params.history}>
<Switch>
<Route path={['/create']}>
<CreateDataSourcePanel {...params} featureFlagStatus={featureFlagStatus} />
</Route>
{featureFlagStatus && (
{canManageDataSource && (
<Route path={['/create']}>
<CreateDataSourcePanel {...params} featureFlagStatus={featureFlagStatus} />
</Route>
)}
{featureFlagStatus && canManageDataSource && (
<Route path={['/configure/OpenSearch']}>
<CreateDataSourceWizardWithRouter />
</Route>
)}
<Route path={['/configure/:type']}>
<ConfigureDirectQueryDataSourceWithRouter notifications={notifications} />
</Route>
{canManageDataSource && (
<Route path={['/configure/:type']}>
<ConfigureDirectQueryDataSourceWithRouter notifications={notifications} />
</Route>
)}
{featureFlagStatus && (
<Route path={['/:id']}>
<EditDataSourceWithRouter />
Expand Down

0 comments on commit 805d409

Please sign in to comment.