Skip to content

Commit

Permalink
fix: disable email modification in portal rest api
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
User email modification is not modifiable anymore https://gravitee.atlassian.net/browse/APIM-4227
  • Loading branch information
Okhelifi committed Mar 14, 2024
1 parent 24eb353 commit 1594058
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Expand Up @@ -114,8 +114,8 @@ public Response updateCurrentUser(@Valid @NotNull(message = "Input must not be n
} else {
updateUserEntity.setPicture(existingUser.getPicture());
}
if (user.getEmail() != null) {
updateUserEntity.setEmail(user.getEmail());
if (existingUser.getEmail() != null) {
updateUserEntity.setEmail(existingUser.getEmail());
}
if (user.getFirstName() != null) {
updateUserEntity.setFirstname(user.getFirstName());
Expand Down
Expand Up @@ -2279,6 +2279,7 @@ paths:
Modify current user information.
Only the current user can modify his/her information.
The user email is not modifiable.
operationId: updateCurrentUser
responses:
200:
Expand Down Expand Up @@ -5020,10 +5021,6 @@ components:
description: Lastname of the user.
type: string
writeOnly: true
email:
description: Email of the user.
type: string
writeOnly: true
customFields:
type: object
description: Values for CustomUserFields
Expand Down
Expand Up @@ -16,8 +16,12 @@
package io.gravitee.rest.api.portal.rest.resource;

import static io.gravitee.common.http.HttpStatusCode.OK_200;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -176,11 +180,16 @@ public void shouldUpdateCurrentUser() {
"f0uv2Oz+v3/L7/DxgoOEhYaHiImKi4yNjo+AgZKTlJWWl5iZmpucnZ6fkJGio6SlpqeoqaqrrK2ur6ChsrO0tba3uLm6u7y9vr" +
"+wscLDxMXGx8jJysvMzc7PwMHS09TV1tfY2drb3N3e39DR4uPk5ebn6Onq6+zt7u/g4fLz9PX29/j5+vv8/f7/8PMKDAgQQLGj" +
"yIMKHChQwbOnwIMaLEiRQrWryIMaPGjQYcO3osUwAAOw==";
final String userEmail = "example@gio.com";

userInput.setAvatar(newAvatar);
userInput.setId(USER_NAME);
when(userService.update(eq(GraviteeContext.getExecutionContext()), eq(USER_NAME), any())).thenReturn(new UserEntity());

UserEntity existingUser = new UserEntity();
existingUser.setEmail(userEmail);
when(userService.findById(eq(GraviteeContext.getExecutionContext()), any())).thenReturn(existingUser);

final Response response = target().request().put(Entity.json(userInput));
assertEquals(HttpStatusCode.OK_200, response.getStatus());

Expand All @@ -191,6 +200,7 @@ public void shouldUpdateCurrentUser() {
assertNotNull(updateUserEntity);
assertEquals(expectedAvatar, updateUserEntity.getPicture());
assertNull(updateUserEntity.getStatus());
assertEquals(userEmail, updateUserEntity.getEmail());

User updateUser = response.readEntity(User.class);
assertNotNull(updateUser);
Expand Down

0 comments on commit 1594058

Please sign in to comment.