Skip to content

Commit

Permalink
Backkward compatiblity for update name old apps
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Apr 8, 2024
1 parent 87b7484 commit 5eaa1ae
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [7.2.10]
- If the app sends only a givenname to /mobile/api/sp/update (old app) update the self-asserted chosenname field
- If the app sends only the chosen name (new app) update the self-asserted chosenname field.
- Is the app sends both the givenname as the chosenname field, produce an error the formal-givenname can't be updated this way

## [7.2.9]
- Make chosenname optional in mobile API

Expand Down
2 changes: 1 addition & 1 deletion account-gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.openconext</groupId>
<artifactId>myconext</artifactId>
<version>7.2.10-SNAPSHOT</version>
<version>7.2.10</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>account-gui</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion myconext-gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.openconext</groupId>
<artifactId>myconext</artifactId>
<version>7.2.10-SNAPSHOT</version>
<version>7.2.10</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>myconext-gui</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion myconext-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.openconext</groupId>
<artifactId>myconext</artifactId>
<version>7.2.10-SNAPSHOT</version>
<version>7.2.10</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>myconext-server</artifactId>
Expand Down
15 changes: 13 additions & 2 deletions myconext-server/src/main/java/myconext/api/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,27 @@ public ResponseEntity<StatusResponse> createEduIDAccount(@Valid @RequestBody Cre
@PutMapping("/sp/update")
public ResponseEntity<UserResponse> updateUserProfile(Authentication authentication, @Valid @RequestBody UpdateUserNameRequest deltaUser) {
User user = userFromAuthentication(authentication);
if (StringUtils.hasText(deltaUser.getGivenName())) {
user.setChosenName(deltaUser.getGivenName());
}
if (StringUtils.hasText(deltaUser.getChosenName())) {
user.setChosenName(deltaUser.getChosenName());
}
user.setGivenName(deltaUser.getGivenName());
user.setFamilyName(deltaUser.getFamilyName());
if (CollectionUtils.isEmpty(user.getLinkedAccounts())) {
if (StringUtils.hasText(deltaUser.getGivenName())) {
user.setGivenName(deltaUser.getGivenName());
}
if (StringUtils.hasText(deltaUser.getFamilyName())) {
user.setFamilyName(deltaUser.getFamilyName());
}
}
user.validate();

userRepository.save(user);
logWithContext(user, "update", "name", LOG, "Update user profile");

authenticationRequestRepository.deleteByUserId(user.getId());

return returnUserResponse(user);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public class UpdateUserNameRequest implements Serializable {

private String chosenName;

@NotBlank
private String givenName;

@NotBlank
private String familyName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import java.util.Map;

import static io.restassured.RestAssured.given;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;

public class UserMobileControllerTest extends AbstractIntegrationTest {

Expand Down Expand Up @@ -46,7 +45,26 @@ public void updateUserProfile() throws IOException {
.then()
.statusCode(201);
User user = userRepository.findUserByEmail("[email protected]").get();
//There are linked-accounts, so only the chosen name is updated
assertEquals(userNameRequest.getChosenName(), user.getChosenName());
assertNotEquals(userNameRequest.getGivenName(), user.getGivenName());
assertNotEquals(userNameRequest.getFamilyName(), user.getFamilyName());
}

@Test
public void updateUserProfileNonValidatedAccount() throws IOException {
UpdateUserNameRequest userNameRequest = new UpdateUserNameRequest("Annie", "Anna", "Winters");
given()
.when()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.auth().oauth2(doOpaqueAccessToken(true, new String[]{"eduid.nl/mobile"}, "introspect_no_linked_accounts"))
.body(userNameRequest)
.put("/mobile/api/sp/update")
.then()
.statusCode(201);
User user = userRepository.findUserByEmail("[email protected]").get();
//There are no linked-accounts, everything is updated
assertEquals(userNameRequest.getChosenName(), user.getChosenName());
assertEquals(userNameRequest.getGivenName(), user.getGivenName());
assertEquals(userNameRequest.getFamilyName(), user.getFamilyName());
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.openconext</groupId>
<artifactId>myconext</artifactId>
<version>7.2.10-SNAPSHOT</version>
<version>7.2.10</version>
<packaging>pom</packaging>
<name>myconext</name>
<description>My OpenConext</description>
Expand Down
2 changes: 1 addition & 1 deletion tiqr-mock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.openconext</groupId>
<artifactId>myconext</artifactId>
<version>7.2.10-SNAPSHOT</version>
<version>7.2.10</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>tiqr-mock</artifactId>
Expand Down

0 comments on commit 5eaa1ae

Please sign in to comment.