aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorPhilippe Perrin <philippe.perrin@sonarsource.com>2020-06-15 17:51:10 +0200
committersonartech <sonartech@sonarsource.com>2020-06-26 20:04:58 +0000
commit02c96005860a0e8dd76491e3ff612f876f7bb09f (patch)
tree3c8aa4e9a40e5096f7f38600eabb3cb6bd1097ef /server
parent98cadf2880787e8caaf73460d59a080a04a3f0b4 (diff)
downloadsonarqube-02c96005860a0e8dd76491e3ff612f876f7bb09f.tar.gz
sonarqube-02c96005860a0e8dd76491e3ff612f876f7bb09f.zip
SONAR-13398 System admin are provided with a link to the global background task page
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalContainer-test.tsx.snap2
-rw-r--r--server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx24
-rw-r--r--server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx25
-rw-r--r--server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx7
-rw-r--r--server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotificationRenderer-test.tsx1
-rw-r--r--server/sonar-web/src/main/js/app/components/indexation/__tests__/__snapshots__/IndexationNotificationRenderer-test.tsx.snap54
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/constants.ts5
7 files changed, 110 insertions, 8 deletions
diff --git a/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalContainer-test.tsx.snap b/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalContainer-test.tsx.snap
index adf8cc40e47..cf87ae0d4f2 100644
--- a/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalContainer-test.tsx.snap
+++ b/server/sonar-web/src/main/js/app/components/__tests__/__snapshots__/GlobalContainer-test.tsx.snap
@@ -31,7 +31,7 @@ exports[`should render correctly 1`] = `
}
/>
<Connect(GlobalMessages) />
- <withIndexationContext(IndexationNotification) />
+ <Connect(withCurrentUser(withIndexationContext(IndexationNotification))) />
<ChildComponent />
</Connect(withAppState(IndexationContextProvider))>
</Workspace>
diff --git a/server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx b/server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx
index 50c98188e1e..e53b6e65257 100644
--- a/server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx
+++ b/server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx
@@ -19,13 +19,19 @@
*/
import * as React from 'react';
+import { withCurrentUser } from '../../../components/hoc/withCurrentUser';
import withIndexationContext, {
WithIndexationContextProps
} from '../../../components/hoc/withIndexationContext';
+import { hasGlobalPermission, isLoggedIn } from '../../../helpers/users';
import './IndexationNotification.css';
import IndexationNotificationHelper from './IndexationNotificationHelper';
import IndexationNotificationRenderer from './IndexationNotificationRenderer';
+interface Props extends WithIndexationContextProps {
+ currentUser: T.CurrentUser;
+}
+
interface State {
progression?: IndexationProgression;
}
@@ -35,10 +41,17 @@ export enum IndexationProgression {
Completed
}
-export class IndexationNotification extends React.PureComponent<WithIndexationContextProps, State> {
- state: State = {
- progression: undefined
- };
+export class IndexationNotification extends React.PureComponent<Props, State> {
+ state: State;
+ isSystemAdmin = false;
+
+ constructor(props: Props) {
+ super(props);
+
+ this.state = { progression: undefined };
+ this.isSystemAdmin =
+ isLoggedIn(this.props.currentUser) && hasGlobalPermission(this.props.currentUser, 'admin');
+ }
componentDidMount() {
this.refreshNotification();
@@ -79,9 +92,10 @@ export class IndexationNotification extends React.PureComponent<WithIndexationCo
progression={progression}
percentCompleted={percentCompleted ?? 0}
onDismissCompletedNotification={this.handleDismissCompletedNotification}
+ displayBackgroundTaskLink={this.isSystemAdmin}
/>
);
}
}
-export default withIndexationContext(IndexationNotification);
+export default withCurrentUser(withIndexationContext(IndexationNotification));
diff --git a/server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx b/server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx
index 9cb464cd6de..794786e793e 100644
--- a/server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx
+++ b/server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx
@@ -19,19 +19,23 @@
*/
import * as React from 'react';
+import { FormattedMessage } from 'react-intl';
+import { Link } from 'react-router';
import { ButtonLink } from 'sonar-ui-common/components/controls/buttons';
import { Alert } from 'sonar-ui-common/components/ui/Alert';
import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n';
+import { BackgroundTaskTypes } from '../../../apps/background-tasks/constants';
import { IndexationProgression } from './IndexationNotification';
export interface IndexationNotificationRendererProps {
progression: IndexationProgression;
percentCompleted: number;
onDismissCompletedNotification: VoidFunction;
+ displayBackgroundTaskLink?: boolean;
}
export default function IndexationNotificationRenderer(props: IndexationNotificationRendererProps) {
- const { progression, percentCompleted } = props;
+ const { progression, percentCompleted, displayBackgroundTaskLink } = props;
const inProgress = progression === IndexationProgression.InProgress;
@@ -49,6 +53,25 @@ export default function IndexationNotificationRenderer(props: IndexationNotifica
<span className="spacer-left">
{translateWithParameters('indexation.in_progress.details', percentCompleted)}
</span>
+ {displayBackgroundTaskLink && (
+ <span className="spacer-left">
+ <FormattedMessage
+ id="indexation.in_progress.admin_details"
+ defaultMessage={translate('indexation.in_progress.admin_details')}
+ values={{
+ link: (
+ <Link
+ to={{
+ pathname: '/admin/background_tasks',
+ query: { taskType: BackgroundTaskTypes.IssueSync }
+ }}>
+ {translate('background_tasks.page')}
+ </Link>
+ )
+ }}
+ />
+ </span>
+ )}
</>
) : (
<>
diff --git a/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx b/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx
index 207db1ee713..f09fc87d60a 100644
--- a/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx
+++ b/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx
@@ -20,6 +20,7 @@
import { shallow } from 'enzyme';
import * as React from 'react';
+import { mockCurrentUser } from '../../../../helpers/testMocks';
import { IndexationNotification, IndexationProgression } from '../IndexationNotification';
import IndexationNotificationHelper from '../IndexationNotificationHelper';
import IndexationNotificationRenderer from '../IndexationNotificationRenderer';
@@ -82,6 +83,10 @@ it('should hide the success banner on dismiss action', () => {
function shallowRender(props?: Partial<IndexationNotification['props']>) {
return shallow<IndexationNotification>(
- <IndexationNotification indexationContext={{ status: { isCompleted: false } }} {...props} />
+ <IndexationNotification
+ currentUser={mockCurrentUser()}
+ indexationContext={{ status: { isCompleted: false } }}
+ {...props}
+ />
);
}
diff --git a/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotificationRenderer-test.tsx b/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotificationRenderer-test.tsx
index 3bafb5ebba8..ace5c8ee506 100644
--- a/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotificationRenderer-test.tsx
+++ b/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotificationRenderer-test.tsx
@@ -29,6 +29,7 @@ import IndexationNotificationRenderer, {
it('should render correctly', () => {
expect(shallowRender()).toMatchSnapshot('in-progress');
+ expect(shallowRender({ displayBackgroundTaskLink: true })).toMatchSnapshot('in-progress-admin');
expect(shallowRender({ progression: IndexationProgression.Completed })).toMatchSnapshot(
'completed'
);
diff --git a/server/sonar-web/src/main/js/app/components/indexation/__tests__/__snapshots__/IndexationNotificationRenderer-test.tsx.snap b/server/sonar-web/src/main/js/app/components/indexation/__tests__/__snapshots__/IndexationNotificationRenderer-test.tsx.snap
index c0cb064d7df..2674a8f4a12 100644
--- a/server/sonar-web/src/main/js/app/components/indexation/__tests__/__snapshots__/IndexationNotificationRenderer-test.tsx.snap
+++ b/server/sonar-web/src/main/js/app/components/indexation/__tests__/__snapshots__/IndexationNotificationRenderer-test.tsx.snap
@@ -55,3 +55,57 @@ exports[`should render correctly: in-progress 1`] = `
</Alert>
</div>
`;
+
+exports[`should render correctly: in-progress-admin 1`] = `
+<div
+ className="indexation-notification-wrapper"
+>
+ <Alert
+ className="indexation-notification-banner"
+ display="banner"
+ variant="warning"
+ >
+ <div
+ className="display-flex-center"
+ >
+ <span>
+ indexation.in_progress
+ </span>
+ <i
+ className="spinner spacer-left"
+ />
+ <span
+ className="spacer-left"
+ >
+ indexation.in_progress.details.25
+ </span>
+ <span
+ className="spacer-left"
+ >
+ <FormattedMessage
+ defaultMessage="indexation.in_progress.admin_details"
+ id="indexation.in_progress.admin_details"
+ values={
+ Object {
+ "link": <Link
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to={
+ Object {
+ "pathname": "/admin/background_tasks",
+ "query": Object {
+ "taskType": "ISSUE_SYNC",
+ },
+ }
+ }
+ >
+ background_tasks.page
+ </Link>,
+ }
+ }
+ />
+ </span>
+ </div>
+ </Alert>
+</div>
+`;
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/constants.ts b/server/sonar-web/src/main/js/apps/background-tasks/constants.ts
index 34d1d7f642e..ec685551027 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/constants.ts
+++ b/server/sonar-web/src/main/js/apps/background-tasks/constants.ts
@@ -29,6 +29,11 @@ export const STATUSES = {
CANCELED: 'CANCELED'
};
+export enum BackgroundTaskTypes {
+ Report = 'REPORT',
+ IssueSync = 'ISSUE_SYNC'
+}
+
export const ALL_TYPES = 'ALL_TYPES';
export const CURRENTS = {