]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11370 Update link to rules page
authorPascal Mugnier <pascal.mugnier@sonarsource.com>
Tue, 23 Oct 2018 08:11:00 +0000 (10:11 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 25 Oct 2018 18:21:02 +0000 (20:21 +0200)
server/sonar-web/src/main/js/apps/securityReports/components/App.tsx
server/sonar-web/src/main/js/apps/securityReports/components/VulnerabilityList.tsx
server/sonar-web/src/main/js/apps/securityReports/components/__tests__/__snapshots__/VulnerabilityList-test.tsx.snap
server/sonar-web/src/main/js/apps/securityReports/utils.ts

index 7f7bc9b1790b07a08337d717fec1d490bc9c1455..32a198800133ee7f7d4c8c8b5be0836abb395961 100755 (executable)
@@ -35,6 +35,7 @@ import { isLongLivingBranch } from '../../../helpers/branches';
 import DocTooltip from '../../../components/docs/DocTooltip';
 import { getRulesUrl } from '../../../helpers/urls';
 import { isSonarCloud } from '../../../helpers/system';
+import { StandardType } from '../utils';
 import '../style.css';
 
 interface Props {
@@ -48,7 +49,7 @@ interface State {
   loading: boolean;
   findings: Array<SecurityHotspot>;
   hasVulnerabilities: boolean;
-  type: 'owaspTop10' | 'sansTop25' | 'cwe';
+  type: StandardType;
   showCWE: boolean;
 }
 
index 3094cd5554a782fd52aa344abc179abe58365515..5cde1c6db304dcd715532a4e2797ae65495b55f1 100755 (executable)
@@ -32,7 +32,8 @@ import {
   renderOwaspTop10Category,
   renderSansTop25Category,
   renderCWECategory,
-  Standards
+  Standards,
+  StandardType
 } from '../utils';
 import DetachIcon from '../../../components/icons-components/DetachIcon';
 import Tooltip from '../../../components/controls/Tooltip';
@@ -46,13 +47,19 @@ interface Props {
   component: Component;
   findings: SecurityHotspot[];
   showCWE: boolean;
-  type: 'owaspTop10' | 'sansTop25' | 'cwe';
+  type: StandardType;
 }
 
 interface State {
   standards: Standards;
 }
 
+const STANDARDS_TAGS = {
+  owaspTop10: 'owasp',
+  sansTop25: 'sans-top25',
+  cwe: 'cwe'
+};
+
 export default class VulnerabilityList extends React.PureComponent<Props, State> {
   mounted = false;
   state: State = { standards: { owaspTop10: {}, sansTop25: {}, cwe: {} } };
@@ -79,12 +86,7 @@ export default class VulnerabilityList extends React.PureComponent<Props, State>
       );
   };
 
-  getName(
-    finding: SecurityHotspot,
-    type: 'owaspTop10' | 'sansTop25' | 'cwe',
-    activeRules: number,
-    totalRules: number
-  ) {
+  getName(finding: SecurityHotspot, type: StandardType, activeRules: number, totalRules: number) {
     const category = finding.category || finding.cwe || 'unknown';
     const renderers = {
       owaspTop10: renderOwaspTop10Category,
@@ -102,8 +104,11 @@ export default class VulnerabilityList extends React.PureComponent<Props, State>
             />
           )}
         {activeRules === 0 &&
-          totalRules > 0 && (
-            <HelpTooltip className="spacer-left" overlay={this.renderMoreRulesOverlay(totalRules)}>
+          totalRules > 0 &&
+          category !== 'unknown' && (
+            <HelpTooltip
+              className="spacer-left"
+              overlay={this.renderMoreRulesOverlay(totalRules, type, category)}>
               <PlusCircleIcon className="vertical-middle" fill={theme.blue} size={12} />
             </HelpTooltip>
           )}
@@ -111,10 +116,20 @@ export default class VulnerabilityList extends React.PureComponent<Props, State>
     );
   }
 
-  renderMoreRulesOverlay = (totalRules: number) => {
+  // We redirect the user to the rules page, using languages, types, keywords and tags filters
+  // to display the correct list of rules
+  renderMoreRulesOverlay = (totalRules: number, type: StandardType, category: string) => {
     const languages = this.props.component.qualityProfiles
       ? this.props.component.qualityProfiles.map(qp => qp.language).join(',')
       : '';
+    let tags;
+    let q;
+    if (type === 'cwe') {
+      q = `${STANDARDS_TAGS[type]}:${category.toLowerCase()}`;
+      tags = 'cwe';
+    } else {
+      tags = `${STANDARDS_TAGS[type]}-${category.toLowerCase()}`;
+    }
     return (
       <>
         <p>{translate('security_reports.activate_rules')}</p>
@@ -122,7 +137,7 @@ export default class VulnerabilityList extends React.PureComponent<Props, State>
         <Link
           className="spacer-left link-no-underline"
           to={getRulesUrl(
-            { languages, types: `${IssueType.Hotspot},${IssueType.Vulnerability}` },
+            { languages, tags, q, types: `${IssueType.Hotspot},${IssueType.Vulnerability}` },
             isSonarCloud() ? this.props.component.organization : undefined
           )}>
           {translateWithParameters('security_reports.activate_rules.link', totalRules)}
index 33b0ec369619e2d664de87aefaa54ffc838039d5..ddee9f669d3d45c92c8f6dbf3e8476f67b5d6691 100644 (file)
@@ -348,6 +348,8 @@ exports[`renders 1`] = `
                           "pathname": "/coding_rules",
                           "query": Object {
                             "languages": "",
+                            "q": undefined,
+                            "tags": "owasp-a3",
                             "types": "SECURITY_HOTSPOT,VULNERABILITY",
                           },
                         }
@@ -1135,6 +1137,8 @@ exports[`renders with cwe 1`] = `
                           "pathname": "/coding_rules",
                           "query": Object {
                             "languages": "",
+                            "q": undefined,
+                            "tags": "owasp-a3",
                             "types": "SECURITY_HOTSPOT,VULNERABILITY",
                           },
                         }
index d7e82afcfa251b0ff2604a06ee2eab448c8b4d83..138c5652b16bd834a270ea7e07eb9236cbad74b5 100755 (executable)
@@ -17,6 +17,9 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+
+export type StandardType = 'owaspTop10' | 'sansTop25' | 'cwe';
+
 export interface Standards {
   owaspTop10: { [x: string]: { title: string; description?: string } };
   sansTop25: { [x: string]: { title: string; description?: string } };