Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide create data source routes when data_source.manageableBy is none #7298

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading