Skip to content

Commit

Permalink
Throw error when notifications via email enabled and no email provide…
Browse files Browse the repository at this point in the history
…d for new user
  • Loading branch information
pvannierop committed Jul 5, 2024
1 parent 8c98c70 commit f032f80
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/radarbase/appserver/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.radarbase.appserver.repository.ProjectRepository;
import org.radarbase.appserver.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -50,6 +51,9 @@
@Slf4j
public class UserService {

@Value("${notification.email.enabled:false}")
private boolean sendEmailNotifications;

private final transient UserConverter userConverter;
private final transient UserRepository userRepository;
private final transient ProjectRepository projectRepository;
Expand Down Expand Up @@ -152,6 +156,13 @@ public FcmUserDto saveUserInProject(FcmUserDto userDto) {
+ ". Please use Update endpoint if need to update the user");
}

if (sendEmailNotifications && (userDto.getEmailAddress() == null || userDto.getEmailAddress().isEmpty())) {
throw new InvalidUserDetailsException(
"The option to send notifications via email is enabled. " +
"Email Address is required for sending email notifications. " +
"Please provide a valid email address.");
}

User newUser = userConverter.dtoToEntity(userDto).setProject(project);
// maintain a bi-directional relationship
newUser.getUsermetrics().setUser(newUser);
Expand Down

0 comments on commit f032f80

Please sign in to comment.