* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
+import { Alert } from 'sonar-ui-common/components/ui/Alert';
import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner';
+import { translate } from 'sonar-ui-common/helpers/l10n';
import { getDuplications } from '../../../api/components';
import { getIssueFlowSnippets } from '../../../api/issues';
+import throwGlobalError from '../../../app/utils/throwGlobalError';
import DuplicationPopup from '../../../components/SourceViewer/components/DuplicationPopup';
import {
filterDuplicationBlocksByLine,
issuePopup?: { issue: string; name: string };
linePopup?: T.LinePopup & { component: string };
loading: boolean;
+ notAccessible: boolean;
}
export default class CrossComponentSourceViewerWrapper extends React.PureComponent<Props, State> {
state: State = {
components: {},
duplicationsByLine: {},
- loading: true
+ loading: true,
+ notAccessible: false
};
componentDidMount() {
}
}
},
- () => {
+ (response: Response) => {
+ if (response.status !== 403) {
+ throwGlobalError(response);
+ }
if (this.mounted) {
- this.setState({ loading: false });
+ this.setState({ loading: false, notAccessible: response.status === 403 });
}
}
);
};
render() {
- const { loading } = this.state;
+ const { loading, notAccessible } = this.state;
if (loading) {
return (
);
}
+ if (notAccessible) {
+ return (
+ <Alert className="spacer-top" variant="warning">
+ {translate('code_viewer.no_source_code_displayed_due_to_security')}
+ </Alert>
+ );
+ }
+
const { components, duplications, duplicationsByLine, linePopup } = this.state;
const issuesByComponent = issuesByComponentAndLine(this.props.issues);
const locationsByComponent = groupLocationsByComponent(this.props.locations, components);
expect(getIssueFlowSnippets).toBeCalledWith('foo');
});
+it('Should handle no access rights', async () => {
+ (getIssueFlowSnippets as jest.Mock).mockRejectedValueOnce({ status: 403 });
+
+ const wrapper = shallowRender();
+ await waitAndUpdate(wrapper);
+
+ expect(wrapper.state().notAccessible).toBe(true);
+ expect(wrapper).toMatchSnapshot();
+});
+
it('should handle issue popup', () => {
const wrapper = shallowRender();
// open