Skip to content

Commit

Permalink
Allow for non-unique emails
Browse files Browse the repository at this point in the history
  • Loading branch information
witold.brzozowski committed Oct 22, 2024
1 parent 211df5b commit fe50b75
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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 @@ -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;
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 @@ -9,7 +9,7 @@

public interface UserRepository extends BaseRepository<User>, JpaRepository<User, Long> {

Optional<User> findFirstByMail(String mail);
Optional<User> findFirstByMailAndActiveTrue(String mail);

Optional<User> findFirstByPrincipalName(String principalName);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/info/fingo/urlopia/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE UNIQUE INDEX users_mail_index ON users (mail);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE users DROP CONSTRAINT IF EXISTS users_mail_index;
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fe50b75

Please sign in to comment.