Skip to content

Commit ce8a46a

Browse files
authored
Implement Code feature control (#35115)
* update security api tests * rough POC to migrate Code to use Feature Controls * fix tests * [Code]: Integrate with Feature control * Rename callWithRequest to callCluster
1 parent e4a8c7a commit ce8a46a

File tree

30 files changed

+366
-388
lines changed

30 files changed

+366
-388
lines changed

x-pack/plugins/code/public/actions/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export * from './search';
1111
export * from './file';
1212
export * from './structure';
1313
export * from './editor';
14-
export * from './user';
1514
export * from './commit';
1615
export * from './status';
1716
export * from './project_config';

x-pack/plugins/code/public/actions/user.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

x-pack/plugins/code/public/components/admin_page/admin.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { EuiTab, EuiTabs } from '@elastic/eui';
7+
import { parse as parseQuery } from 'querystring';
88
import React from 'react';
99
import { connect } from 'react-redux';
10+
import { RouteComponentProps, withRouter } from 'react-router-dom';
1011
import styled from 'styled-components';
1112
import url from 'url';
1213

14+
import { EuiTab, EuiTabs } from '@elastic/eui';
1315
import theme from '@elastic/eui/dist/eui_theme_light.json';
14-
import { parse as parseQuery } from 'querystring';
15-
import { RouteComponentProps, withRouter } from 'react-router-dom';
16+
1617
import { Repository } from '../../../model';
1718
import { RootState } from '../../reducers';
1819
import { EmptyProject } from './empty_project';
@@ -39,7 +40,6 @@ enum AdminTabs {
3940
interface Props extends RouteComponentProps {
4041
repositories: Repository[];
4142
repositoryLoading: boolean;
42-
isAdmin: boolean;
4343
}
4444

4545
interface State {
@@ -120,7 +120,7 @@ class AdminPage extends React.PureComponent<Props, State> {
120120
const repositoriesCount = this.props.repositories.length;
121121
const showEmpty = repositoriesCount === 0 && !this.props.repositoryLoading;
122122
if (showEmpty) {
123-
return <EmptyProject isAdmin={this.props.isAdmin} />;
123+
return <EmptyProject />;
124124
}
125125
return <ProjectTab />;
126126
}
@@ -142,7 +142,6 @@ class AdminPage extends React.PureComponent<Props, State> {
142142
const mapStateToProps = (state: RootState) => ({
143143
repositories: state.repository.repositories,
144144
repositoryLoading: state.repository.loading,
145-
isAdmin: state.userProfile.isCodeAdmin,
146145
});
147146

148147
export const Admin = withRouter(connect(mapStateToProps)(AdminPage));

x-pack/plugins/code/public/components/admin_page/empty_project.tsx

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { EuiButton, EuiFlexGroup, EuiSpacer, EuiText } from '@elastic/eui';
87
import React from 'react';
98
import { Link } from 'react-router-dom';
9+
10+
import { EuiButton, EuiFlexGroup, EuiSpacer, EuiText } from '@elastic/eui';
11+
import { uiCapabilities } from 'ui/capabilities';
12+
1013
import { ImportProject } from './import_project';
1114

12-
export const EmptyProject = ({ isAdmin }: { isAdmin: boolean }) => (
13-
<div className="code-projects-tab">
14-
<EuiSpacer size="xl" />
15-
<div className="code-projects-tab__empty_header">
16-
<EuiText>
17-
<h1>You don't have any projects yet</h1>
18-
</EuiText>
19-
<EuiText color="subdued">{isAdmin && <p>Let's import your first one</p>}</EuiText>
15+
export const EmptyProject = () => {
16+
const isAdmin = uiCapabilities.code.admin as boolean;
17+
return (
18+
<div className="code-projects-tab">
19+
<EuiSpacer size="xl" />
20+
<div className="code-projects-tab__empty_header">
21+
<EuiText>
22+
<h1>You don't have any projects yet</h1>
23+
</EuiText>
24+
<EuiText color="subdued">{isAdmin && <p>Let's import your first one</p>}</EuiText>
25+
</div>
26+
{isAdmin && <ImportProject />}
27+
<EuiSpacer />
28+
<EuiFlexGroup justifyContent="center">
29+
<Link to="/setup-guide">
30+
<EuiButton>View the Setup Guide</EuiButton>
31+
</Link>
32+
</EuiFlexGroup>
2033
</div>
21-
{isAdmin && <ImportProject />}
22-
<EuiSpacer />
23-
<EuiFlexGroup justifyContent="center">
24-
<Link to="/setup-guide">
25-
<EuiButton>View the Setup Guide</EuiButton>
26-
</Link>
27-
</EuiFlexGroup>
28-
</div>
29-
);
34+
);
35+
};

x-pack/plugins/code/public/components/admin_page/project_tab.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import moment from 'moment';
2929
import React, { ChangeEvent } from 'react';
3030
import { connect } from 'react-redux';
3131
import styled from 'styled-components';
32+
import { uiCapabilities } from 'ui/capabilities';
33+
3234
import { Repository } from '../../../model';
3335
import { closeToast, importRepo } from '../../actions';
3436
import { RepoStatus, RootState } from '../../reducers';
@@ -77,7 +79,6 @@ const sortOptions = [
7779
interface Props {
7880
projects: Repository[];
7981
status: { [key: string]: RepoStatus };
80-
isAdmin: boolean;
8182
importRepo: (repoUrl: string) => void;
8283
importLoading: boolean;
8384
toastMessage?: string;
@@ -192,7 +193,7 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
192193
};
193194

194195
public render() {
195-
const { projects, isAdmin, status, toastMessage, showToast, toastType } = this.props;
196+
const { projects, status, toastMessage, showToast, toastType } = this.props;
196197
const projectsCount = projects.length;
197198
const modal = this.state.showImportProjectModal && this.renderImportModal();
198199

@@ -205,7 +206,7 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
205206
project={repo}
206207
showStatus={true}
207208
status={status[repo.uri]}
208-
enableManagement={isAdmin}
209+
enableManagement={uiCapabilities.code.admin as boolean}
209210
/>
210211
));
211212

@@ -243,7 +244,7 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
243244
<EuiFlexItem grow />
244245
<EuiFlexItem grow />
245246
<EuiFlexItem>
246-
{isAdmin && (
247+
{(uiCapabilities.code.admin as boolean) && (
247248
// @ts-ignore
248249
<NewProjectButton onClick={this.openModal} data-test-subj="newProjectButton">
249250
Add New Project
@@ -270,7 +271,6 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
270271
const mapStateToProps = (state: RootState) => ({
271272
projects: state.repository.repositories,
272273
status: state.status.status,
273-
isAdmin: state.userProfile.isCodeAdmin,
274274
importLoading: state.repository.importLoading,
275275
toastMessage: state.repository.toastMessage,
276276
toastType: state.repository.toastType,

x-pack/plugins/code/public/reducers/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { setup, SetupState } from './setup';
1818
import { shortcuts, ShortcutsState } from './shortcuts';
1919
import { RepoState, RepoStatus, status, StatusState } from './status';
2020
import { symbol, SymbolState } from './symbol';
21-
import { userProfile, UserProfileState } from './user';
2221

2322
export { RepoState, RepoStatus };
2423

@@ -30,7 +29,6 @@ export interface RootState {
3029
editor: EditorState;
3130
route: RouteState;
3231
status: StatusState;
33-
userProfile: UserProfileState;
3432
commit: CommitState;
3533
blame: BlameState;
3634
languageServer: LanguageServerState;
@@ -46,7 +44,6 @@ const reducers = {
4644
search,
4745
route,
4846
status,
49-
userProfile,
5047
commit,
5148
blame,
5249
languageServer,

x-pack/plugins/code/public/reducers/user.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

x-pack/plugins/code/public/sagas/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
import { watchRootRoute } from './setup';
4444
import { watchRepoCloneSuccess, watchRepoDeleteFinished } from './status';
4545
import { watchLoadStructure } from './structure';
46-
import { watchLoadUserProfile } from './user';
4746

4847
export function* rootSaga() {
4948
yield fork(watchRootRoute);
@@ -63,7 +62,6 @@ export function* rootSaga() {
6362
yield fork(watchInitRepoCmd);
6463
yield fork(watchGotoRepo);
6564
yield fork(watchLoadRepo);
66-
yield fork(watchLoadUserProfile);
6765
yield fork(watchSearchRouteChange);
6866
yield fork(watchAdminRouteChange);
6967
yield fork(watchMainRouteChange);

x-pack/plugins/code/public/sagas/repository.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
indexRepoFailed,
2626
indexRepoSuccess,
2727
initRepoCommand,
28-
loadUserProfile,
2928
updateCloneProgress,
3029
updateDeleteProgress,
3130
updateIndexProgress,
@@ -171,7 +170,6 @@ export function* watchGotoRepo() {
171170
}
172171

173172
function* handleAdminRouteChange() {
174-
yield put(loadUserProfile());
175173
yield put(fetchRepos());
176174
yield put(fetchRepoConfigs());
177175
yield put(loadLanguageServers());

x-pack/plugins/code/public/sagas/user.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)