]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8908 Check permissions when displaying an issue permalink
authorStas Vilchik <vilchiks@gmail.com>
Mon, 8 May 2017 15:52:40 +0000 (17:52 +0200)
committerStas Vilchik <stas-vilchik@users.noreply.github.com>
Tue, 9 May 2017 08:02:57 +0000 (10:02 +0200)
server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangesEmailTemplate.java
server/sonar-server/src/test/resources/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/display_component_key_if_no_component_name.txt
server/sonar-server/src/test/resources/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_should_display_resolution_change.txt
server/sonar-server/src/test/resources/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt
server/sonar-server/src/test/resources/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt
server/sonar-server/src/test/resources/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt
server/sonar-web/src/main/js/components/issue/components/IssueTitleBar.js
server/sonar-web/src/main/js/components/issue/components/__tests__/IssueTitleBar-test.js
server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueTitleBar-test.js.snap
server/sonar-web/src/main/js/helpers/urls.js

index 348886958b741ee9690434a620c3a81e37d7c33f..6835d58a35f90d41260057e24dfd0afbfa8a4a92 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.issue.notification;
 
 import com.google.common.base.Strings;
+import java.io.UnsupportedEncodingException;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.apache.commons.lang.StringUtils;
@@ -31,6 +32,8 @@ import org.sonar.db.user.UserDto;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 import org.sonar.plugins.emailnotifications.api.EmailTemplate;
 
+import static java.net.URLEncoder.encode;
+
 /**
  * Creates email message for notification "issue-changes".
  */
@@ -100,9 +103,17 @@ public class IssueChangesEmailTemplate extends EmailTemplate {
     appendField(sb, "Message", null, notif.getFieldValue("message"));
   }
 
