diff --git a/src/main/java/info/fingo/urlopia/api/v2/proxy/presence/PresenceConfirmationProxyService.java b/src/main/java/info/fingo/urlopia/api/v2/proxy/presence/PresenceConfirmationProxyService.java index 423ac2f0..e9469318 100644 --- a/src/main/java/info/fingo/urlopia/api/v2/proxy/presence/PresenceConfirmationProxyService.java +++ b/src/main/java/info/fingo/urlopia/api/v2/proxy/presence/PresenceConfirmationProxyService.java @@ -23,7 +23,7 @@ public class PresenceConfirmationProxyService { private final PresenceConfirmationService presenceConfirmationService; public void confirmPresence(PresenceConfirmationProxyInput proxyInput) { - var user = userService.get(proxyInput.email()); + var user = userService.getByMail(proxyInput.email()); var startTime = DEFAULT_START_TIME; var endTime = startTime.plusMinutes(Math.round(60 * user.getWorkTime())); diff --git a/src/main/java/info/fingo/urlopia/api/v2/slack/presence/SlackPresenceConfirmationEventHandler.java b/src/main/java/info/fingo/urlopia/api/v2/slack/presence/SlackPresenceConfirmationEventHandler.java index cd2944fe..7fe40a02 100644 --- a/src/main/java/info/fingo/urlopia/api/v2/slack/presence/SlackPresenceConfirmationEventHandler.java +++ b/src/main/java/info/fingo/urlopia/api/v2/slack/presence/SlackPresenceConfirmationEventHandler.java @@ -72,7 +72,7 @@ private void confirmPresence(String userSlackId, String latestMessageTimestamp) { try { var userEmail = getUserEmail(userSlackId); - var user = userService.get(userEmail); + var user = userService.getByMail(userEmail); confirmUserTodayPresence(user, eventMessage); addReactionToLatestMessage(channel, latestMessageTimestamp, SUCCESS_EMOJI_NAME); } catch (NoSuchUserException | SlackBotException ex) { diff --git a/src/main/java/info/fingo/urlopia/config/mail/receive/MailDecider.java b/src/main/java/info/fingo/urlopia/config/mail/receive/MailDecider.java index c6adb189..7263e980 100644 --- a/src/main/java/info/fingo/urlopia/config/mail/receive/MailDecider.java +++ b/src/main/java/info/fingo/urlopia/config/mail/receive/MailDecider.java @@ -64,7 +64,7 @@ public void resolve(Mail mail) { private void parse(Mail mail){ var senderMail = mail.getSenderAddress(); try{ - var sender = userService.get(senderMail); + var sender = userService.getByMail(senderMail); mailParser.clear(); mailParser.parseSubject(mail); diff --git a/src/main/java/info/fingo/urlopia/user/User.java b/src/main/java/info/fingo/urlopia/user/User.java index 75012bae..8eb79d49 100644 --- a/src/main/java/info/fingo/urlopia/user/User.java +++ b/src/main/java/info/fingo/urlopia/user/User.java @@ -25,7 +25,7 @@ public class User { @Column(nullable = false, unique = true) private String adName; - @Column(nullable = false, unique = true) + @Column(nullable = false) private String mail; private String firstName; diff --git a/src/main/java/info/fingo/urlopia/user/UserRepository.java b/src/main/java/info/fingo/urlopia/user/UserRepository.java index 7257cdbd..41809598 100644 --- a/src/main/java/info/fingo/urlopia/user/UserRepository.java +++ b/src/main/java/info/fingo/urlopia/user/UserRepository.java @@ -9,7 +9,7 @@ public interface UserRepository extends BaseRepository, JpaRepository { - Optional findFirstByMail(String mail); + Optional findFirstByMailAndActiveTrue(String mail); Optional findFirstByPrincipalName(String principalName); diff --git a/src/main/java/info/fingo/urlopia/user/UserService.java b/src/main/java/info/fingo/urlopia/user/UserService.java index 2569440a..2c5f3017 100644 --- a/src/main/java/info/fingo/urlopia/user/UserService.java +++ b/src/main/java/info/fingo/urlopia/user/UserService.java @@ -61,9 +61,9 @@ public User get(Long userId) { }); } - public User get(String userMail) { + public User getByMail(String userMail) { return userRepository - .findFirstByMail(userMail) + .findFirstByMailAndActiveTrue(userMail) .orElseThrow(() -> { log.error("There is no user with email: {}", Anonymizer.anonymizeMail(userMail)); return NoSuchUserException.invalidEmail(); diff --git a/src/main/resources/scripts/U3_5_0_2__drop_email_unique_constraint.sql b/src/main/resources/scripts/U3_5_0_2__drop_email_unique_constraint.sql new file mode 100644 index 00000000..f950dcec --- /dev/null +++ b/src/main/resources/scripts/U3_5_0_2__drop_email_unique_constraint.sql @@ -0,0 +1 @@ +CREATE UNIQUE INDEX users_mail_index ON users (mail); \ No newline at end of file diff --git a/src/main/resources/scripts/V3_5_0_2__drop_email_unique_constraint.sql b/src/main/resources/scripts/V3_5_0_2__drop_email_unique_constraint.sql new file mode 100644 index 00000000..b17fe238 --- /dev/null +++ b/src/main/resources/scripts/V3_5_0_2__drop_email_unique_constraint.sql @@ -0,0 +1 @@ +ALTER TABLE users DROP CONSTRAINT IF EXISTS users_mail_index; \ No newline at end of file diff --git a/src/test/groovy/info/fingo/urlopia/api/v2/proxy/presence/PresenceConfirmationProxyServiceSpec.groovy b/src/test/groovy/info/fingo/urlopia/api/v2/proxy/presence/PresenceConfirmationProxyServiceSpec.groovy index af9c1bb4..21dea73a 100644 --- a/src/test/groovy/info/fingo/urlopia/api/v2/proxy/presence/PresenceConfirmationProxyServiceSpec.groovy +++ b/src/test/groovy/info/fingo/urlopia/api/v2/proxy/presence/PresenceConfirmationProxyServiceSpec.groovy @@ -27,7 +27,7 @@ class PresenceConfirmationProxyServiceSpec extends Specification { and: def presenceConfirmationProxyInput = new PresenceConfirmationProxyInput(sampleProxyToken, sampleEmail, "") - userService.get(sampleEmail) >> sampleUser + userService.getByMail(sampleEmail) >> sampleUser when: presenceConfirmationProxyService.confirmPresence(presenceConfirmationProxyInput) @@ -53,7 +53,7 @@ class PresenceConfirmationProxyServiceSpec extends Specification { and: def presenceConfirmationProxyInput = new PresenceConfirmationProxyInput(sampleProxyToken, sampleEmail, testHours) - userService.get(sampleEmail) >> sampleUser + userService.getByMail(sampleEmail) >> sampleUser when: presenceConfirmationProxyService.confirmPresence(presenceConfirmationProxyInput) @@ -96,7 +96,7 @@ class PresenceConfirmationProxyServiceSpec extends Specification { and: def presenceConfirmationProxyInput = new PresenceConfirmationProxyInput(sampleProxyToken, sampleEmail, testHours) - userService.get(sampleEmail) >> sampleUser + userService.getByMail(sampleEmail) >> sampleUser when: presenceConfirmationProxyService.confirmPresence(presenceConfirmationProxyInput) diff --git a/src/test/groovy/info/fingo/urlopia/api/v2/slack/presence/SlackPresenceConfirmationEventHandlerSpec.groovy b/src/test/groovy/info/fingo/urlopia/api/v2/slack/presence/SlackPresenceConfirmationEventHandlerSpec.groovy index 824eacf4..558421ed 100644 --- a/src/test/groovy/info/fingo/urlopia/api/v2/slack/presence/SlackPresenceConfirmationEventHandlerSpec.groovy +++ b/src/test/groovy/info/fingo/urlopia/api/v2/slack/presence/SlackPresenceConfirmationEventHandlerSpec.groovy @@ -90,7 +90,7 @@ class SlackPresenceConfirmationEventHandlerSpec extends Specification { } sampleMentionEvent.getText() >> "<@FPA12L32>" sampleMentionEvent.getUser() >> sampleUserSlackId - userService.get(sampleUserMail) >> sampleUser + userService.getByMail(sampleUserMail) >> sampleUser when: handler.handleMention(sampleMentionPayload, sampleContext) @@ -118,7 +118,7 @@ class SlackPresenceConfirmationEventHandlerSpec extends Specification { } sampleMentionEvent.getText() >> testText sampleMentionEvent.getUser() >> sampleUserSlackId - userService.get(sampleUserMail) >> sampleUser + userService.getByMail(sampleUserMail) >> sampleUser when: handler.handleMention(sampleMentionPayload, sampleContext) @@ -165,7 +165,7 @@ class SlackPresenceConfirmationEventHandlerSpec extends Specification { } sampleMentionEvent.getText() >> testText sampleMentionEvent.getUser() >> sampleUserSlackId - userService.get(sampleUserMail) >> sampleUser + userService.getByMail(sampleUserMail) >> sampleUser when: handler.handleMention(sampleMentionPayload, sampleContext) @@ -207,7 +207,7 @@ class SlackPresenceConfirmationEventHandlerSpec extends Specification { } sampleMentionEvent.getText() >> "<@FPA12L32>" sampleMentionEvent.getUser() >> sampleUserSlackId - userService.get(_ as String) >> {throw NoSuchUserException.invalidEmail()} + userService.getByMail(_ as String) >> {throw NoSuchUserException.invalidEmail()} when: handler.handleMention(sampleMentionPayload, sampleContext) @@ -229,7 +229,7 @@ class SlackPresenceConfirmationEventHandlerSpec extends Specification { } sampleMessageEvent.getText() >> "<@FPA12L32>" sampleMessageEvent.getUser() >> sampleUserSlackId - userService.get(sampleUserMail) >> sampleUser + userService.getByMail(sampleUserMail) >> sampleUser when: handler.handleDirectMessage(sampleMessagePayload, sampleContext) @@ -257,7 +257,7 @@ class SlackPresenceConfirmationEventHandlerSpec extends Specification { } sampleMessageEvent.getText() >> testText sampleMessageEvent.getUser() >> sampleUserSlackId - userService.get(sampleUserMail) >> sampleUser + userService.getByMail(sampleUserMail) >> sampleUser when: handler.handleDirectMessage(sampleMessagePayload, sampleContext) @@ -304,7 +304,7 @@ class SlackPresenceConfirmationEventHandlerSpec extends Specification { } sampleMessageEvent.getText() >> testText sampleMessageEvent.getUser() >> sampleUserSlackId - userService.get(sampleUserMail) >> sampleUser + userService.getByMail(sampleUserMail) >> sampleUser when: handler.handleDirectMessage(sampleMessagePayload, sampleContext) @@ -346,7 +346,7 @@ class SlackPresenceConfirmationEventHandlerSpec extends Specification { } sampleMessageEvent.getText() >> "<@FPA12L32>" sampleMessageEvent.getUser() >> sampleUserSlackId - userService.get(_ as String) >> {throw NoSuchUserException.invalidEmail()} + userService.getByMail(_ as String) >> {throw NoSuchUserException.invalidEmail()} when: handler.handleDirectMessage(sampleMessagePayload, sampleContext)