3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.v2.api.user.controller;
22 import io.swagger.v3.oas.annotations.Operation;
23 import io.swagger.v3.oas.annotations.Parameter;
24 import io.swagger.v3.oas.annotations.enums.ParameterIn;
25 import javax.validation.Valid;
26 import org.sonar.server.v2.api.model.RestPage;
27 import org.sonar.server.v2.api.user.model.RestUser;
28 import org.sonar.server.v2.api.user.request.UsersSearchRestRequest;
29 import org.sonar.server.v2.api.user.response.UsersSearchRestResponse;
30 import org.springdoc.api.annotations.ParameterObject;
31 import org.springframework.http.HttpStatus;
32 import org.springframework.http.MediaType;
33 import org.springframework.web.bind.annotation.DeleteMapping;
34 import org.springframework.web.bind.annotation.GetMapping;
35 import org.springframework.web.bind.annotation.PathVariable;
36 import org.springframework.web.bind.annotation.RequestMapping;
37 import org.springframework.web.bind.annotation.RequestParam;
38 import org.springframework.web.bind.annotation.ResponseStatus;
39 import org.springframework.web.bind.annotation.RestController;
41 import static org.sonar.server.v2.WebApiEndpoints.USER_ENDPOINT;
43 @RequestMapping(USER_ENDPOINT)
45 public interface UserController {
47 @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
48 @ResponseStatus(HttpStatus.OK)
49 @Operation(summary = "Users search", description = """
50 Get a list of users. By default, only active users are returned.
51 The following fields are only returned when user has Administer System permission or for logged-in in user :
57 'sonarLintLastConnectionDate'
59 Field 'sonarqubeLastConnectionDate' is only updated every hour, so it may not be accurate, for instance when a user authenticates many times in less than one hour.
61 UsersSearchRestResponse search(@ParameterObject UsersSearchRestRequest usersSearchRestRequest, @Valid @ParameterObject RestPage restPage);
63 @DeleteMapping(path = "/{login}")
64 @ResponseStatus(HttpStatus.NO_CONTENT)
65 @Operation(summary = "Deactivate a user", description = "Deactivate a user. Requires Administer System permission.")
67 @PathVariable("login") @Parameter(description = "The login of the user to delete.", required = true, in = ParameterIn.PATH) String login,
68 @RequestParam(value = "anonymize", required = false, defaultValue = "false") @Parameter(description = "Anonymize user in addition to deactivating it.") Boolean anonymize);
70 @GetMapping(path = "/{login}")
71 @ResponseStatus(HttpStatus.OK)
72 @Operation(summary = "Fetch a single user", description = """
74 The following fields are only returned when user has Administer System permission or for logged-in in user :
80 'sonarLintLastConnectionDate'
82 Field 'sonarqubeLastConnectionDate' is only updated every hour, so it may not be accurate, for instance when a user authenticates many times in less than one hour.
84 RestUser fetchUser(@PathVariable("login") @Parameter(description = "The login of the user to fetch.", required = true, in = ParameterIn.PATH) String login);