]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6523 Replace Rails api/users/search with Java implementation
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 13 May 2015 07:55:03 +0000 (09:55 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 18 May 2015 08:26:03 +0000 (10:26 +0200)
server/sonar-server/src/main/java/org/sonar/server/user/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/UsersWs.java
server/sonar-server/src/main/resources/org/sonar/server/user/ws/example-search.json
server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/UsersWsTest.java
server/sonar-web/src/main/coffee/issue/views/assign-form-view.coffee
server/sonar-web/src/main/coffee/issues/facets/assignee-facet.coffee
server/sonar-web/src/main/coffee/issues/facets/reporter-facet.coffee
server/sonar-web/src/main/js/navigator/filters/ajax-select-filters.js
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/users_controller.rb [deleted file]
server/sonar-web/src/main/webapp/WEB-INF/app/helpers/application_helper.rb

index 4b4dee32d4dcabb24bacd6fe323e498fa112b05c..7f4cf2439ce16992bb4114863149cb6556dfc8e3 100644 (file)
@@ -52,10 +52,11 @@ public class SearchAction implements UsersWsAction {
 
   @Override
   public void define(WebService.NewController controller) {
-    WebService.NewAction action = controller.createAction("search2")
+    WebService.NewAction action = controller.createAction("search")
       .setDescription("Get a list of active users.")
       .setSince("3.6")
-      .setHandler(this);
+      .setHandler(this)
+      .setResponseExample(getClass().getResource("example-search.json"));
 
     action.addFieldsParam(FIELDS);
     action.addPagingParams(50);
index 476461d2c272a2cfc69489721adbbaa3ecefa864..d8bc63bc696c0912e5f92ec90e0b8065fbd3650a 100644 (file)
@@ -20,8 +20,6 @@
 
 package org.sonar.server.user.ws;
 
-import com.google.common.io.Resources;
-import org.sonar.api.server.ws.RailsHandler;
 import org.sonar.api.server.ws.WebService;
 
 public class UsersWs implements WebService {
@@ -38,34 +36,10 @@ public class UsersWs implements WebService {
       .setSince("3.6")
       .setDescription("Users management");
 
-    defineSearchAction(controller);
     for (UsersWsAction action : actions) {
       action.define(controller);
     }
 
     controller.done();
   }
-
-  private void defineSearchAction(NewController controller) {
-    NewAction action = controller.createAction("search")
-      .setDescription("Get a list of users")
-      .setSince("3.6")
-      .setHandler(RailsHandler.INSTANCE)
-      .setResponseExample(Resources.getResource(this.getClass(), "example-search.json"));
-
-    action.createParam("includeDeactivated")
-      .setDescription("Include deactivated users")
-      .setDefaultValue("false")
-      .setPossibleValues("true", "false");
-
-    action.createParam("logins")
-      .setDescription("Comma-separated list of user logins")
-      .setExampleValue("admin,sbrandhof");
-
-    action.createParam("s")
-      .setDescription("UTF-8 search query on login or name")
-      .setExampleValue("bran");
-
-    RailsHandler.addFormatParam(action);
-  }
 }
index 3cbb0005bcf00cd74a41d019fb0f4df735f04741..7b959b2c5947cd80762fa0e94150ea80a25364a0 100644 (file)
@@ -9,7 +9,8 @@
     {
       "login": "sbrandhof",
       "name": "Simon",
-      "active": true
+      "active": true,
+      "scmAccounts": ["simon.brandhof", "s.brandhof@company.tld"]
     }
   ]
 }
index 722f1eaaddf9653c6ffbc0eed1f3bf81580eba10..ab3c60cb8f22bd9815d241865494cf3e6dd656e8 100644 (file)
@@ -58,54 +58,54 @@ public class SearchActionTest {
 
   @Test
   public void search_empty() throws Exception {
-    tester.newGetRequest("api/users", "search2").execute().assertJson(getClass(), "empty.json");
+    tester.newGetRequest("api/users", "search").execute().assertJson(getClass(), "empty.json");
   }
 
   @Test
   public void search_without_parameters() throws Exception {
     injectUsers(5);
 
-    tester.newGetRequest("api/users", "search2").execute().assertJson(getClass(), "five_users.json");
+    tester.newGetRequest("api/users", "search").execute().assertJson(getClass(), "five_users.json");
   }
 
   @Test
   public void search_with_query() throws Exception {
     injectUsers(5);
 
-    tester.newGetRequest("api/users", "search2").setParam("q", "user-1").execute().assertJson(getClass(), "user_one.json");
+    tester.newGetRequest("api/users", "search").setParam("q", "user-1").execute().assertJson(getClass(), "user_one.json");
   }
 
   @Test
   public void search_with_paging() throws Exception {
     injectUsers(10);
 
-    tester.newGetRequest("api/users", "search2").setParam("ps", "5").execute().assertJson(getClass(), "page_one.json");
-    tester.newGetRequest("api/users", "search2").setParam("ps", "5").setParam("p", "2").execute().assertJson(getClass(), "page_two.json");
+    tester.newGetRequest("api/users", "search").setParam("ps", "5").execute().assertJson(getClass(), "page_one.json");
+    tester.newGetRequest("api/users", "search").setParam("ps", "5").setParam("p", "2").execute().assertJson(getClass(), "page_two.json");
   }
 
   @Test
   public void search_with_fields() throws Exception {
     injectUsers(1);
 
-    assertThat(tester.newGetRequest("api/users", "search2").execute().outputAsString())
+    assertThat(tester.newGetRequest("api/users", "search").execute().outputAsString())
       .contains("login")
       .contains("name")
       .contains("email")
       .contains("scmAccounts");
 
-    assertThat(tester.newGetRequest("api/users", "search2").setParam("f", "").execute().outputAsString())
+    assertThat(tester.newGetRequest("api/users", "search").setParam("f", "").execute().outputAsString())
       .contains("login")
       .contains("name")
       .contains("email")
       .contains("scmAccounts");
 
-    assertThat(tester.newGetRequest("api/users", "search2").setParam("f", "login").execute().outputAsString())
+    assertThat(tester.newGetRequest("api/users", "search").setParam("f", "login").execute().outputAsString())
       .contains("login")
       .doesNotContain("name")
       .doesNotContain("email")
       .doesNotContain("scmAccounts");
 
-    assertThat(tester.newGetRequest("api/users", "search2").setParam("f", "scmAccounts").execute().outputAsString())
+    assertThat(tester.newGetRequest("api/users", "search").setParam("f", "scmAccounts").execute().outputAsString())
       .doesNotContain("login")
       .doesNotContain("name")
       .doesNotContain("email")
index 62dd223058eee9be2b9f0ea10966f0c6eaf9247e..1ea55a414627019be38d72779d97334dcbf51355 100644 (file)
@@ -24,7 +24,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.i18n.I18n;
-import org.sonar.api.server.ws.RailsHandler;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.user.UserUpdater;
@@ -46,7 +45,8 @@ public class UsersWsTest {
       new UpdateAction(mock(UserIndex.class), mock(UserUpdater.class), userSessionRule),
       new CurrentUserAction(userSessionRule),
       new DeactivateAction(mock(UserIndex.class), mock(UserUpdater.class), userSessionRule),
-    new ChangePasswordAction(mock(UserUpdater.class), userSessionRule)));
+      new ChangePasswordAction(mock(UserUpdater.class), userSessionRule),
+      new SearchAction(mock(UserIndex.class))));
     controller = tester.controller("api/users");
   }
 
