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.UserCreateRestRequest;
29 import org.sonar.server.v2.api.user.request.UsersSearchRestRequest;
30 import org.sonar.server.v2.api.user.response.UsersSearchRestResponse;
31 import org.springdoc.api.annotations.ParameterObject;
32 import org.springframework.http.HttpStatus;
33 import org.springframework.http.MediaType;
34 import org.springframework.web.bind.annotation.DeleteMapping;
35 import org.springframework.web.bind.annotation.GetMapping;
36 import org.springframework.web.bind.annotation.PathVariable;
37 import org.springframework.web.bind.annotation.PostMapping;
38 import org.springframework.web.bind.annotation.RequestBody;
39 import org.springframework.web.bind.annotation.RequestMapping;
40 import org.springframework.web.bind.annotation.RequestParam;
41 import org.springframework.web.bind.annotation.ResponseStatus;
42 import org.springframework.web.bind.annotation.RestController;
44 import static org.sonar.server.v2.WebApiEndpoints.USER_ENDPOINT;
46 @RequestMapping(USER_ENDPOINT)
48 public interface UserController {
50 @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
51 @ResponseStatus(HttpStatus.OK)
52 @Operation(summary = "Users search", description = """
53 Get a list of users. By default, only active users are returned.
54 The following fields are only returned when user has Administer System permission or for logged-in in user :
60 'sonarLintLastConnectionDate'
62 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.
64 UsersSearchRestResponse search(@ParameterObject UsersSearchRestRequest usersSearchRestRequest, @Valid @ParameterObject RestPage restPage);
66 @DeleteMapping(path = "/{login}")
67 @ResponseStatus(HttpStatus.NO_CONTENT)
68 @Operation(summary = "Deactivate a user", description = "Deactivate a user. Requires Administer System permission.")
70 @PathVariable("login") @Parameter(description = "The login of the user to delete.", required = true, in = ParameterIn.PATH) String login,
71 @RequestParam(value = "anonymize", required = false, defaultValue = "false") @Parameter(description = "Anonymize user in addition to deactivating it.") Boolean anonymize);
73 @GetMapping(path = "/{login}")
74 @ResponseStatus(HttpStatus.OK)
75 @Operation(summary = "Fetch a single user", description = """
77 The following fields are only returned when user has Administer System permission or for logged-in in user :
83 'sonarLintLastConnectionDate'
85 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.
87 RestUser fetchUser(@PathVariable("login") @Parameter(description = "The login of the user to fetch.", required = true, in = ParameterIn.PATH) String login);
89 @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
90 @ResponseStatus(HttpStatus.OK)
91 @Operation(summary = "User creation", description = """
93 If a deactivated user account exists with the given login, it will be reactivated.
94 Requires Administer System permission
96 RestUser create(@Valid @RequestBody(required = true) UserCreateRestRequest userCreateRestRequest);