Merge branch 'mimocode/nimble-circuit' into master
This commit is contained in:
commit
0dec90db47
@ -13,6 +13,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Profile("dev")
|
@Profile("dev")
|
||||||
@ -60,6 +61,7 @@ public class AdminDataInitializer implements CommandLineRunner {
|
|||||||
admin.setLastName(ADMIN_LAST_NAME);
|
admin.setLastName(ADMIN_LAST_NAME);
|
||||||
admin.setParticipantType(ParticipantType.PRIVATE);
|
admin.setParticipantType(ParticipantType.PRIVATE);
|
||||||
admin.setRole(UserRole.ADMIN);
|
admin.setRole(UserRole.ADMIN);
|
||||||
|
admin.setCreatedAt(LocalDateTime.now());
|
||||||
admin.setStatus(RegistrationStatus.APPROVED);
|
admin.setStatus(RegistrationStatus.APPROVED);
|
||||||
admin.setEnabled(true);
|
admin.setEnabled(true);
|
||||||
admin.setEmailVerified(true);
|
admin.setEmailVerified(true);
|
||||||
@ -74,6 +76,7 @@ public class AdminDataInitializer implements CommandLineRunner {
|
|||||||
testUser.setLastName("Benutzer");
|
testUser.setLastName("Benutzer");
|
||||||
testUser.setParticipantType(ParticipantType.PRIVATE);
|
testUser.setParticipantType(ParticipantType.PRIVATE);
|
||||||
testUser.setRole(UserRole.MEMBER);
|
testUser.setRole(UserRole.MEMBER);
|
||||||
|
testUser.setCreatedAt(LocalDateTime.now());
|
||||||
testUser.setStatus(RegistrationStatus.PENDING);
|
testUser.setStatus(RegistrationStatus.PENDING);
|
||||||
testUser.setEnabled(false);
|
testUser.setEnabled(false);
|
||||||
testUser.setEmailVerified(true);
|
testUser.setEmailVerified(true);
|
||||||
|
|||||||
@ -59,6 +59,9 @@ public class User implements UserDetails {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private RegistrationStatus status = RegistrationStatus.PENDING;
|
private RegistrationStatus status = RegistrationStatus.PENDING;
|
||||||
|
|
||||||
|
@Column(updatable = false)
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private boolean enabled = false;
|
private boolean enabled = false;
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@ public interface UserMapper {
|
|||||||
@Mapping(target = "verificationToken", ignore = true)
|
@Mapping(target = "verificationToken", ignore = true)
|
||||||
@Mapping(target = "passwordResetToken", ignore = true)
|
@Mapping(target = "passwordResetToken", ignore = true)
|
||||||
@Mapping(target = "passwordResetTokenExpiry", ignore = true)
|
@Mapping(target = "passwordResetTokenExpiry", ignore = true)
|
||||||
|
@Mapping(target = "createdAt", ignore = true)
|
||||||
User mapToEntity(IamDtos.RegistrationRequest request, @MappingTarget User user);
|
User mapToEntity(IamDtos.RegistrationRequest request, @MappingTarget User user);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -73,6 +74,7 @@ public class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
User newUser = userMapper.mapToEntity(request, new User());
|
User newUser = userMapper.mapToEntity(request, new User());
|
||||||
|
newUser.setCreatedAt(LocalDateTime.now());
|
||||||
String token = UUID.randomUUID().toString();
|
String token = UUID.randomUUID().toString();
|
||||||
newUser.setVerificationToken(token);
|
newUser.setVerificationToken(token);
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,36 @@
|
|||||||
|
package at.mueller.eeg.backend.iam.domain;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class UserTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createdAtFieldExists() {
|
||||||
|
User user = new User();
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
user.setCreatedAt(now);
|
||||||
|
|
||||||
|
assertEquals(now, user.getCreatedAt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createdAtIsNotUpdatable() throws NoSuchFieldException {
|
||||||
|
var field = User.class.getDeclaredField("createdAt");
|
||||||
|
var column = field.getAnnotation(jakarta.persistence.Column.class);
|
||||||
|
|
||||||
|
assertNotNull(column, "@Column annotation must be present on createdAt");
|
||||||
|
assertFalse(column.updatable(), "createdAt must be non-updatable");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createdAtDefaultIsNull() {
|
||||||
|
User user = new User();
|
||||||
|
|
||||||
|
assertNull(user.getCreatedAt(), "createdAt should default to null (not auto-generated)");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user