@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);
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 {
.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);
- }
}
{
"login": "sbrandhof",
"name": "Simon",
- "active": true
+ "active": true,
+ "scmAccounts": ["simon.brandhof", "s.brandhof@company.tld"]
}
]
}
@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")
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;
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");
}
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);
}
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
getUrl: ->
- "#{baseUrl}/api/users/search2"
+ "#{baseUrl}/api/users/search"
prepareAjaxSearch: ->
quietMillis: 300
class extends CustomValuesFacet
getUrl: ->
- "#{baseUrl}/api/users/search2"
+ "#{baseUrl}/api/users/search"
prepareAjaxSearch: ->
quietMillis: 300
var UserSuggestions = Suggestions.extend({
url: function() {
- return baseUrl + '/api/users/search2';
+ return baseUrl + '/api/users/search';
},
parse: function(response) {
var that = this;
return $j
.ajax({
- url: baseUrl + '/api/users/search2',
+ url: baseUrl + '/api/users/search',
type: 'GET',
data: { q: v }
})
var that = this;
return $j
.ajax({
- url: baseUrl + '/api/users/search2',
+ url: baseUrl + '/api/users/search',
type: 'GET',
data: { q: v }
})
+++ /dev/null
-#
-# 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
# * <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 } }',