]> source.dussan.org Git - sonarqube.git/commitdiff
SC-700 Hide Configure Analysis button for non logged users (#1817)
authorSiegfried Ehret <siegfried.ehret@sonarsource.com>
Wed, 26 Jun 2019 12:54:37 +0000 (14:54 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 28 Jun 2019 06:45:53 +0000 (08:45 +0200)
server/sonar-web/src/main/js/apps/projects/components/ProjectCard.tsx
server/sonar-web/src/main/js/apps/projects/components/ProjectCardLeak.tsx
server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverall.tsx
server/sonar-web/src/main/js/apps/projects/components/ProjectsList.tsx
server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCard-test.tsx
server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardLeak-test.tsx
server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardOverall-test.tsx
server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardLeak-test.tsx.snap
server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverall-test.tsx.snap

index c72bc780b65a9d54936f22172f9ce5520ebc430a..41eff587d2f51ca39fb9ce77abf61a3843b03129 100644 (file)
@@ -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;
index beb338949ffce2e7345e0401a58b93bc74eb6b71..f943afbeefadaf3c3c6b66340ed84f26aa8d6851 100644 (file)
@@ -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>
index 214c6970ffb923a5b8afa0e687ec9619ab9995aa..25699239619683b5883218f4a776c7df3219d3ca 100644 (file)
@@ -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>
         )}
index 7225fdedf8500f3a35cebac5ef32224504ea7282..fed40f17638ccf32973ff34f9acc8b2523e6a386 100644 (file)
@@ -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}
index e5ef944be49dd2d88f23dee69b17b70dc9018fd3..6b40eb6729378fddbb8ec615dcf5abb19198c7a3 100644 (file)
@@ -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}
index 59df2a1b6e5ec7868d921227f9856228353c1b21..88d83f3fef55f850086287971972bb49bd205a7f 100644 (file)
@@ -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}
index 827d89e4aef8a0546391e25f748f0e2b6d8c8d5d..979844f75e4a4a6e809afff10e5617195aeabe3a 100644 (file)
@@ -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}
index 1ed5822d73ea577dc2380c5ed94c1fa7a99b826a..fb8431450f3d9b2ab12cc3a354a154b584f85c4a 100644 (file)
@@ -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"
index f7b58066d008b232d7463f3dfbd5b480f77bbff5..0c70453a77fdc407f5b83bf2705bd09084ecb7ad 100644 (file)
@@ -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"