Browse Source

SONAR-20181 FE - Rename pageRestResponse to page

tags/10.2.0.77647
guillaume-peoch-sonarsource 9 months ago
parent
commit
56d2c712d5

+ 1
- 1
server/sonar-web/src/main/js/api/mocks/IssuesServiceMock.ts View File



handleGetUsers = () => { handleGetUsers = () => {
return this.reply({ return this.reply({
pageRestResponse: mockPaging(),
page: mockPaging(),
users: [mockLoggedInUser() as unknown as RestUser], users: [mockLoggedInUser() as unknown as RestUser],
}); });
}; };

+ 1
- 1
server/sonar-web/src/main/js/api/mocks/SecurityHotspotServiceMock.ts View File

mockRestUser({ name: 'User Doe', login: 'user.doe' }), mockRestUser({ name: 'User Doe', login: 'user.doe' }),
mockRestUser({ name: 'User Foo', login: 'user.foo' }), mockRestUser({ name: 'User Foo', login: 'user.foo' }),
], ],
pageRestResponse: mockPaging(),
page: mockPaging(),
}); });
}; };



+ 5
- 5
server/sonar-web/src/main/js/api/mocks/UsersServiceMock.ts View File

}; };


handleGetUsers: typeof getUsers<RestUserDetailed> = (data) => { handleGetUsers: typeof getUsers<RestUserDetailed> = (data) => {
let pageRestResponse = {
let page = {
pageIndex: 1, pageIndex: 1,
pageSize: 0, pageSize: 0,
total: 10, total: 10,
}; };


if (data.pageIndex !== undefined && data.pageIndex !== pageRestResponse.pageIndex) {
pageRestResponse = { pageIndex: 2, pageSize: 2, total: 10 };
if (data.pageIndex !== undefined && data.pageIndex !== page.pageIndex) {
page = { pageIndex: 2, pageSize: 2, total: 10 };
const users = [ const users = [
mockRestUser({ mockRestUser({
name: `Local User ${this.users.length + 4}`, name: `Local User ${this.users.length + 4}`,
}), }),
]; ];


return this.reply({ pageRestResponse, users });
return this.reply({ page, users });
} }


const users = this.getFilteredRestUsers({ const users = this.getFilteredRestUsers({
}); });


return this.reply({ return this.reply({
pageRestResponse: {
page: {
pageIndex: 1, pageIndex: 1,
pageSize: users.length, pageSize: users.length,
total: 10, total: 10,

+ 1
- 1
server/sonar-web/src/main/js/api/users.ts View File

sonarLintLastConnectionDateTo?: string; sonarLintLastConnectionDateTo?: string;
pageSize?: number; pageSize?: number;
pageIndex?: number; pageIndex?: number;
}): Promise<{ pageRestResponse: Paging; users: T[] }> {
}): Promise<{ page: Paging; users: T[] }> {
return getJSON('/api/v2/users', data).catch(throwGlobalError); return getJSON('/api/v2/users', data).catch(throwGlobalError);
} }



+ 2
- 2
server/sonar-web/src/main/js/apps/issues/utils.ts View File

query: string, query: string,
page = 1 page = 1
): Promise<{ paging: Paging; results: RestUser[] }> => { ): Promise<{ paging: Paging; results: RestUser[] }> => {
return getUsers<RestUser>({ pageIndex: page, q: query }).then(({ pageRestResponse, users }) => ({
paging: pageRestResponse,
return getUsers<RestUser>({ pageIndex: page, q: query }).then(({ page, users }) => ({
paging: page,
results: users, results: users,
})); }));
}; };

+ 1
- 1
server/sonar-web/src/main/js/queries/users.ts View File

return results.reduce( return results.reduce(
(acc, { data, isLoading }) => ({ (acc, { data, isLoading }) => ({
users: acc.users.concat(data?.users ?? []), users: acc.users.concat(data?.users ?? []),
total: data?.pageRestResponse.total,
total: data?.page.total,
isLoading: acc.isLoading || isLoading, isLoading: acc.isLoading || isLoading,
}), }),
{ users: [] as U[], total: 0, isLoading: false } { users: [] as U[], total: 0, isLoading: false }

+ 8
- 8
server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/controller/UserController.java View File

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@Operation(summary = "Users search", description = """ @Operation(summary = "Users search", description = """
Get a list of users. By default, only active users are returned.<br>
Get a list of users. By default, only active users are returned.
The following fields are only returned when user has Administer System permission or for logged-in in user : The following fields are only returned when user has Administer System permission or for logged-in in user :
'email'
'externalIdentity'
'externalProvider'
'groups'
'lastConnectionDate'
'sonarLintLastConnectionDate'
'tokensCount'<br>
'email',
'externalIdentity',
'externalProvider',
'groups',
'lastConnectionDate',
'sonarLintLastConnectionDate',
'tokensCount'.
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. 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.
""") """)
UsersSearchRestResponse search( UsersSearchRestResponse search(

+ 3
- 0
server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/user/model/RestUser.java View File

*/ */
package org.sonar.server.v2.api.user.model; package org.sonar.server.v2.api.user.model;


import io.swagger.v3.oas.annotations.media.Schema;

@Schema(implementation = RestUserForAdmins.class)
public interface RestUser { public interface RestUser {
} }

+ 25
- 8
server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/user/controller/DefaultUserControllerTest.java View File

package org.sonar.server.v2.api.user.controller; package org.sonar.server.v2.api.user.controller;


import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
private final UsersSearchRestResponseGenerator responseGenerator = mock(UsersSearchRestResponseGenerator.class); private final UsersSearchRestResponseGenerator responseGenerator = mock(UsersSearchRestResponseGenerator.class);
private final MockMvc mockMvc = ControllerTester.getMockMvc(new DefaultUserController(userSession, userService, responseGenerator)); private final MockMvc mockMvc = ControllerTester.getMockMvc(new DefaultUserController(userSession, userService, responseGenerator));


private static final Gson gson = new Gson();
private static final Gson gson = new GsonBuilder().registerTypeAdapter(RestUser.class, new RestUserDeserializer()).create();


@Test @Test
public void search_whenNoParameters_shouldUseDefaultAndForwardToUserService() throws Exception { public void search_whenNoParameters_shouldUseDefaultAndForwardToUserService() throws Exception {
@Test @Test
public void search_whenAdminParametersUsedButNotAdmin_shouldFail() throws Exception { public void search_whenAdminParametersUsedButNotAdmin_shouldFail() throws Exception {
mockMvc.perform(get(USER_ENDPOINT) mockMvc.perform(get(USER_ENDPOINT)
.param("sonarQubeLastConnectionDateFrom", "2020-01-01T00:00:00+0100"))
.param("sonarQubeLastConnectionDateFrom", "2020-01-01T00:00:00+0100"))
.andExpectAll( .andExpectAll(
status().isForbidden(), status().isForbidden(),
content().string("{\"message\":\"parameter sonarQubeLastConnectionDateFrom requires Administer System permission.\"}")); content().string("{\"message\":\"parameter sonarQubeLastConnectionDateFrom requires Administer System permission.\"}"));


mockMvc.perform(get(USER_ENDPOINT) mockMvc.perform(get(USER_ENDPOINT)
.param("sonarQubeLastConnectionDateTo", "2020-01-01T00:00:00+0100"))
.param("sonarQubeLastConnectionDateTo", "2020-01-01T00:00:00+0100"))
.andExpectAll( .andExpectAll(
status().isForbidden(), status().isForbidden(),
content().string("{\"message\":\"parameter sonarQubeLastConnectionDateTo requires Administer System permission.\"}")); content().string("{\"message\":\"parameter sonarQubeLastConnectionDateTo requires Administer System permission.\"}"));


mockMvc.perform(get(USER_ENDPOINT) mockMvc.perform(get(USER_ENDPOINT)
.param("sonarLintLastConnectionDateFrom", "2020-01-01T00:00:00+0100"))
.param("sonarLintLastConnectionDateFrom", "2020-01-01T00:00:00+0100"))
.andExpectAll( .andExpectAll(
status().isForbidden(), status().isForbidden(),
content().string("{\"message\":\"parameter sonarLintLastConnectionDateFrom requires Administer System permission.\"}")); content().string("{\"message\":\"parameter sonarLintLastConnectionDateFrom requires Administer System permission.\"}"));


mockMvc.perform(get(USER_ENDPOINT) mockMvc.perform(get(USER_ENDPOINT)
.param("sonarLintLastConnectionDateTo", "2020-01-01T00:00:00+0100"))
.param("sonarLintLastConnectionDateTo", "2020-01-01T00:00:00+0100"))
.andExpectAll( .andExpectAll(
status().isForbidden(), status().isForbidden(),
content().string("{\"message\":\"parameter sonarLintLastConnectionDateTo requires Administer System permission.\"}")); content().string("{\"message\":\"parameter sonarLintLastConnectionDateTo requires Administer System permission.\"}"));


} }


static class RestUserDeserializer extends TypeAdapter<RestUser> {

@Override
public void write(JsonWriter out, RestUser value) {
throw new IllegalStateException("not implemented");
}

@Override
public RestUser read(JsonReader reader) {
return gson.fromJson(reader, RestUserForAdmins.class);
}
}

private UserSearchResult generateUserSearchResult(String id, boolean active, boolean local, boolean managed, int groupsCount, int tokensCount) { private UserSearchResult generateUserSearchResult(String id, boolean active, boolean local, boolean managed, int groupsCount, int tokensCount) {
UserDto userDto = new UserDto() UserDto userDto = new UserDto()
.setLogin("login_" + id) .setLogin("login_" + id)
userSession.logIn().setNonSystemAdministrator(); userSession.logIn().setNonSystemAdministrator();


mockMvc.perform( mockMvc.perform(
post(USER_ENDPOINT)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(new UserCreateRestRequest(null, null, "login", "name", null, null))))
post(USER_ENDPOINT)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(gson.toJson(new UserCreateRestRequest(null, null, "login", "name", null, null))))
.andExpectAll( .andExpectAll(
status().isForbidden(), status().isForbidden(),
content().json("{\"message\":\"Insufficient privileges\"}")); content().json("{\"message\":\"Insufficient privileges\"}"));

Loading…
Cancel
Save