Skip to content

Commit

Permalink
Drop user AD name unique constraint (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
boavenn authored Oct 22, 2024
1 parent 3edb6c0 commit e7918f9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ private Optional<User> checkParentTeam(String adTeamDN,
}

private Optional<User> getUser(String userDN) {
return userRepository.findFirstByAdName(userDN);
return userRepository.findFirstByAdNameAndActiveTrue(userDN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private List<String> getTeamMembersDn(ActiveDirectoryTree tree,

private Set<User> getMembers(List<String> membersDn) {
return membersDn.stream()
.map(userRepository::findFirstByAdName)
.map(userRepository::findFirstByAdNameAndActiveTrue)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toSet());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/info/fingo/urlopia/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/info/fingo/urlopia/user/UserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface UserRepository extends BaseRepository<User>, JpaRepository<User

Optional<User> findFirstByAccountName(String accountName);

Optional<User> findFirstByAdName(String adName);
Optional<User> findFirstByAdNameAndActiveTrue(String adName);

@Query("SELECT u.accountName FROM User u")
List<String> findAllAccountNames();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP INDEX IF EXISTS users_ad_name_index;
DROP INDEX IF EXISTS users_ad_name_key;
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e7918f9

Please sign in to comment.