Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DMP-4381: Automatically update createdBy and lastModifiedBy when persisting entities to the database #2308

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1677f48
Updated lastModifiedBy and createdBy to auto update based on entity l…
Ben-Edwards-cgi Nov 22, 2024
3098af6
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Nov 22, 2024
c9fa327
Applied review comments
Ben-Edwards-cgi Nov 25, 2024
e4ab4b1
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Nov 25, 2024
001009b
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Nov 26, 2024
50fe7a6
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Nov 26, 2024
0c05c24
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Nov 27, 2024
b5e877c
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Nov 27, 2024
eaa05ad
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Nov 28, 2024
d8b4f06
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Nov 29, 2024
01db930
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Dec 2, 2024
90c1ad2
Applied review comments
Ben-Edwards-cgi Dec 4, 2024
531a450
Fixed typo
Ben-Edwards-cgi Dec 5, 2024
3ce05ef
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Dec 6, 2024
5ea0748
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Dec 6, 2024
7ce5bbc
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Dec 6, 2024
4cf8620
Added integration test
Ben-Edwards-cgi Dec 9, 2024
2a0110e
Updated how we update createdBy and LastModifiedBy
Ben-Edwards-cgi Dec 9, 2024
7914ce0
Fixed circular reference
Ben-Edwards-cgi Dec 9, 2024
08545fc
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Dec 9, 2024
02606b7
Fixed test
Ben-Edwards-cgi Dec 9, 2024
f5989d0
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Dec 10, 2024
7f37da8
Fixed issue with integration tests
Ben-Edwards-cgi Dec 10, 2024
c94111e
Fixed issue with integration tests
Ben-Edwards-cgi Dec 10, 2024
80aa299
Test fixes
Ben-Edwards-cgi Dec 10, 2024
6aed390
Fixed style
Ben-Edwards-cgi Dec 10, 2024
ff6d5a6
Disabled beforeUpdate to check tests
Ben-Edwards-cgi Dec 10, 2024
66589bd
Tmp changes to verify integration tests
Ben-Edwards-cgi Dec 10, 2024
17bd661
Tmp changes to verify integration tests
Ben-Edwards-cgi Dec 10, 2024
895e710
Reverted a few tmp changes
Ben-Edwards-cgi Dec 10, 2024
3b32154
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Dec 11, 2024
8d11520
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Dec 11, 2024
f6af92b
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Dec 11, 2024
62dc14d
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Dec 12, 2024
b8df67c
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Jan 3, 2025
1354d27
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Jan 6, 2025
d737541
Merge branch 'master' into DMP-4381
Ben-Edwards-cgi Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import uk.gov.hmcts.darts.authentication.exception.AuthenticationError;
import uk.gov.hmcts.darts.authorisation.component.UserIdentity;
import uk.gov.hmcts.darts.common.entity.UserAccountEntity;
import uk.gov.hmcts.darts.common.exception.DartsApiException;

import java.util.Optional;

@Configuration
public class AuthenticationConfiguration {

Expand All @@ -14,4 +19,15 @@ public AuthConfigFallback getNoAuthConfigurationFallback(DefaultAuthConfiguratio
throw new DartsApiException(AuthenticationError.FAILED_TO_OBTAIN_AUTHENTICATION_CONFIG);
};
}

@Bean
public AuditorAware<UserAccountEntity> auditorAware(UserIdentity userIdentity) {
chrisbellingham-hmcts marked this conversation as resolved.
Show resolved Hide resolved
return () -> {
try {
return Optional.ofNullable(userIdentity.getUserAccount());
} catch (Exception e) {
return Optional.empty();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.envers.NotAudited;
import org.springframework.data.annotation.CreatedBy;
import uk.gov.hmcts.darts.common.entity.UserAccountEntity;

import java.time.OffsetDateTime;
Expand All @@ -24,6 +25,7 @@ public class CreatedBaseEntity {
@NotAudited
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "created_by")
@CreatedBy
chrisbellingham-hmcts marked this conversation as resolved.
Show resolved Hide resolved
private UserAccountEntity createdBy;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.Setter;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.envers.NotAudited;
import org.springframework.data.annotation.LastModifiedBy;
import uk.gov.hmcts.darts.common.entity.UserAccountEntity;

import java.time.OffsetDateTime;
Expand All @@ -25,5 +26,6 @@ public class CreatedModifiedBaseEntity extends CreatedBaseEntity {
@NotAudited
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "last_modified_by")
@LastModifiedBy
private UserAccountEntity lastModifiedBy;
}