]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3283 Do not allow to search reviews by author/assignee ID
authorFabrice Bellingard <bellingard@gmail.com>
Tue, 20 Mar 2012 11:23:57 +0000 (12:23 +0100)
committerFabrice Bellingard <bellingard@gmail.com>
Tue, 20 Mar 2012 11:23:57 +0000 (12:23 +0100)
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java
sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java

index 56d566ae9c1d494f20fe8e40ac58d696212973ee..2ca3c693b7e40622602b28c53d422a587440f224 100644 (file)
@@ -338,11 +338,7 @@ class Review < ActiveRecord::Base
       authors=options['authors'].split(',') if options['authors']
       if authors && authors.size>0 && !authors[0].blank?
         conditions << 'user_id in (:authors)'
-        unless Api::Utils.is_number?(authors[0])
-          values[:authors]=User.logins_to_ids(authors)
-        else
-          values[:authors]=authors.map { |user_id| user_id.to_i }
-        end
+        values[:authors]=User.logins_to_ids(authors)
       end
 
       assignees=options['assignees'].split(',') if options['assignees']
@@ -353,11 +349,7 @@ class Review < ActiveRecord::Base
         else
           # Assigned reviews
           conditions << 'assignee_id in (:assignees)'
-          unless Api::Utils.is_number?(assignees[0])
-            values[:assignees]=User.logins_to_ids(assignees)
-          else
-            values[:assignees]=assignees.map { |user_id| user_id.to_i }
-          end
+          values[:assignees]=User.logins_to_ids(assignees)
         end
       end
 
