From 89d6afa62e1cd11421e8d6826a198410b6457eaa Mon Sep 17 00:00:00 2001 From: Siegfried Ehret Date: Wed, 26 Jun 2019 14:54:37 +0200 Subject: [PATCH] SC-700 Hide Configure Analysis button for non logged users (#1817) --- .../apps/projects/components/ProjectCard.tsx | 1 + .../projects/components/ProjectCardLeak.tsx | 6 +- .../components/ProjectCardOverall.tsx | 12 ++- .../apps/projects/components/ProjectsList.tsx | 1 + .../components/__tests__/ProjectCard-test.tsx | 2 + .../__tests__/ProjectCardLeak-test.tsx | 11 ++- .../__tests__/ProjectCardOverall-test.tsx | 11 ++- .../ProjectCardLeak-test.tsx.snap | 82 +++++++++++++++++- .../ProjectCardOverall-test.tsx.snap | 83 ++++++++++++++++++- 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 { 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 { ? translate('projects.no_new_code_period') : translate('projects.not_analyzed')} - {!project.analysisDate && ( + {!project.analysisDate && isLoggedIn(currentUser) && ( {translate('projects.configure_analysis')} 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 { 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 {
{translate('projects.not_analyzed')} - - {translate('projects.configure_analysis')} - + {isLoggedIn(currentUser) && ( + + {translate('projects.configure_analysis')} + + )}
)} 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 { return (
when asked', () => { function shallowRender(type?: string) { return shallow( { 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( { 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( `; +exports[`should display not analyzed yet 1`] = ` +
+
+
+

+ + + Foo + +

+
+ +
+
+
+
+
+ + projects.not_analyzed + +
+
+
+`; + exports[`should display the leak measures and quality gate 1`] = `
`; +exports[`should display not analyzed yet 1`] = ` +
+
+
+

+ + + Foo + +

+
+ +
+
+
+
+
+ + projects.not_analyzed + +
+
+
+`; + exports[`should display the overall measures and quality gate 1`] = `