aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main
diff options
context:
space:
mode:
authorSiegfried Ehret <siegfried.ehret@sonarsource.com>2019-06-26 14:54:37 +0200
committersonartech <sonartech@sonarsource.com>2019-06-28 08:45:53 +0200
commit89d6afa62e1cd11421e8d6826a198410b6457eaa (patch)
treea2d774d6e63168ac59b8538bc04e98ced0584905 /server/sonar-web/src/main
parent11b7f738e75f8e0f5da671d9503b2fa72f0188fb (diff)
downloadsonarqube-89d6afa62e1cd11421e8d6826a198410b6457eaa.tar.gz
sonarqube-89d6afa62e1cd11421e8d6826a198410b6457eaa.zip
SC-700 Hide Configure Analysis button for non logged users (#1817)
Diffstat (limited to 'server/sonar-web/src/main')
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/ProjectCard.tsx1
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/ProjectCardLeak.tsx6
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverall.tsx12
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/ProjectsList.tsx1
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCard-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardLeak-test.tsx11
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardOverall-test.tsx11
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardLeak-test.tsx.snap82
-rw-r--r--server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverall-test.tsx.snap83
9 files changed, 199 insertions, 10 deletions
diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectCard.tsx b/server/sonar-web/src/main/js/apps/projects/components/ProjectCard.tsx
index c72bc780b65..41eff587d2f 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/ProjectCard.tsx
+++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectCard.tsx
@@ -23,6 +23,7 @@ import ProjectCardOverall from './ProjectCardOverall';
import { Project } from '../types';
interface Props {
+ currentUser: T.CurrentUser;
handleFavorite: (component: string, isFavorite: boolean) => void;
height: number;
organization: T.Organization | undefined;
diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLeak.tsx b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLeak.tsx
index beb338949ff..f943afbeefa 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLeak.tsx
+++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLeak.tsx
@@ -31,8 +31,10 @@ import { translate, translateWithParameters } from '../../../helpers/l10n';
import { Project } from '../types';
import { formatDuration } from '../utils';
import { getProjectUrl } from '../../../helpers/urls';
+import { isLoggedIn } from '../../../helpers/users';
interface Props {
+ currentUser: T.CurrentUser;
handleFavorite: (component: string, isFavorite: boolean) => void;
height: number;
organization: T.Organization | undefined;
@@ -41,7 +43,7 @@ interface Props {
export default class ProjectCardLeak extends React.PureComponent<Props> {
render() {
- const { handleFavorite, height, organization, project } = this.props;
+ const { currentUser, handleFavorite, height, organization, project } = this.props;
const { measures } = project;
const hasTags = project.tags.length > 0;
const periodMs = project.leakPeriodDate ? difference(Date.now(), project.leakPeriodDate) : 0;
@@ -108,7 +110,7 @@ export default class ProjectCardLeak extends React.PureComponent<Props> {
? translate('projects.no_new_code_period')
: translate('projects.not_analyzed')}
</span>
- {!project.analysisDate && (
+ {!project.analysisDate && isLoggedIn(currentUser) && (
<Link className="button spacer-left" to={getProjectUrl(project.key)}>
{translate('projects.configure_analysis')}
</Link>
diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverall.tsx b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverall.tsx
index 214c6970ffb..25699239619 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverall.tsx
+++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverall.tsx
@@ -29,8 +29,10 @@ import PrivacyBadgeContainer from '../../../components/common/PrivacyBadgeContai
import { translate, translateWithParameters } from '../../../helpers/l10n';
import { Project } from '../types';
import { getProjectUrl } from '../../../helpers/urls';
+import { isLoggedIn } from '../../../helpers/users';
interface Props {
+ currentUser: T.CurrentUser;
handleFavorite: (component: string, isFavorite: boolean) => void;
height: number;
organization: T.Organization | undefined;
@@ -39,7 +41,7 @@ interface Props {
export default class ProjectCardOverall extends React.PureComponent<Props> {
render() {
- const { handleFavorite, height, organization, project } = this.props;
+ const { currentUser, handleFavorite, height, organization, project } = this.props;
const { measures } = project;
const hasTags = project.tags.length > 0;
@@ -96,9 +98,11 @@ export default class ProjectCardOverall extends React.PureComponent<Props> {
<div className="boxed-group-inner">
<div className="project-card-not-analyzed">
<span className="note">{translate('projects.not_analyzed')}</span>
- <Link className="button spacer-left" to={getProjectUrl(project.key)}>
- {translate('projects.configure_analysis')}
- </Link>
+ {isLoggedIn(currentUser) && (
+ <Link className="button spacer-left" to={getProjectUrl(project.key)}>
+ {translate('projects.configure_analysis')}
+ </Link>
+ )}
</div>
</div>
)}
diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectsList.tsx b/server/sonar-web/src/main/js/apps/projects/components/ProjectsList.tsx
index 7225fdedf85..fed40f17638 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/ProjectsList.tsx
+++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectsList.tsx
@@ -76,6 +76,7 @@ export default class ProjectsList extends React.PureComponent<Props> {
return (
<div key={key} style={{ ...style, height }}>
<ProjectCard
+ currentUser={this.props.currentUser}
handleFavorite={this.props.handleFavorite}
height={height}
key={project.key}
diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCard-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCard-test.tsx
index e5ef944be49..6b40eb67293 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCard-test.tsx
+++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCard-test.tsx
@@ -21,6 +21,7 @@ import * as React from 'react';
import { shallow } from 'enzyme';
import { Project } from '../../types';
import ProjectCard from '../ProjectCard';
+import { mockCurrentUser } from '../../../../helpers/testMocks';
const ORGANIZATION = { key: 'org', name: 'org' };
@@ -57,6 +58,7 @@ it('should show <ProjectCardLeak/> when asked', () => {
function shallowRender(type?: string) {
return shallow(
<ProjectCard
+ currentUser={mockCurrentUser()}
handleFavorite={jest.fn}
height={200}
organization={ORGANIZATION}
diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardLeak-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardLeak-test.tsx
index 59df2a1b6e5..88d83f3fef5 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardLeak-test.tsx
+++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardLeak-test.tsx
@@ -21,6 +21,7 @@ import * as React from 'react';
import { shallow } from 'enzyme';
import ProjectCardLeak from '../ProjectCardLeak';
import { Project } from '../../types';
+import { mockCurrentUser, mockLoggedInUser } from '../../../../helpers/testMocks';
jest.mock(
'date-fns/difference_in_milliseconds',
@@ -45,6 +46,9 @@ const PROJECT: Project = {
visibility: 'public'
};
+const USER_LOGGED_OUT = mockCurrentUser();
+const USER_LOGGED_IN = mockLoggedInUser();
+
it('should display analysis date and leak start date', () => {
const card = shallowRender(PROJECT);
expect(card.find('.project-card-dates').exists()).toBeTruthy();
@@ -84,9 +88,14 @@ it('should display not analyzed yet', () => {
expect(shallowRender({ ...PROJECT, analysisDate: undefined })).toMatchSnapshot();
});
-function shallowRender(project: Project) {
+it('should display configure analysis button for logged in user', () => {
+ expect(shallowRender({ ...PROJECT, analysisDate: undefined }, USER_LOGGED_IN)).toMatchSnapshot();
+});
+
+function shallowRender(project: Project, user: T.CurrentUser = USER_LOGGED_OUT) {
return shallow(
<ProjectCardLeak
+ currentUser={user}
handleFavorite={jest.fn()}
height={100}
organization={undefined}
diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardOverall-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardOverall-test.tsx
index 827d89e4aef..979844f75e4 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardOverall-test.tsx
+++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardOverall-test.tsx
@@ -21,6 +21,7 @@ import * as React from 'react';
import { shallow } from 'enzyme';
import ProjectCardOverall from '../ProjectCardOverall';
import { Project } from '../../types';
+import { mockCurrentUser, mockLoggedInUser } from '../../../../helpers/testMocks';
const MEASURES = {
alert_status: 'OK',
@@ -39,6 +40,9 @@ const PROJECT: Project = {
visibility: 'public'
};
+const USER_LOGGED_OUT = mockCurrentUser();
+const USER_LOGGED_IN = mockLoggedInUser();
+
it('should display analysis date (and not leak period) when defined', () => {
expect(
shallowRender(PROJECT)
@@ -87,9 +91,14 @@ it('should display not analyzed yet', () => {
expect(shallowRender({ ...PROJECT, analysisDate: undefined })).toMatchSnapshot();
});
-function shallowRender(project: Project) {
+it('should display configure analysis button for logged in user', () => {
+ expect(shallowRender({ ...PROJECT, analysisDate: undefined }, USER_LOGGED_IN)).toMatchSnapshot();
+});
+
+function shallowRender(project: Project, user: T.CurrentUser = USER_LOGGED_OUT) {
return shallow(
<ProjectCardOverall
+ currentUser={user}
handleFavorite={jest.fn()}
height={100}
organization={undefined}
diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardLeak-test.tsx.snap b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardLeak-test.tsx.snap
index 1ed5822d73e..fb8431450f3 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardLeak-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardLeak-test.tsx.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`should display not analyzed yet 1`] = `
+exports[`should display configure analysis button for logged in user 1`] = `
<div
className="boxed-group project-card"
data-key="foo"
@@ -96,6 +96,86 @@ exports[`should display not analyzed yet 1`] = `
</div>
`;
+exports[`should display not analyzed yet 1`] = `
+<div
+ className="boxed-group project-card"
+ data-key="foo"
+ style={
+ Object {
+ "height": 100,
+ }
+ }
+>
+ <div
+ className="boxed-group-header clearfix"
+ >
+ <div
+ className="project-card-header"
+ >
+ <h2
+ className="project-card-name"
+ >
+ <Connect(ProjectCardOrganization)
+ organization={
+ Object {
+ "key": "org",
+ "name": "org",
+ }
+ }
+ />
+ <Link
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to={
+ Object {
+ "pathname": "/dashboard",
+ "query": Object {
+ "id": "foo",
+ },
+ }
+ }
+ >
+ Foo
+ </Link>
+ </h2>
+ <div
+ className="project-card-header-right"
+ >
+ <Connect(PrivacyBadge)
+ className="spacer-left"
+ organization={
+ Object {
+ "key": "org",
+ "name": "org",
+ }
+ }
+ qualifier="TRK"
+ tooltipProps={
+ Object {
+ "projectKey": "foo",
+ }
+ }
+ visibility="public"
+ />
+ </div>
+ </div>
+ </div>
+ <div
+ className="boxed-group-inner"
+ >
+ <div
+ className="project-card-not-analyzed"
+ >
+ <span
+ className="note"
+ >
+ projects.not_analyzed
+ </span>
+ </div>
+ </div>
+</div>
+`;
+
exports[`should display the leak measures and quality gate 1`] = `
<div
className="boxed-group project-card"
diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverall-test.tsx.snap b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverall-test.tsx.snap
index f7b58066d00..0c70453a77f 100644
--- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverall-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverall-test.tsx.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`should display not analyzed yet 1`] = `
+exports[`should display configure analysis button for logged in user 1`] = `
<div
className="boxed-group project-card"
data-key="foo"
@@ -97,6 +97,87 @@ exports[`should display not analyzed yet 1`] = `
</div>
`;
+exports[`should display not analyzed yet 1`] = `
+<div
+ className="boxed-group project-card"
+ data-key="foo"
+ style={
+ Object {
+ "height": 100,
+ }
+ }
+>
+ <div
+ className="boxed-group-header clearfix"
+ >
+ <div
+ className="project-card-header"
+ >
+ <h2
+ className="project-card-name"
+ >
+ <Connect(ProjectCardOrganization)
+ organization={
+ Object {
+ "key": "org",
+ "name": "org",
+ }
+ }
+ />
+ <Link
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to={
+ Object {
+ "pathname": "/dashboard",
+ "query": Object {
+ "branch": undefined,
+ "id": "foo",
+ },
+ }
+ }
+ >
+ Foo
+ </Link>
+ </h2>
+ <div
+ className="project-card-header-right"
+ >
+ <Connect(PrivacyBadge)
+ className="spacer-left"
+ organization={
+ Object {
+ "key": "org",
+ "name": "org",
+ }
+ }
+ qualifier="TRK"
+ tooltipProps={
+ Object {
+ "projectKey": "foo",
+ }
+ }
+ visibility="public"
+ />
+ </div>
+ </div>
+ </div>
+ <div
+ className="boxed-group-inner"
+ >
+ <div
+ className="project-card-not-analyzed"
+ >
+ <span
+ className="note"
+ >
+ projects.not_analyzed
+ </span>
+ </div>
+ </div>
+</div>
+`;
+
exports[`should display the overall measures and quality gate 1`] = `
<div
className="boxed-group project-card"