index 2dfbbab4e9be7232e096172f687238bf8830f6ab..81d3cc850b04f9544593bb2681e6dcec74f91d1f 100644 (file)
@@ -40,8 +40,8 @@ public class ReviewQuery extends Query<Review> {
   private String[] severities;
   private String[] projectKeysOrIds;
   private String[] resourceKeysOrIds;
-  private String[] authorLoginsOrIds;
-  private String[] assigneeLoginsOrIds;
+  private String[] authorLogins;
+  private String[] assigneeLogins;
   private String output;
   private String[] resolutions;
 
@@ -165,34 +165,68 @@ public class ReviewQuery extends Query<Review> {
   }
 
   /**
-   * @return the authorLoginsOrIds
+   * @deprecated since 2.15. Searching by user ID is not possible anymore. Use {@link #getAuthorLogins()} instead.
    */
+  @Deprecated
   public String[] getAuthorLoginsOrIds() {
-    return authorLoginsOrIds;
+    return authorLogins;
   }
 
   /**
-   * @param authorLoginsOrIds
-   *          the authorLoginsOrIds to set
+   * @deprecated since 2.15. Searching by user ID is not possible anymore. Use {@link #setAuthorLogins(String...)} instead.
    */
+  @Deprecated
   public ReviewQuery setAuthorLoginsOrIds(String... authorLoginsOrIds) {
-    this.authorLoginsOrIds = authorLoginsOrIds;
+    setAuthorLogins(authorLoginsOrIds);
+    return this;
+  }
+
+  /**
+   * @return the authorLogins
+   */
+  public String[] getAuthorLogins() {
+    return authorLogins;
+  }
+
+  /**
+   * @param authorLogins
+   *          the authorLogins to set
+   */
+  public ReviewQuery setAuthorLogins(String... authorLogins) {
+    this.authorLogins = authorLogins;
     return this;
   }
 
   /**
-   * @return the assigneeLoginsOrIds
+   * @deprecated since 2.15. Searching by user ID is not possible anymore. Use {@link #getAssigneeLogins()} instead.
    */
+  @Deprecated
   public String[] getAssigneeLoginsOrIds() {
-    return assigneeLoginsOrIds;
+    return assigneeLogins;
   }
 
   /**
-   * @param assigneeLoginsOrIds
-   *          the assigneeLoginsOrIds to set
+   * @deprecated since 2.15. Searching by user ID is not possible anymore. Use {@link #setAssigneeLogins(String...)} instead.
    */
+  @Deprecated
   public ReviewQuery setAssigneeLoginsOrIds(String... assigneeLoginsOrIds) {
-    this.assigneeLoginsOrIds = assigneeLoginsOrIds;
+    setAssigneeLogins(assigneeLoginsOrIds);
+    return this;
+  }
+
+  /**
+   * @return the assigneeLogins
+   */
+  public String[] getAssigneeLogins() {
+    return assigneeLogins;
+  }
+
+  /**
+   * @param assigneeLogins
+   *          the assigneeLogins to set
+   */
+  public ReviewQuery setAssigneeLogins(String... assigneeLogins) {
+    this.assigneeLogins = assigneeLogins;
     return this;
   }
 
@@ -241,8 +275,8 @@ public class ReviewQuery extends Query<Review> {
     appendUrlParameter(url, "severities", severities);
     appendUrlParameter(url, "projects", projectKeysOrIds);
     appendUrlParameter(url, "resources", resourceKeysOrIds);
-    appendUrlParameter(url, "authors", authorLoginsOrIds);
-    appendUrlParameter(url, "assignees", assigneeLoginsOrIds);
+    appendUrlParameter(url, "authors", authorLogins);
+    appendUrlParameter(url, "assignees", assigneeLogins);
     appendUrlParameter(url, "output", output);
     appendUrlParameter(url, "resolutions", resolutions);
     if (resolutions == null && reviewType != null) {
index da52d39baf4ea6bf34da718d200e6e99ce8b6d1a..5632b29c79a144b2ffa98fc32859c6b85a4ea307 100644 (file)
@@ -56,22 +56,40 @@ public class ReviewQueryTest extends QueryTestCase {
         .setSeverities("MINOR", "INFO")
         .setProjectKeysOrIds("com.sonar.foo:bar")
         .setResourceKeysOrIds("2", "3")
-        .setAuthorLoginsOrIds("20")
-        .setAssigneeLoginsOrIds("admin")
+        .setAuthorLogins("foo")
+        .setAssigneeLogins("admin")
         .setOutput("html");
     assertThat(
         query.getUrl(),
-        is("/api/reviews?statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&"));
+        is("/api/reviews?statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=foo&assignees=admin&output=html&"));
   }
 
   @Test
   public void resourceTreeViolationsForSonar2_8() {
     ReviewQuery query = new ReviewQuery();
     query.setIds(10L, 11L).setReviewType("FALSE_POSITIVE").setStatuses("OPEN").setSeverities("MINOR", "INFO")
-        .setProjectKeysOrIds("com.sonar.foo:bar").setResourceKeysOrIds("2", "3").setAuthorLoginsOrIds("20").setAssigneeLoginsOrIds("admin")
+        .setProjectKeysOrIds("com.sonar.foo:bar").setResourceKeysOrIds("2", "3").setAuthorLogins("foo").setAssigneeLogins("admin")
         .setOutput("html");
     assertThat(
         query.getUrl(),
-        is("/api/reviews?ids=10,11&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&review_type=FALSE_POSITIVE&"));
+        is("/api/reviews?ids=10,11&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=foo&assignees=admin&output=html&review_type=FALSE_POSITIVE&"));
+  }
+
+  // http://jira.codehaus.org/browse/SONAR-3283
+  @Test
+  public void testDeprecatedQueryByUserOrAssigneeId() throws Exception {
+    // the de deprecated setters
+    ReviewQuery query = new ReviewQuery()
+        .setAuthorLoginsOrIds("20")
+        .setAssigneeLoginsOrIds("40");
+    assertThat(query.getAuthorLogins(), is(new String[] {"20"}));
+    assertThat(query.getAssigneeLogins(), is(new String[] {"40"}));
+
+    // and test the deprecated getters
+    query = new ReviewQuery()
+        .setAuthorLogins("foo")
+        .setAssigneeLogins("bar");
+    assertThat(query.getAuthorLoginsOrIds(), is(new String[] {"foo"}));
+    assertThat(query.getAssigneeLoginsOrIds(), is(new String[] {"bar"}));
   }
 }