@@ -63,7 +63,6 @@ public class UsersWsTest {
     WebService.Action action = controller.action("search");
     assertThat(action).isNotNull();
     assertThat(action.isPost()).isFalse();
-    assertThat(action.handler()).isInstanceOf(RailsHandler.class);
     assertThat(action.responseExampleAsString()).isNotEmpty();
     assertThat(action.params()).hasSize(4);
   }
index f32d58792240f8f238ed52f3c234e09d65d54444..b92d7a475fd5fb2e41af3c8851bd2a9cd5dff017 100644 (file)
@@ -119,7 +119,7 @@ define [
 
     search: (query) ->
       if query.length > 1
-        $.get "#{baseUrl}/api/users/search2", q: query
+        $.get "#{baseUrl}/api/users/search", q: query
         .done (data) =>
           @resetAssignees data.users
       else
index b1b91c7e2073376e7faeb913f826794b0630ea37..366b13bb032e5b0c532076eff178b1af5016f32e 100644 (file)
@@ -33,7 +33,7 @@ define [
 
 
     getUrl: ->
-      "#{baseUrl}/api/users/search2"
+      "#{baseUrl}/api/users/search"
 
     prepareAjaxSearch: ->
       quietMillis: 300
index aa2c9dcd659403d0fcba5897964722f3712ec36a..2feacfc218496d6feebe6892418367f27bf3fe63 100644 (file)
@@ -28,7 +28,7 @@ define [
   class extends CustomValuesFacet
 
     getUrl: ->
-      "#{baseUrl}/api/users/search2"
+      "#{baseUrl}/api/users/search"
 
     prepareAjaxSearch: ->
       quietMillis: 300
index fecdcada306fcdc6169e334317a18bca7018820a..c354b73b48bd4c0940a5a4f0e379d5b22762ab09 100644 (file)
@@ -68,7 +68,7 @@ define([
   var UserSuggestions = Suggestions.extend({
 
     url: function() {
-      return baseUrl + '/api/users/search2';
+      return baseUrl + '/api/users/search';
     },
 
     parse: function(response) {
@@ -440,7 +440,7 @@ define([
       var that = this;
       return $j
           .ajax({
-            url: baseUrl + '/api/users/search2',
+            url: baseUrl + '/api/users/search',
             type: 'GET',
             data: { q: v }
           })
@@ -473,7 +473,7 @@ define([
       var that = this;
       return $j
           .ajax({
-            url: baseUrl + '/api/users/search2',
+            url: baseUrl + '/api/users/search',
             type: 'GET',
             data: { q: v }
           })
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/users_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/users_controller.rb
deleted file mode 100644 (file)
index 11353de..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-#
-
-# since 3.6
-class Api::UsersController < Api::ApiController
-
-  #
-  # GET /api/users/search?<parameters>
-  #
-  # -- Example
-  # curl -v 'http://localhost:9000/api/users/search?includeDeactivated=true&logins=simon,julien'
-  #
-  def search
-    users = Api.users.find(params)
-
-    select2_format=(params[:f]=='s2')
-    if select2_format
-      hash = {
-          :more => false,
-          :results => users.map { |user| {:id => user.login, :text => "#{user.name} (#{user.login})"} }
-      }
-    else
-      hash = {:users => users.map { |user| User.to_hash(user) }}
-    end
-
-    respond_to do |format|
-      format.json { render :json => jsonp(hash) }
-      format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'users') }
-    end
-  end
-
-  #
-  # POST /api/users/deactivate
-  #
-  # -- Mandatory parameters
-  # 'login' is the user identifier
-  #
-  # -- Example
-  # curl -X POST -v -u admin:admin 'http://localhost:9000/api/users/deactivate?login=<the user to deactivate>'
-  #
-  # since 3.7
-  #
-  def deactivate
-    verify_post_request
-    require_parameters :login
-
-    Api.users.deactivate(params[:login])
-
-    hash={}
-    respond_to do |format|
-      format.json { render :json => jsonp(hash) }
-      format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'users') }
-    end
-  end
-
-end
index 780779064ce7daadf3d37ab49ffec9b2c86dab08..7565b8051903b2a9bacbede77bad6b6c0a2d69fb 100644 (file)
@@ -725,7 +725,7 @@ module ApplicationHelper
   # * <tt>:select2_options</tt> - hash of select2 options
   #
   def user_select_tag(name, options={})
-    ws_url="#{ApplicationController::root_context}/api/users/search2"
+    ws_url="#{ApplicationController::root_context}/api/users/search"
     options[:min_length]=2
     options[:select2_ajax_options]={
       'data' => 'function (term, page) { return { q: term, p: page } }',