-  private void appendFooter(StringBuilder sb, Notification notification) {
+  private void appendFooter(StringBuilder sb, Notification notification){
     String issueKey = notification.getFieldValue("key");
-    sb.append("See it in SonarQube: ").append(settings.getServerBaseURL()).append("/issues?issues=").append(issueKey).append(NEW_LINE);
+    try {
+      sb.append("See it in SonarQube: ").append(settings.getServerBaseURL())
+        .append("/project/issues?id=").append(encode(notification.getFieldValue("projectKey"), "UTF-8"))
+        .append("&issues=").append(issueKey)
+        .append("&open=").append(issueKey)
+        .append(NEW_LINE);
+    } catch (UnsupportedEncodingException e) {
+      throw new IllegalStateException("Encoding not supported", e);
+    }
   }
 
   private static void appendLine(StringBuilder sb, @Nullable String line) {
index 55fac8811442ded78851a284c8b0cda88d7fe856..a098041a84834ab6f1c3ad1cbc63c9bae901ace4 100644 (file)
@@ -4,4 +4,4 @@ Message: Has 3 cycles
 
 Resolution: FIXED (was FALSE-POSITIVE)
 
-See it in SonarQube: http://nemo.sonarsource.org/issues?issues=ABCDE
+See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&issues=ABCDE&open=ABCDE
index 8d41e1cd9f14d43c97ddced6b96a48bd48abcbc4..5bc4f6237daa8dec7cc12d5b354c68c05593273f 100644 (file)
@@ -4,4 +4,4 @@ Message: Has 3 cycles
 
 Action Plan changed to ABC 1.0
 
-See it in SonarQube: http://nemo.sonarsource.org/issues?issues=ABCDE
+See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&issues=ABCDE&open=ABCDE
index 482adb0a0175eb4ba2e1e17b9b956d48f35e8c3a..15768633c9d9efe37654f2f7aa2369025de08a69 100644 (file)
@@ -4,4 +4,4 @@ Message: Has 3 cycles
 
 Assignee changed to louis
 
-See it in SonarQube: http://nemo.sonarsource.org/issues?issues=ABCDE
+See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&issues=ABCDE&open=ABCDE
index b4497b7fbe80cfefdb62af96e85c424ccd60439e..5def650c04170c9b94e779cc0fd1c17cd178ed7b 100644 (file)
@@ -9,4 +9,4 @@ Resolution: FALSE-POSITIVE
 Status: RESOLVED
 Tags: [bug performance]
 
-See it in SonarQube: http://nemo.sonarsource.org/issues?issues=ABCDE
+See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&issues=ABCDE&open=ABCDE
index c6ca72d5747cde6b13db5b78eed894bafd24e4dc..8621fce9439b74f9b2d6d5d8d1bb0c0d829be70e 100644 (file)
@@ -25,7 +25,7 @@ import IssueMessage from './IssueMessage';
 import SimilarIssuesFilter from './SimilarIssuesFilter';
 import LocationIndex from '../../common/LocationIndex';
 import Tooltip from '../../controls/Tooltip';
-import { getSingleIssueUrl } from '../../../helpers/urls';
+import { getComponentIssuesUrl } from '../../../helpers/urls';
 import { formatMeasure } from '../../../helpers/measures';
 import { translate, translateWithParameters } from '../../../helpers/l10n';
 import type { Issue } from '../types';
@@ -62,6 +62,8 @@ export default function IssueTitleBar(props: Props) {
   // dirty trick :(
   const onIssuesPage = document.getElementById('issues-page') != null;
 
+  const issueUrl = getComponentIssuesUrl(issue.project, { issues: issue.key, open: issue.key });
+
   return (
     <table className="issue-table">
       <tbody>
@@ -94,10 +96,7 @@ export default function IssueTitleBar(props: Props) {
                 <li className="issue-meta">
                   {onIssuesPage
                     ? locationsBadge
-                    : <Link
-                        onClick={stopPropagation}
-                        target="_blank"
-                        to={getSingleIssueUrl(issue.key)}>
+                    : <Link onClick={stopPropagation} target="_blank" to={issueUrl}>
                         {locationsBadge}
                       </Link>}
                 </li>}
@@ -106,7 +105,7 @@ export default function IssueTitleBar(props: Props) {
                   className="js-issue-permalink icon-link"
                   onClick={stopPropagation}
                   target="_blank"
-                  to={getSingleIssueUrl(issue.key)}
+                  to={issueUrl}
                 />
               </li>
               {hasSimilarIssuesFilter &&
index 8545979087b3c119623878034fd6a3e71c0ee57e..f09d709908fb658007415ecfafe877475de1f430 100644 (file)
@@ -25,6 +25,7 @@ const issue = {
   line: 26,
   creationDate: '2017-03-01T09:36:01+0100',
   organization: 'myorg',
+  project: 'myproject',
   key: 'AVsae-CQS-9G3txfbFN2',
   rule: 'javascript:S1067',
   message: 'Reduce the number of conditional operators (4) used in the expression',
index 2e3be9e376e48d4e313411566af35525f0f25557..2a7d3bdbcea7041dcddc569f0e6ecd5532a834b9 100644 (file)
@@ -33,6 +33,7 @@ exports[`should render the titlebar correctly 1`] = `
                   "line": 26,
                   "message": "Reduce the number of conditional operators (4) used in the expression",
                   "organization": "myorg",
+                  "project": "myproject",
                   "rule": "javascript:S1067",
                   "secondaryLocations": Array [],
                 }
@@ -63,8 +64,9 @@ exports[`should render the titlebar correctly 1`] = `
               target="_blank"
               to={
                 Object {
-                  "pathname": "/issues",
+                  "pathname": "/project/issues",
                   "query": Object {
+                    "id": "myproject",
                     "issues": "AVsae-CQS-9G3txfbFN2",
                     "open": "AVsae-CQS-9G3txfbFN2",
                   },
@@ -112,6 +114,7 @@ exports[`should render the titlebar with the filter 1`] = `
                   "line": 26,
                   "message": "Reduce the number of conditional operators (4) used in the expression",
                   "organization": "myorg",
+                  "project": "myproject",
                   "rule": "javascript:S1067",
                   "secondaryLocations": Array [],
                 }
@@ -142,8 +145,9 @@ exports[`should render the titlebar with the filter 1`] = `
               target="_blank"
               to={
                 Object {
-                  "pathname": "/issues",
+                  "pathname": "/project/issues",
                   "query": Object {
+                    "id": "myproject",
                     "issues": "AVsae-CQS-9G3txfbFN2",
                     "open": "AVsae-CQS-9G3txfbFN2",
                   },
@@ -164,6 +168,7 @@ exports[`should render the titlebar with the filter 1`] = `
                   "line": 26,
                   "message": "Reduce the number of conditional operators (4) used in the expression",
                   "organization": "myorg",
+                  "project": "myproject",
                   "rule": "javascript:S1067",
                   "secondaryLocations": Array [],
                 }
index ffa866797e79506edb83c9cc7defbf1e50dedc0a..7f512e298c8815424763648bd8db52733da2f455 100644 (file)
@@ -55,13 +55,6 @@ export function getComponentIssuesUrlAsString(componentKey, query) {
   return `${window.baseUrl}${path.pathname}?${stringify(path.query)}`;
 }
 
-/**
- * Generate URL for a single issue
- */
-export function getSingleIssueUrl(issues) {
-  return { pathname: '/issues', query: { issues, open: issues } };
-}
-
 /**
  * Generate URL for a component's drilldown page
  * @param {string} componentKey