Skip to content

Commit

Permalink
Use created Instant from teams during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Oct 8, 2024
1 parent 02afa7e commit 0680a54
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions server/src/main/java/access/teams/Membership.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.Instant;

@Getter
@NoArgsConstructor
Expand All @@ -13,5 +14,6 @@ public class Membership implements Serializable {

private Person person;
private Role role;
private Instant created;

}
2 changes: 2 additions & 0 deletions server/src/main/java/access/teams/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.Instant;

@Getter
@NoArgsConstructor
Expand All @@ -15,4 +16,5 @@ public class Person implements Serializable {
private String name;
private String email;
private String schacHomeOrganization;
private Instant created;
}
4 changes: 2 additions & 2 deletions server/src/main/java/access/teams/TeamsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void provision(Role role, Membership membership) {
newUser.setName(person.getName());
newUser.setEmail(person.getEmail());
newUser.setSchacHomeOrganization(person.getSchacHomeOrganization());
newUser.setCreatedAt(now);
newUser.setCreatedAt(person.getCreated());
newUser.setLastActivity(now);
newUser.nameInvariant();
return userRepository.save(newUser);
Expand All @@ -144,7 +144,7 @@ private void provision(Role role, Membership membership) {
userRole.setInviter("teams_migration");
userRole.setUser(user);
userRole.setRole(role);
userRole.setCreatedAt(now);
userRole.setCreatedAt(membership.getCreated());
userRole.setEndDate(now.plus(DEFAULT_EXPIRY_DAYS, ChronoUnit.DAYS));
access.teams.Role teamsRole = membership.getRole();
userRole.setAuthority(mapAuthority(teamsRole));
Expand Down
12 changes: 10 additions & 2 deletions server/src/test/java/access/teams/TeamsControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -70,7 +72,9 @@ void migrateTeam() throws JsonProcessingException {
users.forEach(user -> assertEquals(team.getName(), user.getUserRoles().iterator().next().getRole().getName()));
userRoles.forEach((key, teamsRole) -> {
User user = users.stream().filter(u -> u.getName().equals(key)).findFirst().get();
assertTrue(Instant.now().minus(28, ChronoUnit.DAYS).isAfter(user.getCreatedAt()));
UserRole userRole = user.getUserRoles().stream().findFirst().get();
assertTrue(Instant.now().minus(13, ChronoUnit.DAYS).isAfter(userRole.getCreatedAt()));
Authority authority = userRole.getAuthority();
assertEquals(mapAuthority(teamsRole), authority);
if (teamsRole.equals(Role.MEMBER) || teamsRole.equals(Role.OWNER)) {
Expand Down Expand Up @@ -104,7 +108,11 @@ private List<Membership> getMemberships() {
"urn:collab:person:surfnet.nl:" + entry.getKey().toLowerCase().replaceAll(" ", "."),
entry.getKey(),
entry.getKey().replaceAll(" ", "") + "@example.com",
"example.com"), entry.getValue()))
"example.com",
Instant.now().minus(30, ChronoUnit.DAYS)),
entry.getValue(),
Instant.now().minus(15, ChronoUnit.DAYS)
))
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -182,7 +190,7 @@ void migrateTeamInvalidPerson() {
void migrateTeamInvalidSchacHome() {
List<Application> applications = List.of(new Application("999", EntityType.SAML20_SP));
Person person = new Person();
Membership membership = new Membership(person, Role.MANAGER);
Membership membership = new Membership(person, Role.MANAGER, Instant.now());
List<Membership> memberships = List.of(membership);
Team team = new Team(
"nl:surfnet:diensten:test",
Expand Down

0 comments on commit 0680a54

Please sign in to comment.