diff --git a/src/main/java/info/fingo/urlopia/team/ActiveDirectoryTeamLeaderProvider.java b/src/main/java/info/fingo/urlopia/team/ActiveDirectoryTeamLeaderProvider.java index 9c344ec..1b16197 100644 --- a/src/main/java/info/fingo/urlopia/team/ActiveDirectoryTeamLeaderProvider.java +++ b/src/main/java/info/fingo/urlopia/team/ActiveDirectoryTeamLeaderProvider.java @@ -42,6 +42,6 @@ private Optional checkParentTeam(String adTeamDN, } private Optional getUser(String userDN) { - return userRepository.findFirstByAdName(userDN); + return userRepository.findFirstByAdNameAndActiveTrue(userDN); } } diff --git a/src/main/java/info/fingo/urlopia/team/ActiveDirectoryTeamSynchronizer.java b/src/main/java/info/fingo/urlopia/team/ActiveDirectoryTeamSynchronizer.java index 53f37f7..208c6b0 100644 --- a/src/main/java/info/fingo/urlopia/team/ActiveDirectoryTeamSynchronizer.java +++ b/src/main/java/info/fingo/urlopia/team/ActiveDirectoryTeamSynchronizer.java @@ -119,7 +119,7 @@ private List getTeamMembersDn(ActiveDirectoryTree tree, private Set getMembers(List membersDn) { return membersDn.stream() - .map(userRepository::findFirstByAdName) + .map(userRepository::findFirstByAdNameAndActiveTrue) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toSet()); diff --git a/src/main/java/info/fingo/urlopia/user/User.java b/src/main/java/info/fingo/urlopia/user/User.java index 662b0f4..d0d593e 100644 --- a/src/main/java/info/fingo/urlopia/user/User.java +++ b/src/main/java/info/fingo/urlopia/user/User.java @@ -22,7 +22,7 @@ public class User { @Column(nullable = false) private String principalName; - @Column(nullable = false, unique = true) + @Column(nullable = false) private String adName; @Column(nullable = false) diff --git a/src/main/java/info/fingo/urlopia/user/UserRepository.java b/src/main/java/info/fingo/urlopia/user/UserRepository.java index 8f320a5..b8f60b7 100644 --- a/src/main/java/info/fingo/urlopia/user/UserRepository.java +++ b/src/main/java/info/fingo/urlopia/user/UserRepository.java @@ -15,7 +15,7 @@ public interface UserRepository extends BaseRepository, JpaRepository findFirstByAccountName(String accountName); - Optional findFirstByAdName(String adName); + Optional findFirstByAdNameAndActiveTrue(String adName); @Query("SELECT u.accountName FROM User u") List findAllAccountNames(); diff --git a/src/main/resources/scripts/U3_5_0_6__drop_ad_name_unique_constraint.sql b/src/main/resources/scripts/U3_5_0_6__drop_ad_name_unique_constraint.sql new file mode 100644 index 0000000..1714650 --- /dev/null +++ b/src/main/resources/scripts/U3_5_0_6__drop_ad_name_unique_constraint.sql @@ -0,0 +1,2 @@ +CREATE UNIQUE INDEX users_ad_name_index ON users (ad_name); +CREATE UNIQUE INDEX users_ad_name_key ON users (ad_name); \ No newline at end of file diff --git a/src/main/resources/scripts/V3_5_0_6__drop_ad_name_unique_constraint.sql b/src/main/resources/scripts/V3_5_0_6__drop_ad_name_unique_constraint.sql new file mode 100644 index 0000000..1f1e3a4 --- /dev/null +++ b/src/main/resources/scripts/V3_5_0_6__drop_ad_name_unique_constraint.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS users_ad_name_index; +DROP INDEX IF EXISTS users_ad_name_key; \ No newline at end of file diff --git a/src/test/groovy/info/fingo/urlopia/team/ActiveDirectoryTeamLeaderProviderSpec.groovy b/src/test/groovy/info/fingo/urlopia/team/ActiveDirectoryTeamLeaderProviderSpec.groovy index d799d6d..c200cbe 100644 --- a/src/test/groovy/info/fingo/urlopia/team/ActiveDirectoryTeamLeaderProviderSpec.groovy +++ b/src/test/groovy/info/fingo/urlopia/team/ActiveDirectoryTeamLeaderProviderSpec.groovy @@ -52,7 +52,7 @@ class ActiveDirectoryTeamLeaderProviderSpec extends Specification { and: def user = Mock(User) - userRepository.findFirstByAdName(managedBy.substring(managedBy.indexOf(':') + 2)) >> Optional.of(user) + userRepository.findFirstByAdNameAndActiveTrue(managedBy.substring(managedBy.indexOf(':') + 2)) >> Optional.of(user) when: var teamDN = childTeamDN.substring(childTeamDN.indexOf(':') + 2) @@ -100,7 +100,7 @@ class ActiveDirectoryTeamLeaderProviderSpec extends Specification { and: def user = Mock(User) - userRepository.findFirstByAdName(managedBy.substring(managedBy.indexOf(':') + 2)) >> Optional.of(user) + userRepository.findFirstByAdNameAndActiveTrue(managedBy.substring(managedBy.indexOf(':') + 2)) >> Optional.of(user) when: var teamDN = childTeamDN.substring(childTeamDN.indexOf(':') + 2) @@ -143,7 +143,7 @@ class ActiveDirectoryTeamLeaderProviderSpec extends Specification { and: def user = Mock(User) - userRepository.findFirstByAdName(_ as String) >> Optional.of(user) + userRepository.findFirstByAdNameAndActiveTrue(_ as String) >> Optional.of(user) when: var teamDN = childTeamDN.substring(childTeamDN.indexOf(':') + 2)